Ticket #38377: 38377.1.diff
| File 38377.1.diff, 5.7 KB (added by , 9 years ago) |
|---|
-
src/wp-admin/js/customize-controls.js
diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js index 18862ae..ec3d871 100644
3329 3329 * @param {object} attachment 3330 3330 */ 3331 3331 setImageFromAttachment: function( attachment ) { 3332 var sizes = [ 'site_icon-32', 'thumbnail', 'full' ], 3332 var sizes = [ 'site_icon-32', 'thumbnail', 'full' ], link, 3333 3333 icon; 3334 3334 3335 3335 _.each( sizes, function( size ) { … … 3343 3343 // Set the Customizer setting; the callback takes care of rendering. 3344 3344 this.setting( attachment.id ); 3345 3345 3346 if ( ! icon ) { 3347 return; 3348 } 3349 3346 3350 // Update the icon in-browser. 3347 $( 'link[sizes="32x32"]' ).attr( 'href', icon.url ); 3351 link = $( 'link[rel="icon"][sizes="32x32"]' ); 3352 link.attr( 'href', icon.url ); 3348 3353 }, 3349 3354 3350 3355 /** … … 3361 3366 this.params.attachment = {}; 3362 3367 this.setting( '' ); 3363 3368 this.renderContent(); // Not bound to setting change when emptying. 3364 $( 'link[rel="icon"] ' ).attr( 'href', '' );3369 $( 'link[rel="icon"][sizes="32x32"]' ).attr( 'href', '/favicon.ico' ); // Set to default. 3365 3370 } 3366 3371 }); 3367 3372 -
src/wp-includes/general-template.php
diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php index 5174936..8e58b5c 100644
function wp_site_icon() { 2776 2776 return; 2777 2777 } 2778 2778 2779 $meta_tags = array( 2780 sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( get_site_icon_url( 32 ) ) ), 2781 sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( get_site_icon_url( 192 ) ) ), 2782 sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( get_site_icon_url( 180 ) ) ), 2783 sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( get_site_icon_url( 270 ) ) ), 2784 ); 2779 $meta_tags = array(); 2780 $icon_32 = get_site_icon_url( 32 ); 2781 if ( empty( $icon_32 ) && is_customize_preview() ) { 2782 $icon_32 = '/favicon.ico'; // Serve default favicon URL in customizer so element can be updated for preview. 2783 } 2784 if ( $icon_32 ) { 2785 $meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( $icon_32 ) ); 2786 } 2787 $icon_192 = get_site_icon_url( 192 ); 2788 if ( $icon_192 ) { 2789 $meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( $icon_192 ) ); 2790 } 2791 $icon_180 = get_site_icon_url( 180 ); 2792 if ( $icon_180 ) { 2793 $meta_tags[] = sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( $icon_180 ) ); 2794 } 2795 $icon_270 = get_site_icon_url( 270 ); 2796 if ( $icon_270 ) { 2797 $meta_tags[] = sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( $icon_270 ) ); 2798 } 2785 2799 2786 2800 /** 2787 2801 * Filters the site icon meta tags, so Plugins can add their own. -
tests/phpunit/tests/general/template.php
diff --git tests/phpunit/tests/general/template.php tests/phpunit/tests/general/template.php index d650d1d..16007cf 100644
class Tests_General_Template extends WP_UnitTestCase { 23 23 } 24 24 25 25 function tearDown() { 26 global $wp_customize; 26 27 $this->_remove_custom_logo(); 28 $this->_remove_site_icon(); 29 $wp_customize = null; 27 30 28 31 parent::tearDown(); 29 32 } … … class Tests_General_Template extends WP_UnitTestCase { 51 54 $this->_set_site_icon(); 52 55 $this->expectOutputString( $this->site_icon_url ); 53 56 site_icon_url(); 54 $this->_remove_site_icon();55 57 } 56 58 57 59 /** … … class Tests_General_Template extends WP_UnitTestCase { 117 119 118 120 $this->expectOutputString( $output ); 119 121 wp_site_icon(); 120 121 $this->_remove_site_icon();122 122 } 123 123 124 124 /** … … class Tests_General_Template extends WP_UnitTestCase { 143 143 add_filter( 'site_icon_meta_tags', array( $this, '_custom_site_icon_meta_tag' ) ); 144 144 wp_site_icon(); 145 145 remove_filter( 'site_icon_meta_tags', array( $this, '_custom_site_icon_meta_tag' ) ); 146 } 146 147 147 $this->_remove_site_icon(); 148 /** 149 * @group site_icon 150 * @ticket 38377 151 */ 152 function test_customize_preview_wp_site_icon_empty() { 153 global $wp_customize; 154 wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); 155 156 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 157 $wp_customize = new WP_Customize_Manager(); 158 $wp_customize->register_controls(); 159 $wp_customize->start_previewing_theme(); 160 161 $this->expectOutputString( '<link rel="icon" href="/favicon.ico" sizes="32x32" />' . "\n" ); 162 wp_site_icon(); 163 } 164 165 /** 166 * @group site_icon 167 * @ticket 38377 168 */ 169 function test_customize_preview_wp_site_icon_dirty() { 170 global $wp_customize; 171 wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); 172 173 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 174 $wp_customize = new WP_Customize_Manager(); 175 $wp_customize->register_controls(); 176 $wp_customize->start_previewing_theme(); 177 178 $attachment_id = $this->_insert_attachment(); 179 $wp_customize->set_post_value( 'site_icon', $attachment_id ); 180 $wp_customize->get_setting( 'site_icon' )->preview(); 181 $output = array( 182 sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( wp_get_attachment_image_url( $attachment_id, 32 ) ) ), 183 sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( wp_get_attachment_image_url( $attachment_id, 192 ) ) ), 184 sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( wp_get_attachment_image_url( $attachment_id, 180 ) ) ), 185 sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( wp_get_attachment_image_url( $attachment_id, 270 ) ) ), 186 '', 187 ); 188 $output = implode( "\n", $output ); 189 $this->expectOutputString( $output ); 190 wp_site_icon(); 148 191 } 149 192 150 193 /**