Make WordPress Core

Changeset 62686


Ignore:
Timestamp:
07/10/2026 12:41:52 PM (3 months ago)
Author:
tyxla
Message:

Toolbar: Correctly preview site title and icon changes in the admin bar.

On Settings → General, live-previewing an unsaved site title change no
longer removes the admin bar site icon: the icon element is preserved and
re-prepended when the title text is updated.

Additionally, adding, changing, or removing the site icon is now
live-previewed in the admin bar, keeping the toolbar in sync with the
img.site-icon element and the has-site-icon class before the form is
saved.

Developed in: #12474.

Props fushar, tyxla.
Fixes #65606.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/site-icon.js

    r58927 r62686  
    1515                $hiddenDataField = $( '#site_icon_hidden_field' ),
    1616                $removeButton = $( '#js-remove-site-icon' ),
     17                $adminBarSiteName = $( '#wp-admin-bar-site-name' ),
     18                $adminBarSiteNameLink = $adminBarSiteName.children( 'a' ).first(),
    1719                frame;
    1820
    … …  
    195197                );
    196198
     199                // Replace the site icon in the admin bar.
     200                $adminBarSiteNameLink.children( 'img.site-icon' ).remove();
     201                $( '<img />' )
     202                        .attr( {
     203                                class: 'site-icon',
     204                                src: attributes.url,
     205                                alt: '',
     206                                width: 20,
     207                                height: 20,
     208                        } )
     209                        .prependTo( $adminBarSiteNameLink );
     210                $adminBarSiteName.addClass( 'has-site-icon' );
     211
    197212                // If the choose button is not in the update state, swap the classes.
    198213                if ( $chooseButton.attr( 'data-state' ) !== '1' ) {
    … …  
    225240                        alt: '',
    226241                } );
     242
     243                // Remove the site icon from the admin bar.
     244                $adminBarSiteNameLink.children( 'img.site-icon' ).remove();
     245                $adminBarSiteName.removeClass( 'has-site-icon' );
    227246
    228247                /**
  • trunk/src/wp-admin/includes/options.php

    r61440 r62686  
    4141
    4242                $( '#blogname' ).on( 'input', function() {
    43                         var title = $.trim( $( this ).val() ) || homeURL;
     43                        var title = $.trim( $( this ).val() ) || homeURL,
     44                                $siteIcon = $siteName.children();
    4445
    4546                        // Truncate to 40 characters.
    … …  
    4849                        }
    4950
    50                         $siteName.text( title );
     51                        $siteName.text( title ).prepend( $siteIcon );
    5152                        $siteIconPreview.text( title );
    5253                });
Note: See TracChangeset for help on using the changeset viewer.