*/ 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'] ) : ''; } ?> /> plugin_name . '-availability', array(), 'no' ); $option = $field_default; if ( ! empty( $options[ $field_id ] ) ) { $option = $options[ $field_id ]; } ?>
plugin_name . '-availability', array(), 'no' ); $option = $field_default; if ( ! empty( $options[ $field_id ] ) ) { $option = $options[ $field_id ]; } ?> plugin_name . '-availability', array(), 'no' ); $option = isset( $options[ $field_id ] ) ? $options[ $field_id ] : 0; ?>