From b317b8714779c00973aab8f7db5214bc650d84a9 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Thu, 7 Apr 2022 22:14:05 +0000 Subject: [PATCH] Toolbar: Add a filter to help remove site icons from toolbar for large multisite, and lazy load them by default. This changeset introduces the `wp_admin_bar_show_site_icons` filter to help developers to hide site icons from the toolbar, as it may have negative performance impact on large multisites. It also adds a default lazy load behavior for these icons. Props wslyhbb, sabernhardt, lkraav, kebbet, peterwilsoncc. Fixes #54447 Built from https://develop.svn.wordpress.org/trunk@53100 git-svn-id: http://core.svn.wordpress.org/trunk@52689 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/admin-bar.php | 19 ++++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index 6f05fb7b26..274212acf7 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -611,14 +611,27 @@ function wp_admin_bar_my_sites_menu( $wp_admin_bar ) { ) ); + /** + * 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 = '
'; diff --git a/wp-includes/version.php b/wp-includes/version.php index 4b03bb10e5..e4058e8822 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-53099'; +$wp_version = '6.0-alpha-53100'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.