From 580bf5eead7d490ef22bc3f98655f89bbe8cc472 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 18 Oct 2010 17:58:36 +0000 Subject: [PATCH] Allow turning off the admin bar via WP_SHOW_ADMIN_BAR constant, no_admin_bar() function, or show_admin_bar filter. see #14772 git-svn-id: http://svn.automattic.com/wordpress/trunk@15834 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/media-upload.php | 2 ++ wp-admin/press-this.php | 3 +++ wp-admin/update.php | 2 ++ wp-includes/admin-bar.php | 21 +++++++++++++++------ wp-includes/functions.php | 11 +++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/wp-admin/media-upload.php b/wp-admin/media-upload.php index bd21e4bc4..83cfb4cf6 100644 --- a/wp-admin/media-upload.php +++ b/wp-admin/media-upload.php @@ -9,6 +9,8 @@ * @subpackage Administration */ +define('WP_SHOW_ADMIN_BAR' , false); + /** Load WordPress Administration Bootstrap */ require_once('./admin.php'); diff --git a/wp-admin/press-this.php b/wp-admin/press-this.php index 903992cb2..fcf366bd0 100644 --- a/wp-admin/press-this.php +++ b/wp-admin/press-this.php @@ -6,8 +6,11 @@ * @subpackage Press_This */ +define('WP_SHOW_ADMIN_BAR' , false); + /** WordPress Administration Bootstrap */ require_once('./admin.php'); + header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); if ( ! current_user_can('edit_posts') ) diff --git a/wp-admin/update.php b/wp-admin/update.php index 0664ac8f3..4aed33bb7 100644 --- a/wp-admin/update.php +++ b/wp-admin/update.php @@ -6,6 +6,8 @@ * @subpackage Administration */ +define('WP_SHOW_ADMIN_BAR' , false); + /** WordPress Administration Bootstrap */ require_once('./admin.php'); diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index 94d2da32f..355651125 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -11,12 +11,20 @@ function wp_admin_bar_init() { global $current_user, $pagenow, $wp_admin_bar; + if ( defined('WP_SHOW_ADMIN_BAR') ) + $show_it = (bool) WP_SHOW_ADMIN_BAR; + else + $show_it = true; + + if ( ! apply_filters('show_admin_bar', $show_it, get_current_screen() ) ) + return false; + /* Set the protocol constant used throughout this code */ if ( !defined( 'PROTO' ) ) if ( is_ssl() ) define( 'PROTO', 'https://' ); else define( 'PROTO', 'http://' ); - /* Don't load the admin bar if the user is not logged in, or we are using press this */ - if ( !is_user_logged_in() || 'press-this.php' == $pagenow || 'update.php' == $pagenow ) + /* Don't load the admin bar if the user is not logged in */ + if ( !is_user_logged_in() ) return false; /* Set up the settings we need to render menu items */ @@ -26,7 +34,7 @@ function wp_admin_bar_init() { /* Enqueue the JS files for the admin bar. */ if ( is_user_logged_in() ) wp_enqueue_script( 'jquery', false, false, false, true ); - + /* Load the admin bar class code ready for instantiation */ require( ABSPATH . WPINC . '/admin-bar/admin-bar-class.php' ); @@ -38,6 +46,9 @@ function wp_admin_bar_init() { /* Initialize the admin bar */ $wp_admin_bar = new wp_admin_bar(); + + add_action( 'wp_head', 'wp_admin_bar_css' ); + add_action( 'admin_head', 'wp_admin_bar_css' ); } add_action( 'init', 'wp_admin_bar_init' ); @@ -221,7 +232,7 @@ add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_edit_menu', 100 ); function wp_admin_bar_css() { global $pagenow, $wp_locale; - if ( !is_user_logged_in() || 'press-this.php' == $pagenow || 'update.php' == $pagenow || 'media-upload.php' == $pagenow ) + if ( !is_user_logged_in() ) return; $nobump = false; @@ -232,8 +243,6 @@ function wp_admin_bar_css() {