diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/admin-bar.php --- a/wp/wp-includes/admin-bar.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/admin-bar.php Fri Sep 05 18:40:08 2025 +0200 @@ -41,7 +41,7 @@ */ $admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' ); if ( class_exists( $admin_bar_class ) ) { - $wp_admin_bar = new $admin_bar_class; + $wp_admin_bar = new $admin_bar_class(); } else { return false; } @@ -62,9 +62,8 @@ * the function is also called late on {@see 'wp_footer'}. * * It includes the {@see 'admin_bar_menu'} action which should be used to hook in and - * add new menus to the admin bar. That way you can be sure that you are adding at most - * optimal point, right before the admin bar is rendered. This also gives you access to - * the `$post` global, among others. + * add new menus to the admin bar. This also gives you access to the `$post` global, + * among others. * * @since 3.1.0 * @since 5.4.0 Called on 'wp_body_open' action first, with 'wp_footer' as a fallback. @@ -86,7 +85,10 @@ /** * Loads all necessary admin bar items. * - * This is the hook used to add, remove, or manipulate admin bar items. + * This hook can add, remove, or manipulate admin bar items. The priority + * determines the placement for new items, and changes to existing items + * would require a high priority. To remove or manipulate existing nodes + * without a specific priority, use `wp_before_admin_bar_render`. * * @since 3.1.0 * @@ -122,17 +124,26 @@ */ function wp_admin_bar_wp_menu( $wp_admin_bar ) { if ( current_user_can( 'read' ) ) { - $about_url = self_admin_url( 'about.php' ); + $about_url = self_admin_url( 'about.php' ); + $contribute_url = self_admin_url( 'contribute.php' ); } elseif ( is_multisite() ) { - $about_url = get_dashboard_url( get_current_user_id(), 'about.php' ); + $about_url = get_dashboard_url( get_current_user_id(), 'about.php' ); + $contribute_url = get_dashboard_url( get_current_user_id(), 'contribute.php' ); } else { - $about_url = false; + $about_url = false; + $contribute_url = false; } $wp_logo_menu_args = array( 'id' => 'wp-logo', - 'title' => '' . __( 'About WordPress' ) . '', + 'title' => '' . + /* translators: Hidden accessibility text. */ + __( 'About WordPress' ) . + '', 'href' => $about_url, + 'meta' => array( + 'menu_title' => __( 'About WordPress' ), + ), ); // Set tabindex="0" to make sub menus accessible when no URL is available. @@ -156,6 +167,18 @@ ); } + if ( $contribute_url ) { + // Add contribute link. + $wp_admin_bar->add_node( + array( + 'parent' => 'wp-logo', + 'id' => 'contribute', + 'title' => __( 'Get Involved' ), + 'href' => $contribute_url, + ) + ); + } + // Add WordPress.org link. $wp_admin_bar->add_node( array( @@ -172,7 +195,17 @@ 'parent' => 'wp-logo-external', 'id' => 'documentation', 'title' => __( 'Documentation' ), - 'href' => __( 'https://wordpress.org/support/' ), + 'href' => __( 'https://wordpress.org/documentation/' ), + ) + ); + + // Add learn link. + $wp_admin_bar->add_node( + array( + 'parent' => 'wp-logo-external', + 'id' => 'learn', + 'title' => __( 'Learn WordPress' ), + 'href' => 'https://learn.wordpress.org/', ) ); @@ -209,7 +242,10 @@ $wp_admin_bar->add_node( array( 'id' => 'menu-toggle', - 'title' => '' . __( 'Menu' ) . '', + 'title' => '' . + /* translators: Hidden accessibility text. */ + __( 'Menu' ) . + '', 'href' => '#', ) ); @@ -251,7 +287,10 @@ 'title' => $howdy . $avatar, 'href' => $profile_url, 'meta' => array( - 'class' => $class, + 'class' => $class, + /* translators: %s: Current user's display name. */ + 'menu_title' => sprintf( __( 'Howdy, %s' ), $current_user->display_name ), + 'tabindex' => ( false !== $profile_url ) ? '' : 0, ), ) ); @@ -294,29 +333,19 @@ $user_info .= "{$current_user->user_login}"; } + if ( false !== $profile_url ) { + $user_info .= "" . __( 'Edit Profile' ) . ''; + } + $wp_admin_bar->add_node( array( 'parent' => 'user-actions', 'id' => 'user-info', 'title' => $user_info, 'href' => $profile_url, - 'meta' => array( - 'tabindex' => -1, - ), ) ); - if ( false !== $profile_url ) { - $wp_admin_bar->add_node( - array( - 'parent' => 'user-actions', - 'id' => 'edit-profile', - 'title' => __( 'Edit Profile' ), - 'href' => $profile_url, - ) - ); - } - $wp_admin_bar->add_node( array( 'parent' => 'user-actions', @@ -366,6 +395,9 @@ 'id' => 'site-name', 'title' => $title, 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), + 'meta' => array( + 'menu_title' => $title, + ), ) ); @@ -387,7 +419,7 @@ array( 'parent' => 'site-name', 'id' => 'edit-site', - 'title' => __( 'Edit Site' ), + 'title' => __( 'Manage Site' ), 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), ) ); @@ -405,6 +437,18 @@ // Add the appearance submenu items. wp_admin_bar_appearance_menu( $wp_admin_bar ); + + // Add a Plugins link. + if ( current_user_can( 'activate_plugins' ) ) { + $wp_admin_bar->add_node( + array( + 'parent' => 'site-name', + 'id' => 'plugins', + 'title' => __( 'Plugins' ), + 'href' => admin_url( 'plugins.php' ), + ) + ); + } } } @@ -412,10 +456,16 @@ * Adds the "Edit site" link to the Toolbar. * * @since 5.9.0 + * @since 6.3.0 Added `$_wp_current_template_id` global for editing of current template directly from the admin bar. + * @since 6.6.0 Added the `canvas` query arg to the Site Editor link. + * + * @global string $_wp_current_template_id * * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_edit_site_menu( $wp_admin_bar ) { + global $_wp_current_template_id; + // Don't show if a block theme is not activated. if ( ! wp_is_block_theme() ) { return; @@ -430,7 +480,14 @@ array( 'id' => 'site-editor', 'title' => __( 'Edit site' ), - 'href' => admin_url( 'site-editor.php' ), + 'href' => add_query_arg( + array( + 'postType' => 'wp_template', + 'postId' => $_wp_current_template_id, + 'canvas' => 'edit', + ), + admin_url( 'site-editor.php' ) + ), ) ); } @@ -440,8 +497,9 @@ * * @since 4.3.0 * + * @global WP_Customize_Manager $wp_customize + * * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. - * @global WP_Customize_Manager $wp_customize */ function wp_admin_bar_customize_menu( $wp_admin_bar ) { global $wp_customize; @@ -724,7 +782,7 @@ return; } - $html = ''; + $html = ''; $wp_admin_bar->add_node( array( @@ -809,7 +867,7 @@ ); } elseif ( 'term' === $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) { $tax = get_taxonomy( $tag->taxonomy ); - if ( is_taxonomy_viewable( $tax ) ) { + if ( is_term_publicly_viewable( $tag ) ) { $wp_admin_bar->add_node( array( 'id' => 'view', @@ -865,7 +923,7 @@ ) ); } - } elseif ( is_a( $current_object, 'WP_User' ) && current_user_can( 'edit_user', $current_object->ID ) ) { + } elseif ( $current_object instanceof WP_User && current_user_can( 'edit_user', $current_object->ID ) ) { $edit_user_link = get_edit_user_link( $current_object->ID ); if ( $edit_user_link ) { $wp_admin_bar->add_node( @@ -884,6 +942,7 @@ * Adds "Add New" menu. * * @since 3.1.0 + * @since 6.5.0 Added a New Site link for network installations. * * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ @@ -939,6 +998,9 @@ 'id' => 'new-content', 'title' => $title, 'href' => admin_url( current( array_keys( $actions ) ) ), + 'meta' => array( + 'menu_title' => _x( 'New', 'admin bar menu group label' ), + ), ) ); @@ -954,6 +1016,17 @@ ) ); } + + if ( is_multisite() && current_user_can( 'create_sites' ) ) { + $wp_admin_bar->add_node( + array( + 'parent' => 'new-content', + 'id' => 'add-new-site', + 'title' => _x( 'Site', 'add new from admin bar' ), + 'href' => network_admin_url( 'site-new.php' ), + ) + ); + } } /** @@ -971,7 +1044,7 @@ $awaiting_mod = wp_count_comments(); $awaiting_mod = $awaiting_mod->moderated; $awaiting_text = sprintf( - /* translators: %s: Number of comments. */ + /* translators: Hidden accessibility text. %s: Number of comments. */ _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ); @@ -1046,7 +1119,7 @@ array( 'parent' => 'appearance', 'id' => 'background', - 'title' => __( 'Background' ), + 'title' => _x( 'Background', 'custom background' ), 'href' => admin_url( 'themes.php?page=custom-background' ), 'meta' => array( 'class' => 'hide-if-customize', @@ -1060,7 +1133,7 @@ array( 'parent' => 'appearance', 'id' => 'header', - 'title' => __( 'Header' ), + 'title' => _x( 'Header', 'custom image header' ), 'href' => admin_url( 'themes.php?page=custom-header' ), 'meta' => array( 'class' => 'hide-if-customize', @@ -1068,7 +1141,6 @@ ) ); } - } /** @@ -1087,7 +1159,7 @@ } $updates_text = sprintf( - /* translators: %s: Total number of updates available. */ + /* 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'] ) ); @@ -1119,7 +1191,10 @@ $form = '
'; $form .= ''; - $form .= ''; + $form .= ''; $form .= ''; $form .= '
'; @@ -1191,32 +1266,51 @@ } /** - * Prints style and scripts for the admin bar. + * Enqueues inline style to hide the admin bar when printing. * - * @since 3.1.0 + * @since 6.4.0 */ -function wp_admin_bar_header() { - $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; - ?> - media="print">#wpadminbar { display:none; } - - media="screen"> - html { margin-top: 32px !important; } - @media screen and ( max-width: 782px ) { - html { margin-top: 46px !important; } +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; } - -