initial plugin commit

master
Alen Kolarić 2 years ago
commit 5fcbce1647

@ -0,0 +1,114 @@
=== Plugin Name ===
Contributors: (this should be a list of wordpress.org userid's)
Donate link: https://kolarix.com/biztime
Tags: comments, spam
Requires at least: 3.0.1
Tested up to: 3.4
Stable tag: 4.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Here is a short description of the plugin. This should be no more than 150 characters. No markup here.
== Description ==
This is the long description. No limit, and you can use Markdown (as well as in the following sections).
For backwards compatibility, if this section is missing, the full length of the short description will be used, and
Markdown parsed.
A few notes about the sections above:
* "Contributors" is a comma separated list of wp.org/wp-plugins.org usernames
* "Tags" is a comma separated list of tags that apply to the plugin
* "Requires at least" is the lowest version that the plugin will work on
* "Tested up to" is the highest version that you've *successfully used to test the plugin*. Note that it might work on
higher versions... this is just the highest one you've verified.
* Stable tag should indicate the Subversion "tag" of the latest stable version, or "trunk," if you use `/trunk/` for
stable.
Note that the `readme.txt` of the stable tag is the one that is considered the defining one for the plugin, so
if the `/trunk/readme.txt` file says that the stable tag is `4.3`, then it is `/tags/4.3/readme.txt` that'll be used
for displaying information about the plugin. In this situation, the only thing considered from the trunk `readme.txt`
is the stable tag pointer. Thus, if you develop in trunk, you can update the trunk `readme.txt` to reflect changes in
your in-development version, without having that information incorrectly disclosed about the current stable version
that lacks those changes -- as long as the trunk's `readme.txt` points to the correct stable tag.
If no stable tag is provided, it is assumed that trunk is stable, but you should specify "trunk" if that's where
you put the stable version, in order to eliminate any doubt.
== Installation ==
This section describes how to install the plugin and get it working.
e.g.
1. Upload `biztime.php` to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
1. Place `<?php do_action('plugin_name_hook'); ?>` in your templates
== Frequently Asked Questions ==
= A question that someone might have =
An answer to that question.
= What about foo bar? =
Answer to foo bar dilemma.
== Screenshots ==
1. This screen shot description corresponds to screenshot-1.(png|jpg|jpeg|gif). Note that the screenshot is taken from
the /assets directory or the directory that contains the stable readme.txt (tags or trunk). Screenshots in the /assets
directory take precedence. For example, `/assets/screenshot-1.png` would win over `/tags/4.3/screenshot-1.png`
(or jpg, jpeg, gif).
2. This is the second screen shot
== Changelog ==
= 1.0 =
* A change since the previous version.
* Another change.
= 0.5 =
* List versions from most recent at top to oldest at bottom.
== Upgrade Notice ==
= 1.0 =
Upgrade notices describe the reason a user should upgrade. No more than 300 characters.
= 0.5 =
This version fixes a security related bug. Upgrade immediately.
== Arbitrary section ==
You may provide arbitrary sections, in the same format as the ones above. This may be of use for extremely complicated
plugins where more information needs to be conveyed that doesn't fit into the categories of "description" or
"installation." Arbitrary sections will be shown below the built-in sections outlined above.
== A brief Markdown Example ==
Ordered list:
1. Some feature
1. Another feature
1. Something else about the plugin
Unordered list:
* something
* something else
* third thing
Here's a link to [WordPress](http://wordpress.org/ "Your favorite software") and one to [Markdown's Syntax Documentation][markdown syntax].
Titles are optional, naturally.
[markdown syntax]: http://daringfireball.net/projects/markdown/syntax
"Markdown is what the parser uses to process much of the readme file"
Markdown uses email style notation for blockquotes and I've been told:
> Asterisks for *emphasis*. Double it up for **strong**.
`<?php code(); // goes in backticks ?>`

@ -0,0 +1,358 @@
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
* @subpackage BizTime/admin
*/
/**
* The admin-specific functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package BizTime
* @subpackage BizTime/admin
* @author Kolarix <biztime@kolarix.com>
*/
class Biztime_Admin {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Biztime_Loader as all of the hooks are defined
* in that particular class.
*
* The Biztime_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/biztime-admin.css', array(), $this->version, 'all' );
wp_enqueue_style( $this->plugin_name . '-timepicker', plugin_dir_url( __FILE__ ) . 'css/timepicker.min.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Biztime_Loader as all of the hooks are defined
* in that particular class.
*
* The Biztime_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/biztime-admin.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name . '-timepicker', plugin_dir_url( __FILE__ ) . 'js/timepicker.min.js', array( 'jquery' ), $this->version, false );
}
/**
* Register the settings page for the admin area.
*
* @since 1.0.0
*/
public function register_settings_page() {
add_submenu_page(
'options-general.php',
__( 'Biztime', 'biztime' ),
__( 'Biztime', 'biztime' ),
'manage_options',
'biztime',
array( $this, 'display_settings_page' )
);
}
/**
* Display the settings page content for the page we have created.
*
* @since 1.0.0
*/
public function display_settings_page() {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/biztime-admin-display.php';
}
/**
* Register the settings for our settings page.
*
* @since 1.0.0
*/
public function register_settings() {
register_setting(
$this->plugin_name . '-availability',
$this->plugin_name . '-availability',
array( $this, 'biztime_register_availability' )
);
add_settings_section(
$this->plugin_name . '-availability-section',
__('Availability', 'biztime' ),
array( $this, 'biztime_add_availability_section' ),
$this->plugin_name . '-availability'
);
$days = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
foreach ( $days as $day ) {
add_settings_field(
$day,
__( ucfirst( $day ), 'biztime' ),
array( $this, 'biztime_add_availability_fields' ),
$this->plugin_name . '-availability',
$this->plugin_name . '-availability-section',
array(
'label_for' => $day,
'description' => __( 'Available', 'biztime' )
)
);
};
add_settings_field(
'phone-number',
__( 'Phone number', 'biztime' ),
array( $this, 'biztime_add_availability_input' ),
$this->plugin_name . '-availability',
$this->plugin_name . '-availability-section',
array(
'label_for' => 'phone-number',
'description' => __('Number to be shown in modal', 'biztime' ),
'default' => __( '+01 123 4567', 'biztime' )
)
);
add_settings_field(
'true-msg',
__( 'Message when available', 'biztime' ),
array( $this, 'biztime_add_availability_textarea' ),
$this->plugin_name . '-availability',
$this->plugin_name . '-availability-section',
array(
'label_for' => 'true-msg',
'description' => __('Message to be displayed when user visits page during available hours', 'biztime' ),
'default' => __( 'We are open!', 'biztime' )
)
);
add_settings_field(
'false-msg',
__( 'Message when not available', 'biztime' ),
array( $this, 'biztime_add_availability_textarea' ),
$this->plugin_name . '-availability',
$this->plugin_name . '-availability-section',
array(
'label_for' => 'false-msg',
'description' => __('Message to be displayed when user visits page during unavailable hours', 'biztime' ),
'default' => __( 'We are currently closed!', 'biztime' )
)
);
add_settings_field(
'show-next',
__( 'Next available day', 'biztime' ),
array( $this, 'biztime_add_availability_checkbox' ),
$this->plugin_name . '-availability',
$this->plugin_name . '-availability-section',
array(
'label_for' => 'show-next',
'description' => __('Show the next available day?', 'biztime' )
)
);
add_settings_field(
'next-msg',
__( 'Next available day message', 'biztime' ),
array( $this, 'biztime_add_availability_textarea' ),
$this->plugin_name . '-availability',
$this->plugin_name . '-availability-section',
array(
'label_for' => 'next-msg',
'description' => __('Message to be displayed with the next available day', 'biztime' ),
'default' => __( 'We are back in business on:', 'biztime' )
)
);
}
/**
* Section for the settings.
*
* @since 1.0.0
*/
public function biztime_add_availability_section() {
return;
}
/**
* Availability fields, checkbox and two inputs with timepicker.
*
* @since 1.0.0
*/
public function biztime_add_availability_fields( $args ) {
$field_id = $args['label_for'];
$options = get_option( $this->plugin_name . '-availability', array(), 'no' );
$to = '';
$from = '';
if ( !empty( $options[$field_id]['check'] ) ) {
$to = !empty( $options[$field_id]['to'] ) ? esc_attr( $options[$field_id]['to'] ) : '';
$from = !empty( $options[$field_id]['from'] ) ? esc_attr( $options[$field_id]['from'] ) : '';
}
?>
<input class="day-checkbox" type="checkbox" name="<?php echo $this->plugin_name . '-availability[' . $field_id . '][check]'; ?>" id="<?php echo $this->plugin_name . '-availability[' . $field_id . '][check]'; ?>" <?php checked( !empty( $options[$field_id]['check'] ), true ); ?> />
<label class="label" for="<?php echo $this->plugin_name . '-availability[' . $field_id . '][from]'; ?>">
From:
<input class="timepicker" type="text" name="<?php echo $this->plugin_name . '-availability[' . $field_id . '][from]'; ?>" id="<?php echo $this->plugin_name . '-availability[' . $field_id . '][from]'; ?>" value="<?php echo $from; ?>" />
</label>
<label class="label" for="<?php echo $this->plugin_name . '-availability[' . $field_id . '][to]'; ?>">
To:
<input class="timepicker" type="text" name="<?php echo $this->plugin_name . '-availability[' . $field_id . '][to]'; ?>" id="<?php echo $this->plugin_name . '-availability[' . $field_id . '][to]'; ?>" value="<?php echo $to; ?>" />
</label>
<?php
}
/**
* Phone number input
*
* @since 1.0.0
*/
public function biztime_add_availability_input( $args ) {
$field_id = $args['label_for'];
$field_description = $args['description'];
$field_default = $args['default'];
$options = get_option( $this->plugin_name . '-availability', array(), 'no' );
$option = $field_default;
if ( ! empty( $options[ $field_id ] ) ) {
$option = $options[ $field_id ];
}
?>
<input type="text" name="<?php echo $this->plugin_name . '-availability[' . $field_id . ']'; ?>" id="<?php echo $this->plugin_name . '-availability[' . $field_id . ']'; ?>" value="<?php echo esc_attr( $option ); ?>" class="regular-text" />
<p class="description"><?php echo esc_html( $field_description ); ?></p>
<?php
}
/**
* Availability messages textarea
*
* @since 1.0.0
*/
public function biztime_add_availability_textarea( $args ) {
$field_id = $args['label_for'];
$field_description = $args['description'];
$field_default = $args['default'];
$options = get_option( $this->plugin_name . '-availability', array(), 'no' );
$option = $field_default;
if ( ! empty( $options[ $field_id ] ) ) {
$option = $options[ $field_id ];
}
?>
<textarea name="<?php echo $this->plugin_name . '-availability[' . $field_id . ']'; ?>" id="<?php echo $this->plugin_name . '-availability[' . $field_id . ']'; ?>" class="regular-text" rows="4"><?php echo esc_textarea( $option ); ?></textarea>
<p class="description"><?php echo esc_html( $field_description ); ?></p>
<?php
}
/**
* Next available day checkbox.
*
* @since 1.0.0
*/
public function biztime_add_availability_checkbox( $args ) {
$field_id = $args['label_for'];
$field_description = $args['description'];
$options = get_option( $this->plugin_name . '-availability', array(), 'no' );
$option = isset( $options[ $field_id ] ) ? $options[ $field_id ] : 0;
?>
<label for="<?php echo $this->plugin_name . '-availability[' . $field_id . ']'; ?>">
<input type="checkbox" name="<?php echo $this->plugin_name . '-availability[' . $field_id . ']'; ?>" id="<?php echo $this->plugin_name . '-availability[' . $field_id . ']'; ?>" <?php checked( $option, 1 ); ?> value="1" />
<?php echo esc_html( $field_description ); ?>
</label>
<?php
}
}

@ -0,0 +1,12 @@
/**
* All of the CSS for your admin-specific functionality should be
* included in this file.
*/
.label {
pointer-events: none;
opacity: 0.4;
}
.day-checkbox:checked ~ .label {
pointer-events: initial;
opacity: 1;
}

@ -0,0 +1 @@
.ui-timepicker-container{position:absolute;overflow:hidden;box-sizing:border-box}.ui-timepicker,.ui-timepicker-viewport{box-sizing:content-box;height:205px;display:block;margin:0}.ui-timepicker{list-style:none;padding:0 1px;text-align:center}.ui-timepicker-viewport{padding:0;overflow:auto;overflow-x:hidden}.ui-timepicker-standard{font-family:Verdana,Arial,sans-serif;font-size:1.1em;background-color:#FFF;border:1px solid #AAA;color:#222;margin:0;padding:2px}.ui-timepicker-standard a{border:1px solid transparent;color:#222;display:block;padding:.2em .4em;text-decoration:none}.ui-timepicker-standard .ui-state-hover{background-color:#DADADA;border:1px solid #999;font-weight:400;color:#212121}.ui-timepicker-standard .ui-menu-item{margin:0;padding:0}.ui-timepicker-corners,.ui-timepicker-corners .ui-corner-all{-moz-border-radius:4px;-webkit-border-radius:4px;border-radius:4px}.ui-timepicker-hidden{display:none}.ui-timepicker-no-scrollbar .ui-timepicker{border:none}

@ -0,0 +1 @@
<?php // Silence is golden

@ -0,0 +1,32 @@
(function( $ ) {
'use strict';
/**
* All of the code for your admin-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*
* $(function() {
*
* });
*
* When the window is loaded:
*
* $( window ).load(function() {
*
* });
*
* ...and/or other possibilities.
*
* Ideally, it is not considered best practise to attach more than a
* single DOM-ready or window-load handler for a particular page.
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/
})( jQuery );

File diff suppressed because one or more lines are too long

@ -0,0 +1,38 @@
<?php
/**
* Provide a admin area view for the plugin
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
* @subpackage BizTime/admin/partials
*/
?>
<!-- This file should primarily consist of HTML with a little bit of PHP. -->
<div id="wrap">
<form method="post" action="options.php">
<?php
settings_fields( 'biztime-availability' );
do_settings_sections( 'biztime-availability' );
submit_button();
?>
</form>
</div>
<script type="text/javascript" defer>
jQuery(document).ready(function($) {
$('.timepicker').timepicker({
timeFormat: 'h:mm p',
interval: 30,
startTime: '05:00',
dynamic: false,
dropdown: true,
scrollbar: true
});
})
</script>

@ -0,0 +1,82 @@
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://kolarix.com/biztime
* @since 1.0.0
* @package BizTime
*
* @wordpress-plugin
* Plugin Name: BizTime
* Plugin URI: https://kolarix.com/biztime
* Description: The plugin shows available times and displays different messages depending on availability.
* Version: 1.0.0
* Author: Kolarix
* Author URI: https://kolarix.com/biztime
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: biztime
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'BIZTIME_VERSION', '1.0.0' );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-biztime-activator.php
*/
function activate_biztime() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-biztime-activator.php';
Biztime_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-biztime-deactivator.php
*/
function deactivate_biztime() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-biztime-deactivator.php';
Biztime_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_biztime' );
register_deactivation_hook( __FILE__, 'deactivate_biztime' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-biztime.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
function run_biztime() {
$plugin = new Biztime();
$plugin->run();
}
run_biztime();

@ -0,0 +1,36 @@
<?php
/**
* Fired during plugin activation
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
* @subpackage BizTime/includes
*/
/**
* Fired during plugin activation.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @since 1.0.0
* @package BizTime
* @subpackage BizTime/includes
* @author Kolarix <biztime@kolarix.com>
*/
class Biztime_Activator {
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function activate() {
}
}

@ -0,0 +1,36 @@
<?php
/**
* Fired during plugin deactivation
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
* @subpackage BizTime/includes
*/
/**
* Fired during plugin deactivation.
*
* This class defines all code necessary to run during the plugin's deactivation.
*
* @since 1.0.0
* @package BizTime
* @subpackage BizTime/includes
* @author Kolarix <hello@Kolarix.io>
*/
class Biztime_Deactivator {
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function deactivate() {
}
}

@ -0,0 +1,47 @@
<?php
/**
* Define the internationalization functionality
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
* @subpackage BizTime/includes
*/
/**
* Define the internationalization functionality.
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @since 1.0.0
* @package BizTime
* @subpackage BizTime/includes
* @author Kolarix <biztime@kolarix.com>
*/
class Biztime_i18n {
/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain(
'biztime',
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);
}
}

@ -0,0 +1,157 @@
<?php
/**
* Register all actions and filters for the plugin
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
* @subpackage BizTime/includes
*/
/**
* Register all actions and filters for the plugin.
*
* Maintain a list of all hooks that are registered throughout
* the plugin, and register them with the WordPress API. Call the
* run function to execute the list of actions and filters.
*
* @package BizTime
* @subpackage BizTime/includes
* @author Kolarix <biztime@kolarix.com>
*/
class Biztime_Loader {
/**
* The array of actions registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
*/
protected $actions;
/**
* The array of filters registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
*/
protected $filters;
/**
* The array of shortcodes registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $shortcodes The shortcodes registered with WordPress to fire when the plugin loads.
*/
protected $shortcodes;
/**
* Initialize the collections used to maintain the actions and filters.
*
* @since 1.0.0
*/
public function __construct() {
$this->actions = array();
$this->filters = array();
$this->shortcodes = array();
}
/**
* Add a new action to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress action that is being registered.
* @param object $component A reference to the instance of the object on which the action is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
*/
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Add a new filter to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
*/
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Add a new shortcode to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress shortcode that is being registered.
* @param object $component A reference to the instance of the object on which the shortcode is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority Optional. he priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
*/
public function add_shortcode( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->shortcodes = $this->add( $this->shortcodes, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
*
* @since 1.0.0
* @access private
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
* @return array The collection of actions and filters registered with WordPress.
*/
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'component' => $component,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args
);
return $hooks;
}
/**
* Register the filters and actions with WordPress.
*
* @since 1.0.0
*/
public function run() {
foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
foreach ( $this->shortcodes as $hook ) {
add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
}
}

@ -0,0 +1,222 @@
<?php
/**
* The file that defines the core plugin class
*
* A class definition that includes attributes and functions used across both the
* public-facing side of the site and the admin area.
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
* @subpackage BizTime/includes
*/
/**
* The core plugin class.
*
* This is used to define internationalization, admin-specific hooks, and
* public-facing site hooks.
*
* Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @since 1.0.0
* @package BizTime
* @subpackage BizTime/includes
* @author Kolarix <biztime@kolarix.com>
*/
class Biztime {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var Biztime_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_name The string used to uniquely identify this plugin.
*/
protected $plugin_name;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 1.0.0
*/
public function __construct() {
if ( defined( 'BIZTIME_VERSION' ) ) {
$this->version = BIZTIME_VERSION;
} else {
$this->version = '1.0.0';
}
$this->plugin_name = 'biztime';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - Biztime_Loader. Orchestrates the hooks of the plugin.
* - Biztime_i18n. Defines internationalization functionality.
* - Biztime_Admin. Defines all hooks for the admin area.
* - Biztime_Public. Defines all hooks for the public side of the site.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies() {
/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-biztime-loader.php';
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-biztime-i18n.php';
/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-biztime-admin.php';
/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-biztime-public.php';
$this->loader = new Biztime_Loader();
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the Biztime_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new Biztime_i18n();
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
}
/**
* Register all of the hooks related to the admin area functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_admin_hooks() {
$plugin_admin = new Biztime_Admin( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
$this->loader->add_action( 'admin_menu', $plugin_admin, 'register_settings_page' );
$this->loader->add_action( 'admin_init', $plugin_admin, 'register_settings' );
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_public_hooks() {
$plugin_public = new Biztime_Public( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
$this->loader->add_shortcode( 'biztime_availability_checker', $plugin_public, 'biztime_availability_checker_shortcode' );
$this->loader->add_shortcode( 'biztime_show_availability', $plugin_public,'biztime_show_availability_shortcode' );
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 1.0.0
*/
public function run() {
$this->loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since 1.0.0
* @return string The name of the plugin.
*/
public function get_plugin_name() {
return $this->plugin_name;
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @since 1.0.0
* @return Biztime_Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* Retrieve the version number of the plugin.
*
* @since 1.0.0
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
}

@ -0,0 +1 @@
<?php // Silence is golden

@ -0,0 +1 @@
<?php // Silence is golden

@ -0,0 +1,126 @@
<?php
/**
* The public-facing functionality of the plugin.
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
* @subpackage BizTime/public
*/
/**
* The public-facing functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the public-facing stylesheet and JavaScript.
*
* @package BizTime
* @subpackage BizTime/public
* @author Kolarix <biztime@kolarix.com>
*/
class Biztime_Public {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of the plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Biztime_Loader as all of the hooks are defined
* in that particular class.
*
* The Biztime_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/biztime-public.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Biztime_Loader as all of the hooks are defined
* in that particular class.
*
* The Biztime_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/biztime-public.js', array( 'jquery' ), $this->version, false );
}
function biztime_availability_checker_shortcode( $atts ) {
$options = get_option( 'biztime-availability', array(), 'no' );
$days = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
ob_start();
include( plugin_dir_path( __FILE__ ) . 'partials/biztime-modal-public-display.php' );
$output = ob_get_clean();
return $output;
}
function biztime_show_availability_shortcode() {
$options = get_option( 'biztime-availability', array(), 'no' );
$days = array( 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
ob_start();
include( plugin_dir_path( __FILE__ ) . 'partials/biztime-availability-public-display.php' );
$output = ob_get_clean();
return $output;
}
}

@ -0,0 +1,86 @@
/**
* All of the CSS for your public-facing functionality should be
* included in this file.
*/
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
max-width: 100%;
margin: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 99;
}
.modal-content {
background-color: #ffffff;
border: 1px solid hsl(230, 11%, 40%);
border-radius: 5px;
box-shadow: 0 0 10px 5px hsl(230, 11%, 40%);
margin: 10% auto;
padding: 30px;
width: 80%;
max-width: 1440px;
}
.modal-content__wrapper {
text-align: center;
}
.modal-content__wrapper p {
font-size: 20px;
}
.modal-content__wrapper .available p {
display: inline-block;
border-bottom: 2px solid hsla(119, 72%, 55%, 0.8);
margin-bottom: 10px;
padding-bottom: 10px;
}
.modal-content__wrapper .available p span {
font-weight: bold;
font-size: 24px;
}
.modal-content__wrapper .not-available p{
display: inline-block;
border-bottom: 2px solid hsla(0, 72.1%, 55.1%, 0.8);
margin-bottom: 10px;
padding-bottom: 10px;
}
.next-available {
margin-top: 20px;
}
#close-modal {
cursor: pointer;
float: right;
font-size: 36px;
font-weight: bold;
}
/* Available hours table */
.table-availability {
width: 100%;
max-width: 300px;
border-collapse: collapse;
margin: 0 auto;
}
.table-availability tr:nth-child(odd) {
background: rgba(255, 255, 255, 0.5);
}
.table-availability td {
text-transform: capitalize;
padding: 5px 10px;
color: #666666;
border-bottom: 1px solid #CCCCCC;
}

@ -0,0 +1 @@
<?php // Silence is golden

@ -0,0 +1,21 @@
(function( $ ) {
'use strict';
// Modal toggling
$(document).ready(function($) {
$('#availability-modal').appendTo('body');
$('#open-modal').click(function() {
$('#availability-modal').fadeIn();
});
$('#close-modal, #modal').click(function() {
$('#availability-modal').fadeOut();
});
$('.modal-content').click(function(e) {
e.stopPropagation();
});
});
})( jQuery );

@ -0,0 +1,27 @@
<?php
/**
* Provide a public-facing view for the plugin
*
* This file is used to markup the public-facing aspects of the plugin.
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
* @subpackage BizTime/public/partials
*/
?>
<table class="table table-availability">
<caption><?php esc_html_e( 'Business hours', 'biztime' ); ?></caption>
<?php
foreach ( $days as $day ) {
$from = ! empty( $options[ $day ]['from'] ) ? esc_attr( $options[ $day ]['from'] ) : '';
$to = ! empty( $options[ $day ]['to'] ) ? esc_attr( $options[ $day ]['to'] ) : '';
echo '<tr class="table-row"><td class="col day">' . $day . '</td><td class="col from">' . $from . '</td><td class="col to">' . $to . '</td></tr>';
}
?>
</table>

@ -0,0 +1,83 @@
<?php
/**
* Provide a public-facing view for the plugin
*
* This file is used to markup the public-facing aspects of the plugin.
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
* @subpackage BizTime/public/partials
*/
?>
<?php
$current_day = strtolower(date("l"));
$current_time = date('H:i');
$is_available = false;
$true_msg = $options['true-msg'];
$false_msg = $options['false-msg'];
$show_next = $options['show-next'];
$next_msg = $options['next-msg'];
foreach ($days as $day) {
// Convert the availability range to 24 hour format
$from = date("H:i", strtotime($options[$day]['from']));
$to = date("H:i", strtotime($options[$day]['to']));
if (!empty($options[$day]['check']) && strtotime($from) <= strtotime($current_time) && strtotime($current_time) <= strtotime($to)) {
$is_available = true;
break;
}
}
?>
<div class="checker-demo">
<button id="open-modal" type="button" class="button primary"><?php esc_html_e( 'CHECK AVAILABILITY', 'biztime' ); ?></button>
<span class="sm-grey"><?php esc_html_e( 'TO SEE A PREVIEW', 'biztime' ); ?></span>
</div>
<div id="availability-modal" class="modal">
<div class="modal-content">
<span id="close-modal">&times;</span>
<div class="modal-content__wrapper">
<?php
if ($is_available) {
$phone_number = $options['phone-number'];
echo "<div class='available'><p>" . $true_msg . "</p><div class='only-when-available'>" . $phone_number . "</div></div>";
} else {
echo "<div class='not-available'><p>" . $false_msg . "</p></div>";
$next_day = null;
$start_searching = false;
foreach ($days as $day) {
if ($day === $current_day) {
$start_searching = true;
}
if ($start_searching && !empty($options[$day]['check'])) {
$next_day = $day;
break;
}
}
// if still not found, start from Monday again
if (!$next_day) {
foreach ($days as $day) {
if (!empty($options[$day]['check'])) {
$next_day = $day;
break;
}
}
}
if ($next_day && $show_next) {
echo "<p class='next-available'>" . $next_msg . ucfirst($next_day) . " from " . $options[$next_day]['from'] . " to " . $options[$next_day]['to'] . ".</p>";
}
}
?>
</div>
<pre><br><span>Current:<?php print_r(date("l"));?>, <?php print_r(date('H:i'));?></span></pre>
</div>
</div>

@ -0,0 +1,31 @@
<?php
/**
* Fired when the plugin is uninstalled.
*
* When populating this file, consider the following flow
* of control:
*
* - This method should be static
* - Check if the $_REQUEST content actually is the plugin name
* - Run an admin referrer check to make sure it goes through authentication
* - Verify the output of $_GET makes sense
* - Repeat with other user roles. Best directly by using the links/query string parameters.
* - Repeat things for multisite. Once for a single site in the network, once sitewide.
*
* This file may be updated more in future version of the Boilerplate; however, this is the
* general skeleton and outline for how the file should work.
*
* For more information, see the following discussion:
* https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
*
* @link https://kolarix.com/biztime
* @since 1.0.0
*
* @package BizTime
*/
// If uninstall not called from WordPress, then exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
Loading…
Cancel
Save