array( 'parent' => 'appearance', 'id' => 'themes', 'title' => __( 'Themes' ), 'href' => admin_url( 'themes.php' ), ) ); } if ( ! current_user_can( 'edit_theme_options' ) ) { return; } if ( current_theme_supports( 'widgets' ) ) { $wp_admin_bar->add_node( array( 'parent' => 'appearance', 'id' => 'widgets', 'title' => __( 'Widgets' ), 'href' => admin_url( 'widgets.php' ), ) ); } if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) { $wp_admin_bar->add_node( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __( 'Menus' ), 'href' => admin_url( 'nav-menus.php' ), ) ); } if ( current_theme_supports( 'custom-background' ) ) { $wp_admin_bar->add_node( array( 'parent' => 'appearance', 'id' => 'background', 'title' => _x( 'Background', 'custom background' ), 'href' => admin_url( 'themes.php?page=custom-background' ), 'meta' => array( 'class' => 'hide-if-customize', ), ) ); } if ( current_theme_supports( 'custom-header' ) ) { $wp_admin_bar->add_node( array( 'parent' => 'appearance', 'id' => 'header', 'title' => _x( 'Header', 'custom image header' ), 'href' => admin_url( 'themes.php?page=custom-header' ), 'meta' => array( 'class' => 'hide-if-customize', ), ) ); } } /** * Provides an update link if theme/plugin/core updates are available. * * @since 3.1.0 * * @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'] ) { return; } $updates_text = sprintf( /* 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 = ''; $title = ''; $title .= '' . $updates_text . ''; $wp_admin_bar->add_node( array( 'id' => 'updates', 'title' => $icon . $title, 'href' => network_admin_url( 'update-core.php' ), ) ); } /** * Adds search form. * * @since 3.3.0 * * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_search_menu( $wp_admin_bar ) { if ( is_admin() ) { return; } $form = '
'; $form .= ''; $form .= ''; $form .= ''; $form .= '
'; $wp_admin_bar->add_node( array( 'parent' => 'top-secondary', 'id' => 'search', 'title' => $form, 'meta' => array( 'class' => 'admin-bar-search', 'tabindex' => -1, ), ) ); } /** * Adds a link to exit recovery mode when Recovery Mode is active. * * @since 5.2.0 * * @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() ) { return; } $url = wp_login_url(); $url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url ); $url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION ); $wp_admin_bar->add_node( array( 'parent' => 'top-secondary', 'id' => 'recovery-mode', 'title' => __( 'Exit Recovery Mode' ), 'href' => $url, ) ); } /** * Adds secondary menus. * * @since 3.3.0 * * @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( array( 'id' => 'top-secondary', 'meta' => array( 'class' => 'ab-top-secondary', ), ) ); $wp_admin_bar->add_group( array( 'parent' => 'wp-logo', 'id' => 'wp-logo-external', 'meta' => array( 'class' => 'ab-sub-secondary', ), ) ); } /** * Enqueues inline style to hide the admin bar when printing. * * @since 6.4.0 */ 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' ) ) { return; } 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. * * @since 6.4.0 */ 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 ) { return; } // Back-compat for plugins that disable functionality by unhooking this action. if ( ! has_action( 'wp_head', $header_callback ) ) { return; } remove_action( 'wp_head', $header_callback ); $css = ' @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. * * @since 3.1.0 * * @global bool $show_admin_bar * * @param bool $show Whether to allow the admin bar to show. */ function show_admin_bar( $show ) { global $show_admin_bar; $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. * * @since 3.1.0 * * @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() ) { 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; } /** * Retrieves the admin bar display preference of a user. * * @since 3.1.0 * @access private * * @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 ); if ( false === $pref ) { return true; } return 'true' === $pref; }