确定是否应显示管理栏。

原型

is_admin_bar_showing()

描述

有关此功能和类似主题功能的更多信息,请查看Theme Developer Handbook中的Conditional Tags文章。

返回值

(bool)  是否应显示管理栏。

源文件

路径:wp-includes/admin-bar.php

<?php
...
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;
	if ( is_embed() ) {
		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();
		}
	}
	/**
	 * Filters 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;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/is_admin_bar_showing/