: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
'menu_title' => _x( 'New', 'admin bar menu group label' ),
foreach ( $actions as $link => $action ) {
list( $title, $id ) = $action;
'parent' => 'new-content',
'href' => admin_url( $link ),
if ( is_multisite() && current_user_can( 'create_sites' ) ) {
'parent' => 'new-content',
'title' => _x( 'Site', 'add new from admin bar' ),
'href' => network_admin_url( 'site-new.php' ),
* Adds edit comments link with awaiting moderation count bubble.
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_comments_menu( $wp_admin_bar ) {
if ( ! current_user_can( 'edit_posts' ) ) {
$awaiting_mod = wp_count_comments();
$awaiting_mod = $awaiting_mod->moderated;
$awaiting_text = sprintf(
/* translators: Hidden accessibility text. %s: Number of comments. */
_n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ),
number_format_i18n( $awaiting_mod )
$icon = '<span class="ab-icon" aria-hidden="true"></span>';
$title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>';
$title .= '<span class="screen-reader-text comments-in-moderation-text">' . $awaiting_text . '</span>';
'title' => $icon . $title,
'href' => admin_url( 'edit-comments.php' ),
* Adds appearance submenu items to the "Site Name" menu.
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
$wp_admin_bar->add_group(
if ( current_user_can( 'switch_themes' ) ) {
'parent' => 'appearance',
'title' => __( 'Themes' ),
'href' => admin_url( 'themes.php' ),
if ( ! current_user_can( 'edit_theme_options' ) ) {
if ( current_theme_supports( 'widgets' ) ) {
'parent' => 'appearance',
'title' => __( 'Widgets' ),
'href' => admin_url( 'widgets.php' ),
if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) {
'parent' => 'appearance',
'title' => __( 'Menus' ),
'href' => admin_url( 'nav-menus.php' ),
if ( current_theme_supports( 'custom-background' ) ) {
'parent' => 'appearance',
'title' => _x( 'Background', 'custom background' ),
'href' => admin_url( 'themes.php?page=custom-background' ),
'class' => 'hide-if-customize',
if ( current_theme_supports( 'custom-header' ) ) {
'parent' => 'appearance',
'title' => _x( 'Header', 'custom image header' ),
'href' => admin_url( 'themes.php?page=custom-header' ),
'class' => 'hide-if-customize',
* Provides an update link if theme/plugin/core updates are available.
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_updates_menu( $wp_admin_bar ) {
$update_data = wp_get_update_data();
if ( ! $update_data['counts']['total'] ) {
/* translators: Hidden accessibility text. %s: Total number of updates available. */
_n( '%s update available', '%s updates available', $update_data['counts']['total'] ),
number_format_i18n( $update_data['counts']['total'] )
$icon = '<span class="ab-icon" aria-hidden="true"></span>';
$title = '<span class="ab-label" aria-hidden="true">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
$title .= '<span class="screen-reader-text updates-available-text">' . $updates_text . '</span>';
'title' => $icon . $title,
'href' => network_admin_url( 'update-core.php' ),
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_search_menu( $wp_admin_bar ) {
$form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
$form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
$form .= '<label for="adminbar-search" class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
$form .= '<input type="submit" class="adminbar-button" value="' . __( 'Search' ) . '" />';
'parent' => 'top-secondary',
'class' => 'admin-bar-search',
* Adds a link to exit recovery mode when Recovery Mode is active.
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_recovery_mode_menu( $wp_admin_bar ) {
if ( ! wp_is_recovery_mode() ) {
$url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
$url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );
'parent' => 'top-secondary',
'title' => __( 'Exit Recovery Mode' ),
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) {
$wp_admin_bar->add_group(
'class' => 'ab-top-secondary',
$wp_admin_bar->add_group(
'id' => 'wp-logo-external',
'class' => 'ab-sub-secondary',
* Enqueues inline style to hide the admin bar when printing.
function wp_enqueue_admin_bar_header_styles() {
// Back-compat for plugins that disable functionality by unhooking this action.
$action = is_admin() ? 'admin_head' : 'wp_head';
if ( ! has_action( $action, 'wp_admin_bar_header' ) ) {
remove_action( $action, 'wp_admin_bar_header' );
wp_add_inline_style( 'admin-bar', '@media print { #wpadminbar { display:none; } }' );
* Enqueues inline bump styles to make room for the admin bar.
function wp_enqueue_admin_bar_bump_styles() {
if ( current_theme_supports( 'admin-bar' ) ) {
$admin_bar_args = get_theme_support( 'admin-bar' );
$header_callback = $admin_bar_args[0]['callback'];
if ( empty( $header_callback ) ) {
$header_callback = '_admin_bar_bump_cb';
if ( '_admin_bar_bump_cb' !== $header_callback ) {
// Back-compat for plugins that disable functionality by unhooking this action.
if ( ! has_action( 'wp_head', $header_callback ) ) {
remove_action( 'wp_head', $header_callback );
@media screen { html { margin-top: 32px !important; } }
@media screen and ( max-width: 782px ) { html { margin-top: 46px !important; } }
wp_add_inline_style( 'admin-bar', $css );
* Sets the display status of the admin bar.
* This can be called immediately upon plugin load. It does not need to be called
* from a function hooked to the {@see 'init'} action.
* @global bool $show_admin_bar
* @param bool $show Whether to allow the admin bar to show.
function show_admin_bar( $show ) {
$show_admin_bar = (bool) $show;
* Determines whether the admin bar should be showing.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global bool $show_admin_bar
* @global string $pagenow The filename of the current screen.
* @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' ) || wp_is_json_request() ) {
// Integrated into the admin.
if ( ! isset( $show_admin_bar ) ) {
if ( ! is_user_logged_in() || 'wp-login.php' === $pagenow ) {
$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.
* @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 );
* Retrieves the admin bar display preference of a user.
* @param string $context Context of this preference check. Defaults to 'front'. The 'admin'
* preference is no longer used.
* @param int $user Optional. ID of the user to check, defaults to 0 for current user.
* @return bool Whether the admin bar should be showing for this user.
function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
$pref = get_user_option( "show_admin_bar_{$context}", $user );