options = new ABB_Options(); // Grab an instance of the ABB_Options class add_action('after_setup_theme', array(&$this, 'after_setup_theme')); // Add the necessary theme support add_action('wp_head', array(&$this, 'on_wp_head')); // Output Admin Bar Button display options in the header add_action('wp_enqueue_scripts', array(&$this, 'on_wp_enqueue_scripts')); // Enqueue the necessary front end scripts/styeles add_action('admin_bar_menu', array(&$this, 'on_admin_bar_menu'), 999); // (Maybe) add the hide button to the WordPress admin menu add_action('wp_before_admin_bar_render', array(&$this, 'on_wp_before_admin_bar_render'), 0); // (Maybe) remove the WordPress menu from the WordPress admin menu add_action('wp_after_admin_bar_render', array(&$this, 'on_wp_after_admin_bar_render')); // Output the Admin Bar Button } /** * 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'))); } /** * Output additional WordPress admin bar CSS to the header */ public function on_admin_bar(){ $button_position = $this->options->get('button_position'); $top = (strpos($button_position, 'top') > -1) ? '0' : 'auto'; $bottom = (strpos($button_position, 'bottom') > -1) ? '0' : 'auto'; $left = (strpos($button_position, 'left') > -1) ? '0' : 'auto'; $right = (strpos($button_position, 'right') > -1) // Only one of left/right should cater for 'middle' - no need to set both to 50% ? '0' : ((strpos($button_position, 'middle') > -1) ? '50%' : 'auto'); $reserve_space = $this->options->get('bar_reserve_space'); $background_colour = $this->options->get('admin_bar_colour'); $background_colour_hover = $this->options->get('admin_bar_colour_hover'); $text_colour = $this->options->get('text_colour'); $text_colour_hover = $this->options->get('text_colour_hover'); ?> options->get('button_position'); $animate = $this->options->get('animate'); $animate_duration = $this->options->get('animate_duration'); $animate_direction = $this->options->get('animate_direction'); /** * Work out the animation direction */ if(!$animate) : $direction = false; elseif($button_position === 'top-left') : $direction = ($animate_direction === 'leftright') ? 'left' : 'up'; elseif($button_position === 'top-right') : $direction = ($animate_direction === 'leftright') ? 'right' : 'up'; elseif($button_position === 'top-middle') : $direction = 'up'; elseif($button_position === 'bottom-left') : $direction = ($animate_direction === 'leftright') ? 'left' : 'down'; elseif($button_position === 'bottom-right') : $direction = ($animate_direction === 'leftright') ? 'right' : 'down'; elseif($button_position === 'bottom-middle') : $direction = 'down'; else : $direction = 'left'; endif; /** * Calculate the animation durations */ if(!$animate) : $button_duration = 0; $bar_duration = 0; else : $button_duration = intval(intval($animate_duration) / 3); $bar_duration = intval((intval($animate_duration) / 3) * 2); endif; $bar_auto_hide = $this->options->get('bar_auto_hide'); // Must grab value as an inline check below results in an SVN error ?> options->get('show_hide_button') || is_admin()) // Check to see if the 'hide' button should be shown return; $button_text = 'Hide'; /** * Based on whether or not to animate the showing of the WordPress admin bar, the Admin Bar Button position * and the animation direction, set the dashicon that will be displayed next to the link on the WordPress Admin Bar */ if($this->options->get('animate')) : switch($this->options->get('button_position')) : case 'top-left' : $dashicon = ($this->options->get('animate_direction') === 'leftright') ? 'dashicons-arrow-left-alt' : 'dashicons-arrow-up-alt'; break; case 'top-right' : $dashicon = ($this->options->get('animate_direction') === 'leftright') ? 'dashicons-arrow-right-alt' : 'dashicons-arrow-up-alt'; break; case 'top-middle' : $dashicon = 'dashicons-arrow-up-alt'; break; case 'bottom-left' : $dashicon = ($this->options->get('animate_direction') === 'leftright') ? 'dashicons-arrow-left-alt' : 'dashicons-arrow-down-alt'; break; case 'bottom-right' : $dashicon = ($this->options->get('animate_direction') === 'leftright') ? 'dashicons-arrow-right-alt' : 'dashicons-arrow-down-alt'; break; case 'bottom-middle' : $dashicon = 'dashicons-arrow-down-alt'; break; endswitch; else : $dashicon = 'dashicons-no'; endif; $args = array( // Create the arguments for the hide button 'id' => 'close', 'parent' => false, 'title' => sprintf('%2$s', $dashicon, $button_text), 'href' => '#', 'meta' => array('title' => esc_attr(strip_tags('Hide the admin bar'))) ); $wp_admin_bar->add_node($args); // Add the hide button node } /** * (Maybe) remove the WordPress menu from the WordPress admin menu */ public function on_wp_before_admin_bar_render(){ if(!$this->options->get('show_wordpress_menu')) : global $wp_admin_bar; $wp_admin_bar->remove_menu('wp-logo'); endif; } /** * Output the Admin Bar Button */ public function on_wp_after_admin_bar_render(){ $button_text = $this->options->get('button_text'); ?>