diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index 1bfa8970fd..6e9962274d 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -11,12 +11,7 @@ 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 ) ) + if ( ! show_admin_bar() ) return false; /* Set the protocol constant used throughout this code */ diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 8ad588f771..f7a08565e6 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -4405,12 +4405,32 @@ function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = ar } /** - * Prevents the admin bar from being shown for the current screen. + * Retrieve or set the admin bar display state. * * This can be called immediately upon plugin load. It does not need to be called from a function hooked to the init action. * + * @param bool $show Optional. True to show the admin bar, false to hide it. If not provided the current display state is returned. + * @return bool The current display state if $show is not provided, the previous disply state if $show is provided. + * * @since 3.1.0 */ -function no_admin_bar() { - define('WP_SHOW_ADMIN_BAR', false); +function show_admin_bar( $show = null ) { + static $show_admin_bar = null; + + if ( !isset($show_admin_var) ) { + if ( null !== $show ) + $show_admin_bar = $show; + elseif ( defined('WP_SHOW_ADMIN_BAR') ) + $show_admin_bar = WP_SHOW_ADMIN_BAR; + else + $show_admin_bar = true; + } + + if ( null == $show ) { + return $show_admin_bar; + } else { + $old_value = $show_admin_bar; + $show_admin_bar = $show; + return $old_value; + } }