options = new ABB_Options(); // Grab an instance of the ABB_Options class $this->faq = new ABB_FAQ(false); // Grab an instance of the ABB_Options class 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 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->settings_page, // Settings 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 $this->settings_page // Page ); add_settings_field( 'button_text', // ID __('Button text', $this->plugin_text_domain), // Title array($this, '_option_text'), // Callback $this->settings_page, // Page 'abb_button_section', // Section array( // Args 'label_for' => 'button_text', 'type' => 'text', 'control_args' => array( 'name' => 'admin_bar_button[button_text]', 'class' => 'regular-text', 'faq_description' => __('The text to display in the Admin Bar Button. You can set this to anything you want, the button will resize appropriately.', $this->plugin_text_domain) ) ) ); add_settings_field( 'button_position', __('Position on the screen', $this->plugin_text_domain), array($this, '_option_select'), $this->settings_page, 'abb_button_section', array( 'label_for' => 'button_position', 'type' => 'select', 'control_args' => array( 'name' => 'admin_bar_button[button_position]', 'faq_description' => __('Where on the screen to position the Admin Bar Button. You can place the button in any of the four corners. If you choose \'Bottom left\' or \'Bottom right\' then the WordPress admin bar will also be shown on the bottom of the screen.', $this->plugin_text_domain) ) ) ); add_settings_field( 'button_activate', __('Button activated on', $this->plugin_text_domain), array($this, '_option_select'), $this->settings_page, 'abb_button_section', array( 'label_for' => 'button_activate', 'type' => 'select', 'control_args' => array( 'name' => 'admin_bar_button[button_activate]', 'faq_description' => __('The actions that will activate the WordPress admin bar. Currently you can choose between when the user clicks the button, when they hover over it, or both.', $this->plugin_text_domain) ) ) ); /*----------------------------------------------- WordPress Admin Bar -----------------------------------------------*/ add_settings_section( 'abb_bar_section', // ID __('WordPress Admin Bar', $this->plugin_text_domain), // Title false, // Callback $this->settings_page // Page ); add_settings_field( 'bar_reserve_space', // ID __('Reserve space', $this->plugin_text_domain), // Title array($this, '_option_checkbox'), // Callback $this->settings_page, // Page 'abb_bar_section', // Section array( // Args 'label_for' => 'bar_reserve_space', 'type' => 'checkbox', 'control_args' => array( 'name' => 'admin_bar_button[bar_reserve_space]', 'description' => __('Whether or not to reserve space at the top of the page 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) ) ) ) ) ); add_settings_field( 'bar_auto_hide', __('Auto-hide the admin bar', $this->plugin_text_domain), array($this, '_option_checkbox'), $this->settings_page, 'abb_bar_section', array( 'label_for' => 'bar_auto_hide', 'type' => 'checkbox', 'control_args' => array( 'name' => 'admin_bar_button[bar_auto_hide]', 'description' => __('Whether or not to automatically hide the WordPress admin bar.', $this->plugin_text_domain) ) ) ); add_settings_field( 'bar_show_time', __('Admin bar show time (milliseconds)', $this->plugin_text_domain), array($this, '_option_text'), $this->settings_page, 'abb_bar_section', array( 'label_for' => 'bar_show_time', 'type' => 'text', 'control_args' => array( 'name' => 'admin_bar_button[bar_show_time]', 'description' => __('The time that the WordPress admin bar will be visible for.', $this->plugin_text_domain), 'faq_description' => __('The time (in milliseconds) that the WordPress admin bar will be shown for. The minimum time is 5000 (5 seconds), and setting this option to less than that will result in the default being used. This option is irrelevant and so ignored if Auto-hide the admin bar is not checked.', $this->plugin_text_domain), 'tips' => array( array( __('Tip', $this->plugin_text_domain), __('The minimum value is 5000 (5 seconds).', $this->plugin_text_domain) ) ) ) ) ); add_settings_field( 'show_hide_button', __('Show the hide button', $this->plugin_text_domain), array($this, '_option_checkbox'), $this->settings_page, 'abb_bar_section', array( 'label_for' => 'show_hide_button', 'type' => 'checkbox', 'control_args' => array( 'name' => 'admin_bar_button[show_hide_button]', 'description' => __('Whether or not to include a \'Hide\' button on the WordPress admin bar.', $this->plugin_text_domain), 'faq_description' => __('Whether or not to include a \'Hide\' button on the WordPress admin bar. This is recommended if you\'ve not checked Auto-hide the admin bar', $this->plugin_text_domain), 'tips' => array( array( __('Tip', $this->plugin_text_domain), __('Recommended if you\'ve not checked Auto-hide the admin bar.', $this->plugin_text_domain) ) ) ) ) ); add_settings_field( 'show_wordpress_menu', __('Show the WordPress menu', $this->plugin_text_domain), array($this, '_option_checkbox'), $this->settings_page, 'abb_bar_section', array( 'label_for' => 'show_wordpress_menu', 'type' => 'checkbox', 'control_args' => array( 'name' => 'admin_bar_button[show_wordpress_menu]', 'description' => __('Whether or not to include the WordPress menu on the WordPress admin bar, when it\'s shown.', $this->plugin_text_domain), 'faq_description' => __('Whether or not to include the WordPress menu on the WordPress admin bar, when it\'s shown. Beware that you\'ll lose access to all of the links in the WordPress menu if it\'s not shown.', $this->plugin_text_domain), 'tips' => array( array( __('Tip', $this->plugin_text_domain), __('You\'ll lose access to all of the links in the WordPress menu if it\'s not shown.', $this->plugin_text_domain) ) ) ) ) ); /*----------------------------------------------- Admin Bar Button / WordPress Admin Bar Colours -----------------------------------------------*/ add_settings_section( 'abb_colours_section', // ID __('Colours', $this->plugin_text_domain), // Title false, // Callback $this->settings_page // Page ); add_settings_field( 'admin_bar_colour', // ID __('Background colour', $this->plugin_text_domain), // Title array($this, '_option_text'), // Callback $this->settings_page, // Page 'abb_colours_section', // Section array( // Args 'id' => 'admin_bar_colour', 'type' => 'text', 'control_args' => array( 'name' => 'admin_bar_button[admin_bar_colour]', 'class' => 'abb-colour-picker', 'description' => __('The background colour of the Admin Bar Button and the WordPress admin bar', $this->plugin_text_domain) ) ) ); add_settings_field( 'admin_bar_colour_hover', __('Background colour (hover)', $this->plugin_text_domain), array($this, '_option_text'), $this->settings_page, 'abb_colours_section', array( 'id' => 'admin_bar_colour_hover', 'type' => 'text', 'control_args' => array( 'name' => 'admin_bar_button[admin_bar_colour_hover]', 'class' => 'abb-colour-picker', 'description' => __('The background hover colour of the Admin Bar Button and the WordPress admin bar.', $this->plugin_text_domain), 'faq_description' => __('The background hover colour of the Admin Bar Button and the WordPress admin bar. Also changes the WordPress admin bar sub-menus background colour. Note that only the colour of buttons which are hovered will change, not the entire 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) ) ) ) ) ); add_settings_field( 'text_colour', __('Text colour', $this->plugin_text_domain), array($this, '_option_text'), $this->settings_page, 'abb_colours_section', array( 'id' => 'text_colour', 'type' => 'text', 'control_args' => array( 'name' => 'admin_bar_button[text_colour]', 'class' => 'abb-colour-picker', 'description' => __('The colour of the text for the Admin Bar Button and the WordPress admin bar.', $this->plugin_text_domain) ) ) ); add_settings_field( 'text_colour_hover', __('Text colour (hover)', $this->plugin_text_domain), array($this, '_option_text'), $this->settings_page, 'abb_colours_section', array( 'id' => 'text_colour_hover', 'type' => 'text', 'control_args' => array( 'name' => 'admin_bar_button[text_colour_hover]', 'class' => 'abb-colour-picker', 'description' => __('The hover colour of the text for the Admin Bar Button and the WordPress admin bar.', $this->plugin_text_domain) ) ) ); /*----------------------------------------------- Animations -----------------------------------------------*/ add_settings_section( 'abb_animation_section', // ID __('Animation', $this->plugin_text_domain), // Title false, // Callback $this->settings_page // Page ); add_settings_field( 'animate', // ID __('Animate actions', $this->plugin_text_domain), // Title array($this, '_option_checkbox'), // Callback $this->settings_page, // Page 'abb_animation_section', // Section array( // Args 'label_for' => 'animate', 'type' => 'checkbox', 'control_args' => array( 'name' => 'admin_bar_button[animate]', 'description' => __('Whether or not to animate the showing/hiding of the WordPress admin bar.', $this->plugin_text_domain) ) ) ); add_settings_field( 'animate_duration', __('Animation duration (milliseconds)', $this->plugin_text_domain), array($this, '_option_text'), $this->settings_page, 'abb_animation_section', array( 'label_for' => 'animate_duration', 'type' => 'text', 'control_args' => array( 'name' => 'admin_bar_button[animate_duration]', 'description' => __('The time that it takes for the Admin Bar Button to slide off of the screen and be replaced by the WordPress admin bar (and vice versa).', $this->plugin_text_domain), 'faq_description' => __('The time (in milliseconds) that it takes for the Admin Bar Button to slide off of the screen and be replaced by the WordPress admin bar (and vice versa). Any positive value is acceptable, and setting \'0\' will disable the animation.', $this->plugin_text_domain) ) ) ); add_settings_field( 'animate_direction', __('Animation direction', $this->plugin_text_domain), array($this, '_option_select'), $this->settings_page, 'abb_animation_section', array( 'label_for' => 'animate_direction', 'type' => 'select', 'control_args' => array( 'name' => 'admin_bar_button[animate_direction]', 'description' => __('The direction in which the WordPress admin bar will enter/exit the screen.', $this->plugin_text_domain) ) ) ); } /** * 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_style('abb-colour-picker', plugins_url('css/rgba-color-picker.css?scope=admin-bar-button', __FILE__)); wp_enqueue_script('abb-colour-picker', plugins_url('js/rgba-color-picker.js?scope=admin-bar-button', __FILE__), array('jquery','wp-color-picker'), '', true); wp_enqueue_style('abb-admin', plugins_url('css/abb-admin.css?scope=admin-bar-button', __FILE__)); wp_enqueue_script('abb-admin', plugins_url('js/abb-admin.js?scope=admin-bar-button', __FILE__), array('jquery-ui-tabs')); } /** * Enqueue the necessary admin styles */ public function on_admin_print_styles(){ ?>

plugin_text_domain); ?>

do_settings_sections_tabs($this->settings_page); ?> do_settings_sections_tab_content($this->settings_page); ?>
options = new ABB_Options(); // Grab an instance of the ABB_Options class $new_input = array( 'button_text' => $this->sanitize_text($input, 'button_text'), // Button - text 'button_position' => $this->sanitize_select($input, 'button_position'), // Button - position 'button_activate' => $this->sanitize_select($input, 'button_activate'), // Button - activate 'bar_reserve_space' => $this->sanitize_checkbox($input, 'bar_reserve_space'), // Bar - reserve space 'bar_auto_hide' => $this->sanitize_checkbox($input, 'bar_auto_hide'), // Bar - auto-hide 'bar_show_time' => $this->sanitize_int($input, 'bar_show_time', 2000), // Bar - show time 'show_hide_button' => $this->sanitize_checkbox($input, 'show_hide_button'), // Bar - show hide button 'show_wordpress_menu' => $this->sanitize_checkbox($input, 'show_wordpress_menu'), // Bar - show WordPress menu 'admin_bar_colour' => $this->sanitize_hex_rgba($input, 'admin_bar_colour'), // Colours - bar background 'admin_bar_colour_hover' => $this->sanitize_hex_rgba($input, 'admin_bar_colour_hover'), // Colours - bar background (hover) 'text_colour' => $this->sanitize_hex_rgba($input, 'text_colour'), // Colours - text 'text_colour_hover' => $this->sanitize_hex_rgba($input, 'text_colour_hover'), // Colours - text (hover) 'animate' => $this->sanitize_checkbox($input, 'animate'), // Animations - animate actions 'animate_duration' => $this->sanitize_int($input, 'animate_duration', 0), // Animations - duration 'animate_direction' => $this->sanitize_select($input, 'animate_direction') // Animations - direction ); return array_filter($new_input, array(&$this, '_filter_not_false')); } /** * Sanitize an option before it is saved * * @param required array $input The unsanitized options * @param required string $option_id The ID of the option to sanitize * @return string|boolean The sanitized option, or false on error */ private function sanitize_text($input, $option_id){ if(isset($input[$option_id])) : $text = sanitize_text_field($input[$option_id]); return ($text !== '') ? $text : $this->options->get_default($option_id); endif; return false; } /** * Sanitize an option before it is saved * * @param required array $input The unsanitized options * @param required string $option_id The ID of the option to sanitize * @return string|boolean The sanitized option, or false on error */ private function sanitize_checkbox($input, $option_id){ if(isset($input[$option_id])) : return (isset($input[$option_id])) ? $input[$option_id] : intval($this->options->get_default($option_id)); endif; return false; } /** * Sanitize a option before it is saved * The option must be an absolute integer, and can have a minimum value if required * * @param required array $input The unsanitized options * @param required string $option_id The ID of the option to sanitize * @param integer|boolean $minimum The minimum acceptable value * @return string|boolean The sanitized option, or false on error */ private function sanitize_int($input, $option_id, $minimum = false){ if(isset($input[$option_id])) : $val = absint($input[$option_id]); if(is_int($minimum)) : return ($val >= $minimum) ? $val : $this->options->get_default($option_id); else : return $val; endif; endif; return false; } /** * Sanitize an plugin_text_domain); ?>

plugin_text_domain); ?>

plugin_text_domain); ?> plugin_text_domain); ?>

plugin_text_domain); ?> plugin_text_domain); ?> plugin_text_domain); ?>

faq->do_faq(false); } /** * Callback for outputting the 'Support' halp tab */ public function do_help_support(){ ?>

plugin_text_domain); ?> plugin_text_domain); ?> plugin_text_domain); ?>

plugin_text_domain); ?>

plugin_text_domain); ?>

plugin_text_domain); ?> plugin_text_domain); ?>

'; foreach((array)$wp_settings_sections[$page] as $section) : if(!isset($section['title'])) continue; printf('%2$s', /** %1$s - The ID of the tab */ $section['id'], /** %2$s - The Title of the section */ $section['title'] ); endforeach; do_action('abb_after_tabs'); echo ''; } /** * Output the tab content for each of the setting sections * * @param required string $page The plugin page to outplt settings for */ private function do_settings_sections_tab_content($page){ global $wp_settings_sections, $wp_settings_fields; if(!isset($wp_settings_sections[$page])) return; echo '
'; settings_fields('admin_bar_button_group'); foreach((array)$wp_settings_sections[$page] as $section) : printf(''; endforeach; do_action('abb_after_tab_contents'); echo '

'; submit_button('Save Changes', 'primary', 'submit', false); submit_button('Restore Defaults', 'delete', 'delete', false); echo '

'; 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 an option * * @param required array $args The option args */ public function _option_text($args){ $id = (isset($args['id'])) ? $args['id'] : $args['label_for']; // Grab the option ID $args['control_args']['value'] = $this->options->get($id); // Get the value currently saved for this option $this->do_option( $args['type'], // Option type $id, // ID $args['control_args'] // Args ); } /** * Callback for outputting an option * * @param required array $args The option args */ public function _option_checkbox($args){ $id = (isset($args['id'])) ? $args['id'] : $args['label_for']; // Grab the option ID $args['control_args']['checked'] = ($this->options->get($id)); // Whether or not this option should be 'checked' $this->do_option( $args['type'], // Option type $id, // ID $args['control_args'] // Args ); } /** * Callback for outputting a