is_admin_bar_showing

函式
is_admin_bar_showing ( No parameters )
返回值
  • (bool) Whether the admin bar should be showing.
定義位置
相關方法
wp_admin_bar_shortlink_menu_wp_admin_bar_initwp_admin_bar_site_menushow_admin_barwp_admin_bar_wp_menu
引入
3.1.0
棄用
-

is_admin_bar_showing: 這個函式用來檢查WordPress的管理欄當前是否正在顯示。如果管理欄正在顯示,它返回true,否則返回false。

確定管理欄是否應該顯示。

關於這個和類似主題函式的更多資訊,請檢視《主題開發者手冊》中的{@link Conditional Tags}文章。

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' ) || wp_is_json_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;
}

常見問題

FAQs
檢視更多 >