Make WordPress Core

Ticket #38253: 38253.diff

File 38253.diff, 3.7 KB (added by flixos90, 8 years ago)
  • src/wp-includes/general-template.php

     
    783783 * @return string Site Icon URL.
    784784 */
    785785function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
    786         if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) {
     786        $switched_blog = false;
     787
     788        if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) {
    787789                switch_to_blog( $blog_id );
     790                $switched_blog = true;
    788791        }
    789792
    790793        $site_icon_id = get_option( 'site_icon' );
     
    798801                $url = wp_get_attachment_image_url( $site_icon_id, $size_data );
    799802        }
    800803
    801         if ( is_multisite() && ms_is_switched() ) {
     804        if ( $switched_blog ) {
    802805                restore_current_blog();
    803806        }
    804807
     
    848851 * @return bool Whether the site has a custom logo or not.
    849852 */
    850853function has_custom_logo( $blog_id = 0 ) {
    851         if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) {
     854        $switched_blog = false;
     855
     856        if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) {
    852857                switch_to_blog( $blog_id );
     858                $switched_blog = true;
    853859        }
    854860
    855861        $custom_logo_id = get_theme_mod( 'custom_logo' );
    856862
    857         if ( is_multisite() && ms_is_switched() ) {
     863        if ( $switched_blog ) {
    858864                restore_current_blog();
    859865        }
    860866
     
    871877 */
    872878function get_custom_logo( $blog_id = 0 ) {
    873879        $html = '';
     880        $switched_blog = false;
    874881
    875         if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) {
     882        if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) {
    876883                switch_to_blog( $blog_id );
     884                $switched_blog = true;
    877885        }
    878886
    879887        $custom_logo_id = get_theme_mod( 'custom_logo' );
     
    896904                );
    897905        }
    898906
    899         if ( is_multisite() && ms_is_switched() ) {
     907        if ( $switched_blog ) {
    900908                restore_current_blog();
    901909        }
    902910
  • tests/phpunit/tests/general/template.php

     
    488488                $actual = get_the_modified_time( $d, $post_id );
    489489                $this->assertEquals( $expected, $actual );
    490490        }
     491
     492        /**
     493         * @ticket 38253
     494         */
     495        function test_get_site_icon_url_preserves_switched_state() {
     496                if ( ! is_multisite() ) {
     497                        $this->markTestSkipped( 'This test requires multisite.' );
     498                }
     499
     500                $blog_id = $this->factory->blog->create();
     501                switch_to_blog( $blog_id );
     502
     503                $expected = $GLOBALS['_wp_switched_stack'];
     504
     505                get_site_icon_url( 512, '', $blog_id );
     506
     507                $result = $GLOBALS['_wp_switched_stack'];
     508
     509                restore_current_blog();
     510
     511                $this->assertSame( $expected, $result );
     512        }
     513
     514        /**
     515         * @ticket 38253
     516         */
     517        function test_has_custom_logo_preserves_switched_state() {
     518                if ( ! is_multisite() ) {
     519                        $this->markTestSkipped( 'This test requires multisite.' );
     520                }
     521
     522                $blog_id = $this->factory->blog->create();
     523                switch_to_blog( $blog_id );
     524
     525                $expected = $GLOBALS['_wp_switched_stack'];
     526
     527                has_custom_logo( $blog_id );
     528
     529                $result = $GLOBALS['_wp_switched_stack'];
     530
     531                restore_current_blog();
     532
     533                $this->assertSame( $expected, $result );
     534        }
     535
     536        /**
     537         * @ticket 38253
     538         */
     539        function test_get_custom_logo_preserves_switched_state() {
     540                if ( ! is_multisite() ) {
     541                        $this->markTestSkipped( 'This test requires multisite.' );
     542                }
     543
     544                $blog_id = $this->factory->blog->create();
     545                switch_to_blog( $blog_id );
     546
     547                $expected = $GLOBALS['_wp_switched_stack'];
     548
     549                get_custom_logo( $blog_id );
     550
     551                $result = $GLOBALS['_wp_switched_stack'];
     552
     553                restore_current_blog();
     554
     555                $this->assertSame( $expected, $result );
     556        }
    491557}