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
This commit is contained in:
parent
2c074169e7
commit
b317b87147
|
@ -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(
|
||||
'<img class="blavatar" src="%s" srcset="%s 2x" alt="" width="16" height="16" />',
|
||||
'<img class="blavatar" src="%s" srcset="%s 2x" alt="" width="16" height="16"%s />',
|
||||
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 = '<div class="blavatar"></div>';
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue