diff -r be944660c56a -r 3d72ae0968f4 wp/wp-includes/admin-bar.php --- a/wp/wp-includes/admin-bar.php Wed Sep 21 18:19:35 2022 +0200 +++ b/wp/wp-includes/admin-bar.php Tue Sep 27 16:37:53 2022 +0200 @@ -8,7 +8,7 @@ */ /** - * Instantiate the admin bar object and set it up as a global for access elsewhere. + * Instantiates the admin bar object and set it up as a global for access elsewhere. * * UNHOOKING THIS FUNCTION WILL NOT PROPERLY REMOVE THE ADMIN BAR. * For that, use show_admin_bar(false) or the {@see 'show_admin_bar'} filter. @@ -84,13 +84,13 @@ } /** - * Load all necessary admin bar items. + * Loads all necessary admin bar items. * * This is the hook used to add, remove, or manipulate admin bar items. * * @since 3.1.0 * - * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance, passed by reference. */ do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) ); @@ -114,11 +114,11 @@ } /** - * Add the WordPress logo menu. + * Adds the WordPress logo menu. * * @since 3.3.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_wp_menu( $wp_admin_bar ) { if ( current_user_can( 'read' ) ) { @@ -198,11 +198,11 @@ } /** - * Add the sidebar toggle button. + * Adds the sidebar toggle button. * * @since 3.8.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) { if ( is_admin() ) { @@ -217,11 +217,11 @@ } /** - * Add the "My Account" item. + * Adds the "My Account" item. * * @since 3.3.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_my_account_item( $wp_admin_bar ) { $user_id = get_current_user_id(); @@ -258,11 +258,11 @@ } /** - * Add the "My Account" submenu items. + * Adds the "My Account" submenu items. * * @since 3.1.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_my_account_menu( $wp_admin_bar ) { $user_id = get_current_user_id(); @@ -328,11 +328,11 @@ } /** - * Add the "Site Name" menu. + * Adds the "Site Name" menu. * * @since 3.3.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_site_menu( $wp_admin_bar ) { // Don't show for logged out users. @@ -409,16 +409,48 @@ } /** + * Adds the "Edit site" link to the Toolbar. + * + * @since 5.9.0 + * + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. + */ +function wp_admin_bar_edit_site_menu( $wp_admin_bar ) { + // Don't show if a block theme is not activated. + if ( ! wp_is_block_theme() ) { + return; + } + + // Don't show for users who can't edit theme options or when in the admin. + if ( ! current_user_can( 'edit_theme_options' ) || is_admin() ) { + return; + } + + $wp_admin_bar->add_node( + array( + 'id' => 'site-editor', + 'title' => __( 'Edit site' ), + 'href' => admin_url( 'site-editor.php' ), + ) + ); +} + +/** * Adds the "Customize" link to the Toolbar. * * @since 4.3.0 * - * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance. + * @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; + // Don't show if a block theme is activated and no plugins use the customizer. + if ( wp_is_block_theme() && ! has_action( 'customize_register' ) ) { + return; + } + // Don't show for users who can't access the customizer or when in the admin. if ( ! current_user_can( 'customize' ) || is_admin() ) { return; @@ -455,11 +487,11 @@ } /** - * Add the "My Sites/[Site Name]" menu and all submenus. + * Adds the "My Sites/[Site Name]" menu and all submenus. * * @since 3.1.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_my_sites_menu( $wp_admin_bar ) { // Don't show for logged out users or single site mode. @@ -579,14 +611,27 @@ ) ); + /** + * Filters whether to show the site icons in toolbar. + * + * Returning false to this hook is the recommended way to hide site icons in the toolbar. + * A truthy return may have negative performance impact on large multisites. + * + * @since 6.0.0 + * + * @param bool $show_site_icons Whether site icons should be shown in the toolbar. Default true. + */ + $show_site_icons = apply_filters( 'wp_admin_bar_show_site_icons', true ); + foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { switch_to_blog( $blog->userblog_id ); - if ( has_site_icon() ) { + if ( true === $show_site_icons && has_site_icon() ) { $blavatar = sprintf( - '', + '', esc_url( get_site_icon_url( 16 ) ), - esc_url( get_site_icon_url( 32 ) ) + esc_url( get_site_icon_url( 32 ) ), + ( wp_lazy_loading_enabled( 'img', 'site_icon_in_toolbar' ) ? ' loading="lazy"' : '' ) ); } else { $blavatar = '
'; @@ -665,11 +710,11 @@ } /** - * Provide a shortlink. + * Provides a shortlink. * * @since 3.1.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_shortlink_menu( $wp_admin_bar ) { $short = wp_get_shortlink( 0, 'query' ); @@ -692,7 +737,7 @@ } /** - * Provide an edit link for posts and terms. + * Provides an edit link for posts and terms. * * @since 3.1.0 * @since 5.5.0 Added a "View Post" link on Comments screen for a single post. @@ -703,7 +748,7 @@ * global $user_ID, which contains the ID of the current user. * @global int $post_id The ID of the post when editing comments for a single post. * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_edit_menu( $wp_admin_bar ) { global $tag, $wp_the_query, $user_id, $post_id; @@ -836,11 +881,11 @@ } /** - * Add "Add New" menu. + * Adds "Add New" menu. * * @since 3.1.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_new_content_menu( $wp_admin_bar ) { $actions = array(); @@ -912,11 +957,11 @@ } /** - * Add edit comments link with awaiting moderation count bubble. + * Adds edit comments link with awaiting moderation count bubble. * * @since 3.1.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @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' ) ) { @@ -945,11 +990,11 @@ } /** - * Add appearance submenu items to the "Site Name" menu. + * Adds appearance submenu items to the "Site Name" menu. * * @since 3.1.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @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( @@ -1027,11 +1072,11 @@ } /** - * Provide an update link if theme/plugin/core updates are available. + * Provides an update link if theme/plugin/core updates are available. * * @since 3.1.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_updates_menu( $wp_admin_bar ) { @@ -1061,11 +1106,11 @@ } /** - * Add search form. + * Adds search form. * * @since 3.3.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */ function wp_admin_bar_search_menu( $wp_admin_bar ) { if ( is_admin() ) { @@ -1092,11 +1137,11 @@ } /** - * Add a link to exit recovery mode when Recovery Mode is active. + * Adds a link to exit recovery mode when Recovery Mode is active. * * @since 5.2.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @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() ) { @@ -1118,11 +1163,11 @@ } /** - * Add secondary menus. + * Adds secondary menus. * * @since 3.3.0 * - * @param WP_Admin_Bar $wp_admin_bar + * @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( @@ -1146,7 +1191,7 @@ } /** - * Style and scripts for the admin bar. + * Prints style and scripts for the admin bar. * * @since 3.1.0 */ @@ -1158,7 +1203,7 @@ } /** - * Default admin bar callback. + * Prints default admin bar callback. * * @since 3.1.0 */ @@ -1167,10 +1212,8 @@ ?> media="screen"> html { margin-top: 32px !important; } - * html body { margin-top: 32px !important; } @media screen and ( max-width: 782px ) { html { margin-top: 46px !important; } - * html body { margin-top: 46px !important; } }