Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/js/_enqueues/admin/site-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
$appIconPreview = $( '#app-icon-preview' ),
$hiddenDataField = $( '#site_icon_hidden_field' ),
$removeButton = $( '#js-remove-site-icon' ),
$adminBarSiteName = $( '#wp-admin-bar-site-name' ),
$adminBarSiteNameLink = $adminBarSiteName.children( 'a' ).first(),
frame;

/**
Expand Down Expand Up @@ -194,6 +196,19 @@
'url(' + attributes.url + ')'
);

// Replace the site icon in the admin bar.
$adminBarSiteNameLink.children( 'img.site-icon' ).remove();
$( '<img />' )
.attr( {
class: 'site-icon',
src: attributes.url,
alt: '',
width: 20,
height: 20,
Comment on lines +203 to +207

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor divergence from the original markup is the missing srcset here, although practically it's not an issue because it already uses the original (likely large) image.

} )
.prependTo( $adminBarSiteNameLink );
$adminBarSiteName.addClass( 'has-site-icon' );

// If the choose button is not in the update state, swap the classes.
if ( $chooseButton.attr( 'data-state' ) !== '1' ) {
$chooseButton.attr( {
Expand Down Expand Up @@ -225,6 +240,10 @@
alt: '',
} );

// Remove the site icon from the admin bar.
$adminBarSiteNameLink.children( 'img.site-icon' ).remove();
$adminBarSiteName.removeClass( 'has-site-icon' );

/**
* Resets state to the button, for correct visual style and state.
* Updates the text of the button.
Expand Down
5 changes: 3 additions & 2 deletions src/wp-admin/includes/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ function options_general_add_js() {
homeURL = ( <?php echo wp_json_encode( get_home_url(), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?> || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' );

$( '#blogname' ).on( 'input', function() {
var title = $.trim( $( this ).val() ) || homeURL;
var title = $.trim( $( this ).val() ) || homeURL,
$siteIcon = $siteName.children();

// Truncate to 40 characters.
if ( 40 < title.length ) {
title = title.substring( 0, 40 ) + '\u2026';
}

$siteName.text( title );
$siteName.text( title ).prepend( $siteIcon );
$siteIconPreview.text( title );
});

Expand Down
Loading