返回介绍

is_admin_bar_showing()

发布于 2017-09-11 01:10:04 字数 2755 浏览 1002 评论 0 收藏 0

is_admin_bar_showing()

Determine whether the admin bar should be showing.


description


返回值

(bool) Whether the admin bar should be showing.


源代码

File: wp-includes/admin-bar.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;
}

更新日志

Versiondescription
3.1.0Introduced.

相关函数

Uses

  • wp-includes/query.php: is_embed()
  • wp-includes/pluggable.php: is_user_logged_in()
  • wp-includes/load.php: is_admin()
  • wp-includes/admin-bar.php: _get_admin_bar_pref()
  • wp-includes/admin-bar.php: show_admin_bar
  • wp-includes/plugin.php: apply_filters()
  • Show 1 more use Hide more uses

Used By

  • wp-admin/includes/template.php: _wp_admin_html_begin()
  • wp-includes/admin-bar.php: _wp_admin_bar_init()
  • wp-includes/admin-bar.php: wp_admin_bar_render()
  • wp-includes/post-template.php: get_body_class()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example

    
    if ( is_admin_bar_showing() ) {
        // do something
    }
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文