You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
359 lines
11 KiB
359 lines
11 KiB
<?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
|
|
}
|
|
|
|
}
|