set_options(); // Set the currently saved options $this->set_defaults(); // Set the default options $this->set_select_options(); // Set the options available for each select add_action('after_setup_theme', array(&$this, 'after_setup_theme')); // Add the necessary theme support add_action('wp_enqueue_scripts', array(&$this, 'on_wp_enqueue_scripts')); // Enqueue the necessary front end scripts/styeles add_action('wp_head', array(&$this, 'on_wp_head')); // Output the necessary CSS/JS directly into the head of the front end add_action('admin_bar_menu', array(&$this, 'on_admin_bar_menu'), 999); // If nevessary, add the hide button to the admin menu add_action('admin_menu', array(&$this, 'on_admin_menu')); // Add the Admin Bar Button options Settings menu add_action('admin_init', array(&$this, 'on_admin_init')); // Register the settings that can be saved by this plugin } /** * Add the necessary theme support */ public function after_setup_theme(){ /** Set the CSS to remove the space typically alocated to the WordPress Admin Bar */ add_theme_support('admin-bar', array('callback' => array(&$this, 'on_admin_bar'))); } /** * Set the CSS to remove the space typically reserved for the WordPress Admin Bar */ public function on_admin_bar(){ $reserve_space = $this->get_value('bar_reserve_space'); $background_colour = $this->get_value('admin_bar_colour'); $background_colour_hover = $this->get_value('admin_bar_colour_hover'); $text_colour = $this->get_value('text_colour'); $text_colour_hover = $this->get_value('text_colour_hover'); ?> get_value('show_hide_button') || is_admin()) : return; endif; $button_text = 'Hide '.$this->get_value('text'); $args = array( 'id' => 'hide', 'parent' => 'top-secondary', 'title' => sprintf('%1$s', $button_text), 'href' => '#', 'meta' => array('title' => esc_attr(strip_tags($button_text))) ); $wp_admin_bar->add_node($args); } /** * Add the Admin Bar Button options Settings menu */ public function on_admin_menu(){ $this->page_hook = add_options_page( __('Admin Bar Button Settings', $this->plugin_text_domain), // Page title __('Admin Bar Button', $this->plugin_text_domain), // Menu title 'manage_options', // Required capability $this->plugin_slug, // Page slug array(&$this, 'on_show_page') // Rendering callback ); } /** * Register the settings that can be saved by this plugin */ public function on_admin_init(){ add_action('load-'.$this->page_hook, array(&$this, 'on_admin_load')); // Set information that can only be gathered once the page has loaded register_setting( 'admin_bar_button_group', // Group name 'admin_bar_button', // Option name array(&$this, 'on_save_settings') // Sanatize options callback ); /*----------------------------------------------- Admin Bar Button -----------------------------------------------*/ add_settings_section( 'abb_button_section', // ID __('Admin Bar Button', $this->plugin_text_domain), // Title false, // Callback 'djg_admin_bar_button' // Page ); add_settings_field( 'text', // ID __('Button Text', $this->plugin_text_domain), // Title array($this, '_option_button_text'), // Callback 'djg_admin_bar_button', // Page 'abb_button_section', // Section array( // Args 'label_for' => 'text' ) ); add_settings_field( 'text_direction', __('Text Direction', $this->plugin_text_domain), array($this, '_option_text_direction'), 'djg_admin_bar_button', 'abb_button_section', array( 'label_for' => 'text_direction' ) ); add_settings_field( 'button_position', __('Position on the Screen', $this->plugin_text_domain), array($this, '_option_button_position'), 'djg_admin_bar_button', 'abb_button_section', array( 'label_for' => 'button_position' ) ); add_settings_field( 'button_activate', __('Button Activated On', $this->plugin_text_domain), array($this, '_option_button_activate'), 'djg_admin_bar_button', 'abb_button_section', array( 'label_for' => 'button_activate' ) ); add_settings_field( 'button_animate', __('Animate', $this->plugin_text_domain), array($this, '_option_button_animate'), 'djg_admin_bar_button', 'abb_button_section', array( 'label_for' => 'button_animate' ) ); add_settings_field( 'button_duration', __('Slide Duration (milliseconds)', $this->plugin_text_domain), array($this, '_option_button_duration'), 'djg_admin_bar_button', 'abb_button_section', array( 'label_for' => 'button_duration' ) ); add_settings_field( 'button_direction', __('Slide Direction', $this->plugin_text_domain), array($this, '_option_button_direction'), 'djg_admin_bar_button', 'abb_button_section', array( 'label_for' => 'button_direction' ) ); /*----------------------------------------------- WordPress Admin Bar -----------------------------------------------*/ add_settings_section( 'abb_bar_section', // ID __('WordPress Admin Bar', $this->plugin_text_domain), // Title false, // Callback 'djg_admin_bar_button' // Page ); add_settings_field( 'bar_reserve_space', // ID __('Reserve Space', $this->plugin_text_domain), // Title array($this, '_option_bar_reserve_space'), // Callback 'djg_admin_bar_button', // Page 'abb_bar_section', // Section array( // Args 'label_for' => 'bar_reserve_space' ) ); add_settings_field( 'bar_animate', // ID __('Animate', $this->plugin_text_domain), // Title array($this, '_option_bar_animate'), // Callback 'djg_admin_bar_button', // Page 'abb_bar_section', // Section array( // Args 'label_for' => 'bar_animate' ) ); add_settings_field( 'bar_duration', __('Slide Duration (milliseconds)', $this->plugin_text_domain), array($this, '_option_bar_duration'), 'djg_admin_bar_button', 'abb_bar_section', array( 'label_for' => 'bar_duration' ) ); add_settings_field( 'bar_direction', __('Slide Direction', $this->plugin_text_domain), array($this, '_option_bar_direction'), 'djg_admin_bar_button', 'abb_bar_section', array( 'label_for' => 'bar_direction' ) ); add_settings_field( 'bar_shown_behaviour', __('Admin Bar Behaviour', $this->plugin_text_domain), array($this, '_option_bar_shown_behaviour'), 'djg_admin_bar_button', 'abb_bar_section', array( 'label_for' => 'bar_shown_behaviour' ) ); add_settings_field( 'show_time', __('Show Time (milliseconds)', $this->plugin_text_domain), array($this, '_option_show_time'), 'djg_admin_bar_button', 'abb_bar_section', array( 'label_for' => 'show_time' ) ); add_settings_field( 'show_hide_button', __('Show the Hide Button', $this->plugin_text_domain), array($this, '_option_show_hide_button'), 'djg_admin_bar_button', 'abb_bar_section', array( 'label_for' => 'show_hide_button' ) ); add_settings_field( 'show_wordpress_menu', __('Show the WordPress Menu', $this->plugin_text_domain), array($this, '_option_show_wordpress_menu'), 'djg_admin_bar_button', 'abb_bar_section', array( 'label_for' => 'show_wordpress_menu' ) ); /*----------------------------------------------- WordPress Admin Bar Colours -----------------------------------------------*/ add_settings_section( 'abb_colours_section', // ID __('Colours', $this->plugin_text_domain), // Title false, // Callback 'djg_admin_bar_button' // Page ); add_settings_field( 'admin_bar_colour', // ID __('Background Colour', $this->plugin_text_domain), // Title array($this, '_option_admin_bar_colour'), // Callback 'djg_admin_bar_button', // Page 'abb_colours_section' ); add_settings_field( 'admin_bar_colour_hover', __('Background Colour (Hover)', $this->plugin_text_domain), array($this, '_option_admin_bar_colour_hover'), 'djg_admin_bar_button', 'abb_colours_section' ); add_settings_field( 'text_colour', __('Text Colour', $this->plugin_text_domain), array($this, '_option_text_colour'), 'djg_admin_bar_button', 'abb_colours_section' ); add_settings_field( 'text_colour_hover', __('Text Colour (Hover)', $this->plugin_text_domain), array($this, '_option_text_colour_hover'), 'djg_admin_bar_button', 'abb_colours_section' ); } /** * Grab the current screen and add contextual help */ public function on_admin_load(){ add_action('admin_enqueue_scripts', array(&$this, 'on_admin_enqueue_scripts')); // Enqueue the necessary admin scripts/styeles add_action('admin_print_styles-'.$this->page_hook, array(&$this, 'on_admin_print_styles')); // Print the necessary admin styles $this->screen = get_current_screen(); // Grab the current screen $this->screen->set_help_sidebar($this->do_help_sidebar()); $this->screen->add_help_tab(array( 'id' => 'description', 'title' => __('Description'), 'callback' => array(&$this, 'do_help_description') )); $this->screen->add_help_tab(array( 'id' => 'faq', 'title' => __('FAQ'), 'callback' => array(&$this, 'do_help_faq') )); $this->screen->add_help_tab(array( 'id' => 'support', 'title' => __('Support'), 'callback' => array(&$this, 'do_help_support') )); $this->screen->add_help_tab(array( 'id' => 'donate', 'title' => __('Donate'), 'callback' => array(&$this, 'do_help_donate') )); } /** * Enqueue the necessary admin scripts/styles */ public function on_admin_enqueue_scripts(){ /** Enqueue the required scripts/styles */ wp_enqueue_style('wp-color-picker'); wp_enqueue_script('djg-admin-bar-admin', plugins_url('adminBar-admin.js?scope=admin-bar-button', __FILE__), array('wp-color-picker', 'jquery-ui-tabs')); wp_enqueue_style('djg-admin-bar-admin', plugins_url('adminBar-admin.css?scope=admin-bar-button', __FILE__)); } /** * Enqueue the necessary admin styles */ public function on_admin_print_styles(){ ?>

plugin_text_domain); ?>

do_settings_sections_tabs('djg_admin_bar_button'); ?>

set_defaults(); // Set the default options $this->set_select_options(); // Set the options available for each select $new_input = array(); // Create a new array to hold the sanitized options /** Button text */ if(isset($input['text'])) : $text = sanitize_text_field($input['text']); $new_input['text'] = ($text !== '') ? $text : $this->defaults['text']; endif; /** Text direction */ if(isset($input['text_direction'])) : $new_input['text_direction'] = (array_key_exists($input['text_direction'], $this->select_options['text_direction'])) ? $input['text_direction'] : $this->defaults['text_direction']; endif; /** Button position */ if(isset($input['button_position'])) : $new_input['button_position'] = (array_key_exists($input['button_position'], $this->select_options['button_position'])) ? $input['button_position'] : $this->defaults['button_position']; endif; /** Button activate */ if(isset($input['button_activate'])) : $new_input['button_activate'] = (array_key_exists($input['button_activate'], $this->select_options['button_activate'])) ? $input['button_activate'] : $this->defaults['button_activate']; endif; /** Button animate */ if(isset($input['button_animate'])) : $new_input['button_animate'] = (array_key_exists($input['button_animate'], $this->select_options['button_animate'])) ? $input['button_animate'] : $this->defaults['button_animate']; endif; /** Button duration */ if(isset($input['button_duration'])) : $time = absint($input['button_duration']); $new_input['button_duration'] = ($time >= 0) ? $time : $this->defaults['button_duration']; endif; /** Button direction */ if(isset($input['button_direction'])) : $new_input['button_direction'] = (array_key_exists($input['button_direction'], $this->select_options['button_direction'])) ? $input['button_direction'] : $this->defaults['button_direction']; endif; /** Show reserve space */ if(isset($input['bar_reserve_space'])) : $new_input['bar_reserve_space'] = (isset($input['bar_reserve_space'])) ? intval($input['bar_reserve_space']) : intval($this->defaults['bar_reserve_space']); endif; /** Bar animate */ if(isset($input['bar_animate'])) : $new_input['bar_animate'] = (array_key_exists($input['bar_animate'], $this->select_options['bar_animate'])) ? $input['bar_animate'] : $this->defaults['bar_animate']; endif; /** Bar duration */ if(isset($input['bar_duration'])) : $time = absint($input['bar_duration']); $new_input['bar_duration'] = ($time >= 0) ? $time : $this->defaults['bar_duration']; endif; /** Bar direction */ if(isset($input['bar_direction'])) : $new_input['bar_direction'] = (array_key_exists($input['bar_direction'], $this->select_options['bar_direction'])) ? $input['bar_direction'] : $this->defaults['bar_direction']; endif; /** Bar shown behaviour */ if(isset($input['bar_shown_behaviour'])) : $new_input['bar_shown_behaviour'] = (array_key_exists($input['bar_shown_behaviour'], $this->select_options['bar_shown_behaviour'])) ? $input['bar_shown_behaviour'] : $this->defaults['bar_shown_behaviour']; endif; /** Show time */ if(isset($input['show_time'])) : $time = absint($input['show_time']); $new_input['show_time'] = ($time >= 2000) ? $time : $this->defaults['show_time']; endif; /** Show hide button */ if(isset($input['show_hide_button'])) : $new_input['show_hide_button'] = (isset($input['show_hide_button'])) ? intval($input['show_hide_button']) : intval($this->defaults['show_hide_button']); endif; /** Show WordPress menu */ if(isset($input['show_wordpress_menu'])) : $new_input['show_wordpress_menu'] = (isset($input['show_wordpress_menu'])) ? intval($input['show_wordpress_menu']) : intval($this->defaults['show_wordpress_menu']); endif; /** Bar background colour */ if(isset($input['admin_bar_colour'])) : $new_input['admin_bar_colour'] = $this->sanitize_hex($input['admin_bar_colour']); endif; /** Bar background colour (hover) */ if(isset($input['admin_bar_colour_hover'])) : $new_input['admin_bar_colour_hover'] = $this->sanitize_hex($input['admin_bar_colour_hover']); endif; /** Text colour */ if(isset($input['text_colour'])) : $new_input['text_colour'] = $this->sanitize_hex($input['text_colour']); endif; /** Text colour (hover) */ if(isset($input['text_colour_hover'])) : $new_input['text_colour_hover'] = $this->sanitize_hex($input['text_colour_hover']); endif; return $new_input; } /** * Set the $options, grabbed from the 'wp_options' DB table */ private function set_options(){ $this->options = get_option('admin_bar_button'); } /** * Set the default values, used if a value is not set when the 'on_show_page' or 'on_save_settings' methods are called */ private function set_defaults(){ $this->dafaults = array( 'text' => __('Admin bar', $this->plugin_text_domain), 'text_direction' => 'ltr', 'button_position' => 'top-left', 'button_activate' => 'both', 'button_animate' => 'yes', 'button_duration' => 500, 'button_direction' => 'left', 'bar_reserve_space' => 0, 'bar_animate' => 'yes', 'bar_duration' => 500, 'bar_direction' => 'right', 'bar_shown_behaviour' => 'go', 'show_time' => 5000, 'show_hide_button' => 1, 'show_wordpress_menu' => 1, 'admin_bar_colour' => '#23282D', 'admin_bar_colour_hover' => '#32373C', 'text_colour' => '#9EA3A8', 'text_colour_hover' => '#00B9EB' ); } /** * Set the options that are available for each of the '; echo ''; foreach((array)$wp_settings_sections[$page] as $section) : printf('
', $section['id'] /** %1$s - The ID of the tab */ ); if(!isset($section['title'])) continue; if($section['callback']) call_user_func($section['callback'], $section); if(!isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']])) continue; echo ''; do_settings_fields($page, $section['id']); echo '
'; echo '
'; endforeach; echo ''; } /** * Output an option of the $type specified * * @param required string $type The type of option to output * @parma required string $id The ID of the option that is to be output * @param array $args The arguments to use for the option that is to be output */ private function do_option($type, $id, $args = array()){ switch($type) : case 'text' : $this->do_option_text($id, $args); break; case 'checkbox' : $this->do_option_checkbox($id, $args); break; case 'select' : $this->do_option_select($id, $args); break; endswitch; } /** * Output a text option * * @parma required string $id The ID of the option that is to be output * @param array $args The arguments to use for the option that is to be output */ private function do_option_text($id, $args = array()){ $defaults = array( 'name' => '', 'value' => false, 'class' => '', 'description' => false, 'tips' => false, 'readonly' => false ); $args = wp_parse_args($args, $defaults); extract($args, EXTR_OVERWRITE); $name = ($name !== '') ? $name : $id; $readonly = ($readonly) ? 'readonly="true"' : false; printf( "\n\t".''."\n", $id, /** %1$s - The ID of the input */ $class, /** %2$s - The class of the input */ $name, /** %3$s - The name of the select */ $value, /** %4$s - The value of the option */ $readonly /** %5$s - Whether or not the option is readonly */ ); $this->do_tips($tips); $this->do_description($description); } /** * Output a checkbox option * * @parma required string $id The ID of the option that is to be output * @param array $args The arguments to use for the option that is to be output */ private function do_option_checkbox($id, $args = array()){ $defaults = array( 'name' => '', 'checked' => false, 'class' => '', 'description' => false, 'tips' => false ); $args = wp_parse_args($args, $defaults); extract($args, EXTR_OVERWRITE); $name = ($name !== '') ? $name : $id; $checked = ($checked) ? 'checked="true"' : false; /** Include a hidden input with a value of '0' so that unchecked boxes are given a vaule when _POSTed */ printf( "\n\t".''."\n", $id, /** %1$s - The ID of the input */ $class, /** %2$s - The class of the input */ $name /** %3$s - The name of the select */ ); printf( "\n\t".''."\n", $id, /** %1$s - The ID of the input */ $class, /** %2$s - The class of the input */ $name, /** %3$s - The name of the select */ $checked /** %4$s - Whether or not the checkbox is checked */ ); $this->do_tips($tips); $this->do_description($description); } /** * Output a '."\n", $id, /** %1$s - The ID of the input */ $class, /** %2$s - The class of the input */ $name, /** %3$s - The name of the select */ $selected /** %4$s - The currently selected value */ ); printf( "\n\t".''."\n"; endif; $this->do_tips($tips); $this->do_description($description); } /** * Output a description underneath an option * * @since 2.2 * @param required mixed $description The description to output */ private function do_description($description){ if(is_string($description)) : printf( "\n\t".'

%1$s

'."\n", $description /** %1$s - A brief description of the option */ ); endif; } /** * Output a tip next do an option * * @since 2.2 * @param required array $tips The tips to output (must be an array of arrays) */ private function do_tips($tips){ if(!empty($tips)) : echo ''; foreach($tips as $tip) : if(is_array($tip)) : printf( "\n\t".'%1$s: %2$s'."\n", $tip[0], /** %1$s - The tip prefix */ $tip[1] /** %2$s - The tip to display */ ); elseif(is_string($tip)) : printf( "\n\t".'%1$s'."\n", $tip /** %1$s - The tip to display */ ); endif; endforeach; echo ''; endif; } /** * Callback for outputting the 'text' option */ public function _option_button_text(){ $value = $this->get_value('text'); // Get the value currently saved for this option $this->do_option( 'text', // Option type 'text', // ID array( // Args 'name' => 'admin_bar_button[text]', 'value' => $value, 'class' => 'regular-text' ) ); } /** * Callback for outputting the 'text_direction' option */ public function _option_text_direction(){ $options = $this->select_options['text_direction']; // Get the valid options for this setting $selected = $this->get_value('text_direction'); // Get the value currently selected for this option $this->do_option( 'select', // Option type 'text_direction', // ID array( // Args 'name' => 'admin_bar_button[text_direction]', 'options' => $options, 'selected' => $selected ) ); } /** * Callback for outputting the 'button_position' option */ public function _option_button_position(){ $options = $this->select_options['button_position']; // Get the valid options for this setting $selected = $this->get_value('button_position'); // Get the value currently selected for this option $this->do_option( 'select', // Option type 'button_position', // ID array( // Args 'name' => 'admin_bar_button[button_position]', 'options' => $options, 'selected' => $selected ) ); } /** * Callback for outputting the 'button_activate' option */ public function _option_button_activate(){ $options = $this->select_options['button_activate']; // Get the valid options for this setting $selected = $this->get_value('button_activate'); // Get the value currently selected for this option $this->do_option( 'select', // Option type 'button_activate', // ID array( // Args 'name' => 'admin_bar_button[button_activate]', 'options' => $options, 'selected' => $selected, 'description' => __('The actions that will activate the Admin Bar.', $this->plugin_text_domain) ) ); } /** * Callback for outputting the 'button_animate' option */ public function _option_button_animate(){ $options = $this->select_options['button_animate']; // Get the valid options for this setting $selected = $this->get_value('button_animate'); // Get the value currently selected for this option $this->do_option( 'select', // Option type 'button_animate', // ID array( // Args 'name' => 'admin_bar_button[button_animate]', 'options' => $options, 'selected' => $selected ) ); } /** * Callback for outputting the 'button_duration' option */ public function _option_button_duration(){ $value = $this->get_value('button_duration'); // Get the value currently saved for this option $button_animate = $this->get_value('button_animate'); $readonly = ($button_animate === 'no') ? true : false; $this->do_option( 'text', // Option type 'button_duration', // ID array( // Args 'name' => 'admin_bar_button[button_duration]', 'value' => $value, 'class' => 'regular-text', 'description' => __('The time that it takes for the Admin Bar Button to slide off of (and on to) the screen.', $this->plugin_text_domain), 'readonly' => $readonly ) ); } /** * Callback for outputting the 'button_direction' option */ public function _option_button_direction(){ $options = $this->select_options['button_direction']; // Get the valid options for this setting $selected = $this->get_value('button_direction'); // Get the value currently selected for this option $button_animate = $this->get_value('button_animate'); $disabled = ($button_animate === 'no') ? true : false; $this->do_option( 'select', // Option type 'button_direction', // ID array( // Args 'name' => 'admin_bar_button[button_direction]', 'options' => $options, 'selected' => $selected, 'description' => __('The side of the screen from which the Admin Bar Button will exit (and enter).', $this->plugin_text_domain), 'disabled' => $disabled ) ); } /** * Callback for outputting the 'bar_reserve_space' option */ public function _option_bar_reserve_space(){ $value = $this->get_value('bar_reserve_space'); // Get the value currently saved for this option $checked = ($value) ? true : false; $this->do_option( 'checkbox', // Option type 'bar_reserve_space', // ID array( // Args 'name' => 'admin_bar_button[bar_reserve_space]', 'checked' => $checked, 'description' => __('Whether or not to reserve space for the WordPress Admin Bar.', $this->plugin_text_domain), 'tips' => array( array( __('Tip', $this->plugin_text_domain), __('The default WordPress Admin Bar does this, but for most sites it\'s unnecessary.', $this->plugin_text_domain) ) ) ) ); } /** * Callback for outputting the 'bar_animate' option */ public function _option_bar_animate(){ $options = $this->select_options['bar_animate']; // Get the valid options for this setting $selected = $this->get_value('bar_animate'); // Get the value currently selected for this option $this->do_option( 'select', // Option type 'bar_animate', // ID array( // Args 'name' => 'admin_bar_button[bar_animate]', 'options' => $options, 'selected' => $selected ) ); } /** * Callback for outputting the 'bar_duration' option */ public function _option_bar_duration(){ $value = $this->get_value('bar_duration'); // Get the value currently saved for this option $bar_animate = $this->get_value('bar_animate'); $readonly = ($bar_animate === 'no') ? true : false; $this->do_option( 'text', // Option type 'bar_duration', // ID array( // Args 'name' => 'admin_bar_button[bar_duration]', 'value' => $value, 'class' => 'regular-text', 'description' => __('The time that it takes for the Admin Bar to slide on to (and off of) the screen.', $this->plugin_text_domain), 'readonly' => $readonly ) ); } /** * Callback for outputting the 'bar_direction' option */ public function _option_bar_direction(){ $options = $this->select_options['bar_direction']; // Get the valid options for this setting $selected = $this->get_value('bar_direction'); // Get the value currently selected for this option $bar_animate = $this->get_value('bar_animate'); $disabled = ($bar_animate === 'no') ? true : false; $this->do_option( 'select', // Option type 'bar_direction', // ID array( // Args 'name' => 'admin_bar_button[bar_direction]', 'options' => $options, 'selected' => $selected, 'description' => __('The side of the screen from which the Admin Bar will enter (and exit).', $this->plugin_text_domain), 'disabled' => $disabled ) ); } /** * Callback for outputting the 'bar_shown_behaviour' option */ public function _option_bar_shown_behaviour(){ $options = $this->select_options['bar_shown_behaviour']; // Get the valid options for this setting $selected = $this->get_value('bar_shown_behaviour'); // Get the value currently selected for this option $this->do_option( 'select', // Option type 'bar_shown_behaviour', // ID array( // Args 'name' => 'admin_bar_button[bar_shown_behaviour]', 'options' => $options, 'selected' => $selected, 'description' => __('Once the Admin Bar is shown, what should happen to it?', $this->plugin_text_domain) ) ); } /** * Callback for outputting the 'show_time' option */ public function _option_show_time(){ $value = $this->get_value('show_time'); // Get the value currently saved for this option $bar_shown_behaviour = $this->get_value('bar_shown_behaviour'); $readonly = ($bar_shown_behaviour === 'stay') ? true : false; $this->do_option( 'text', // Option type 'show_time', // ID array( // Args 'name' => 'admin_bar_button[show_time]', 'value' => $value, 'class' => 'regular-text', 'description' => __('The time that the Admin Bar will be visible for, when shown.', $this->plugin_text_domain), 'readonly' => $readonly ) ); } /** * Callback for outputting the 'show_hide_button' option */ public function _option_show_hide_button(){ $value = $this->get_value('show_hide_button'); // Get the value currently saved for this option $checked = ($value) ? true : false; $this->do_option( 'checkbox', // Option type 'show_hide_button', // ID array( // Args 'name' => 'admin_bar_button[show_hide_button]', 'checked' => $checked, 'description' => __('Whether or not to include a \'hide\' button on the Admin Bar when it is shown.', $this->plugin_text_domain), 'tips' => array( array( __('Tip', $this->plugin_text_domain), __('Recommended if you set Admin Bar Behaviour to \'Always remain open\'.', $this->plugin_text_domain) ) ) ) ); } /** * Callback for outputting the 'show_wordpress_menu' option */ public function _option_show_wordpress_menu(){ $value = $this->get_value('show_wordpress_menu'); // Get the value currently saved for this option $checked = ($value) ? true : false; $this->do_option( 'checkbox', // Option type 'show_wordpress_menu', // ID array( // Args 'name' => 'admin_bar_button[show_wordpress_menu]', 'checked' => $checked, 'description' => __('Whether or not to include the WordPress menu on the Admin Bar when it is shown.', $this->plugin_text_domain), 'tips' => array( array( __('Tip', $this->plugin_text_domain), __('You\'ll lose access to all of the links if the WordPress menu is not shown.', $this->plugin_text_domain) ) ) ) ); } /** * Callback for outputting the 'admin_bar_color' option */ public function _option_admin_bar_colour(){ $value = $this->get_value('admin_bar_colour'); // Get the value currently saved for this option $this->do_option( 'text', // Option type 'admin_bar_colour', // ID array( // Args 'name' => 'admin_bar_button[admin_bar_colour]', 'value' => $value, 'class' => 'colour-picker', 'description' => __('The background colour of the Admin Bar Button and the WordPress Admin Bar', $this->plugin_text_domain) ) ); } /** * Callback for outputting the 'admin_bar_colour_hover' option */ public function _option_admin_bar_colour_hover(){ $value = $this->get_value('admin_bar_colour_hover'); // Get the value currently saved for this option $this->do_option( 'text', // Option type 'admin_bar_colour_hover', // ID array( // Args 'name' => 'admin_bar_button[admin_bar_colour_hover]', 'value' => $value, 'class' => 'colour-picker', 'description' => __('The background hover hover colour of the Admin Bar Button and the WordPress Admin bar.', $this->plugin_text_domain), 'tips' => array( array( __('Tip', $this->plugin_text_domain), __('Also changes the WordPress Admin Bar sub-menus background colour.', $this->plugin_text_domain) ) ) ) ); } /** * Callback for outputting the 'text_colour' option */ public function _option_text_colour(){ $value = $this->get_value('text_colour'); // Get the value currently saved for this option $this->do_option( 'text', // Option type 'text_colour', // ID array( // Args 'name' => 'admin_bar_button[text_colour]', 'value' => $value, 'class' => 'colour-picker', 'description' => __('The colour of the text for the Admin Bar Button and the WordPress Admin Bar.', $this->plugin_text_domain) ) ); } /** * Callback for outputting the 'text_colour_hover' option */ public function _option_text_colour_hover(){ $value = $this->get_value('text_colour_hover'); // Get the value currently saved for this option $this->do_option( 'text', // Option type 'text_colour_hover', // ID array( // Args 'name' => 'admin_bar_button[text_colour_hover]', 'value' => $value, 'class' => 'colour-picker', 'description' => __('The hover colour of the text for the Admin Bar Button and the WordPress Admin Bar.', $this->plugin_text_domain) ) ); } /** * Get the value of an option, checking first for a saved setting and then taking the default * * @param required string $option The option to get a value for * @return mixed The value for the selected option */ public function get_value($option){ return isset($this->options[$option]) ? $this->options[$option] : $this->dafaults[$option]; } } ?>