show_admin_bar(). see #14772

git-svn-id: http://svn.automattic.com/wordpress/trunk@15863 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-10-20 13:23:39 +00:00
parent 86274d836d
commit 2814ee67e1
2 changed files with 24 additions and 9 deletions

View File

@ -11,12 +11,7 @@
function wp_admin_bar_init() { function wp_admin_bar_init() {
global $current_user, $pagenow, $wp_admin_bar; global $current_user, $pagenow, $wp_admin_bar;
if ( defined('WP_SHOW_ADMIN_BAR') ) if ( ! show_admin_bar() )
$show_it = (bool) WP_SHOW_ADMIN_BAR;
else
$show_it = true;
if ( ! apply_filters( 'show_admin_bar', $show_it ) )
return false; return false;
/* Set the protocol constant used throughout this code */ /* Set the protocol constant used throughout this code */

View File

@ -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. * 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 * @since 3.1.0
*/ */
function no_admin_bar() { function show_admin_bar( $show = null ) {
define('WP_SHOW_ADMIN_BAR', false); 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;
}
} }