is_admin_bar_showing()判断当前顶部工具栏admin_bar是否显示

目录

描述

This Conditional Tag checks if the WordPress Toolbar is being displayed. This is a boolean function, meaning it returns either TRUE or FALSE.

is_admin_bar_showing() 描述

用法

<?php is_admin_bar_showing(); ?>

is_admin_bar_showing() 用法

参数

This tag does not accept any parameters.

is_admin_bar_showing() 参数

返回值

(boolean) 

True on success, false on failure.

is_admin_bar_showing() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php
if ( is_admin_bar_showing() ) {
    // do something
}
?>

is_admin_bar_showing() 示例

注意

  • This function will always return true in the WordPress admin.
  • 使用到 _get_admin_bar_pref().

is_admin_bar_showing() 注意

历史

添加于 版本: 3.1.0

is_admin_bar_showing() 历史

源文件

is_admin_bar_showing() 函数的代码位于 wp-includes/admin-bar.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Determine whether the admin bar should be showing.
 *
 * @since 3.1.0
 *
 * @global WP_Admin_Bar $wp_admin_bar
 * @global string       $pagenow
 *
 * @return bool Whether the admin bar should be showing.
 */
function is_admin_bar_showing() {
	global $show_admin_bar, $pagenow;

	// For all these types of requests, we never want an admin bar.
	if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )
		return false;

	// Integrated into the admin.
	if ( is_admin() )
		return true;

	if ( ! isset( $show_admin_bar ) ) {
		if ( ! is_user_logged_in() || 'wp-login.php' == $pagenow ) {
			$show_admin_bar = false;
		} else {
			$show_admin_bar = _get_admin_bar_pref();
		}
	}

	/**
	 * Filter whether to show the admin bar.
	 *
	 * Returning false to this hook is the recommended way to hide the admin bar.
	 * The user's display preference is used for logged in users.
	 *
	 * @since 3.1.0
	 *
	 * @param bool $show_admin_bar Whether the admin bar should be shown. Default false.
	 */
	$show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar );

	return $show_admin_bar;
}

is_admin_bar_showing() 源文件

相关