Customize: Prevent absent site icon `link` from outputting an empty string as `href` in customizer; use `/favicon.ico` as fallback.

An empty string causes some browsers to use the current URL as the `href`. When using `history.replaceState()` Chrome will re-fetch the favicon with each call, meaning that `customize.php` gets hit with wasted requests which tax the server.

Fixes #38377.

Built from https://develop.svn.wordpress.org/trunk@38901


git-svn-id: http://core.svn.wordpress.org/trunk@38844 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2016-10-25 04:47:29 +00:00
parent a1777db166
commit afe90360b5
4 changed files with 31 additions and 12 deletions

View File

@ -3333,7 +3333,7 @@
* @param {object} attachment * @param {object} attachment
*/ */
setImageFromAttachment: function( attachment ) { setImageFromAttachment: function( attachment ) {
var sizes = [ 'site_icon-32', 'thumbnail', 'full' ], var sizes = [ 'site_icon-32', 'thumbnail', 'full' ], link,
icon; icon;
_.each( sizes, function( size ) { _.each( sizes, function( size ) {
@ -3347,8 +3347,13 @@
// Set the Customizer setting; the callback takes care of rendering. // Set the Customizer setting; the callback takes care of rendering.
this.setting( attachment.id ); this.setting( attachment.id );
if ( ! icon ) {
return;
}
// Update the icon in-browser. // Update the icon in-browser.
$( 'link[sizes="32x32"]' ).attr( 'href', icon.url ); link = $( 'link[rel="icon"][sizes="32x32"]' );
link.attr( 'href', icon.url );
}, },
/** /**
@ -3365,7 +3370,7 @@
this.params.attachment = {}; this.params.attachment = {};
this.setting( '' ); this.setting( '' );
this.renderContent(); // Not bound to setting change when emptying. this.renderContent(); // Not bound to setting change when emptying.
$( 'link[rel="icon"]' ).attr( 'href', '' ); $( 'link[rel="icon"][sizes="32x32"]' ).attr( 'href', '/favicon.ico' ); // Set to default.
} }
}); });

File diff suppressed because one or more lines are too long

View File

@ -2776,12 +2776,26 @@ function wp_site_icon() {
return; return;
} }
$meta_tags = array( $meta_tags = array();
sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( get_site_icon_url( 32 ) ) ), $icon_32 = get_site_icon_url( 32 );
sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( get_site_icon_url( 192 ) ) ), if ( empty( $icon_32 ) && is_customize_preview() ) {
sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( get_site_icon_url( 180 ) ) ), $icon_32 = '/favicon.ico'; // Serve default favicon URL in customizer so element can be updated for preview.
sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( get_site_icon_url( 270 ) ) ), }
); if ( $icon_32 ) {
$meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( $icon_32 ) );
}
$icon_192 = get_site_icon_url( 192 );
if ( $icon_192 ) {
$meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( $icon_192 ) );
}
$icon_180 = get_site_icon_url( 180 );
if ( $icon_180 ) {
$meta_tags[] = sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( $icon_180 ) );
}
$icon_270 = get_site_icon_url( 270 );
if ( $icon_270 ) {
$meta_tags[] = sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( $icon_270 ) );
}
/** /**
* Filters the site icon meta tags, so Plugins can add their own. * Filters the site icon meta tags, so Plugins can add their own.

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7-alpha-38900'; $wp_version = '4.7-alpha-38901';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.