Make WordPress Core

Changeset 35572


Ignore:
Timestamp:
11/08/2015 02:03:34 AM (10 years ago)
Author:
jeremyfelt
Message:

Site Icon: Wrap site icon retrieval with switch_to_blog() as needed.

When the site icon for another site is requested, retrieving its ID via get_blog_option() is not enough. switch_to_blog() is used to set proper context when required.

Adds multsite tests for has_site_icon().

Props imath.
Fixes #34312.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r35571 r35572  
    759759 */
    760760function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
    761     if ( $blog_id && is_multisite() ) {
    762         $site_icon_id = get_blog_option( $blog_id, 'site_icon' );
    763     } else {
    764         $site_icon_id = get_option( 'site_icon' );
    765     }
     761    if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) {
     762        switch_to_blog( $blog_id );
     763    }
     764
     765    $site_icon_id = get_option( 'site_icon' );
    766766
    767767    if ( $site_icon_id ) {
     
    772772        }
    773773        $url = wp_get_attachment_image_url( $site_icon_id, $size_data );
     774    }
     775
     776    if ( is_multisite() && ms_is_switched() ) {
     777        restore_current_blog();
    774778    }
    775779
  • trunk/tests/phpunit/tests/general/template.php

    r35309 r35572  
    5656        $this->_remove_site_icon();
    5757        $this->assertFalse( has_site_icon() );
     58    }
     59
     60    /**
     61     * @group site_icon
     62     * @group multisite
     63     */
     64    function test_has_site_icon_returns_true_when_called_for_other_site_with_site_icon_set() {
     65        if ( ! is_multisite() ) {
     66            $this->markTestSkipped( 'This test requires multisite.' );
     67        }
     68
     69        $blog_id = $this->factory->blog->create();
     70        switch_to_blog( $blog_id );
     71        $this->_set_site_icon();
     72        restore_current_blog();
     73
     74        $this->assertTrue( has_site_icon( $blog_id ) );
     75    }
     76
     77    /**
     78     * @group site_icon
     79     * @group multisite
     80     */
     81    function test_has_site_icon_returns_false_when_called_for_other_site_without_site_icon_set() {
     82        if ( ! is_multisite() ) {
     83            $this->markTestSkipped( 'This test requires multisite.' );
     84        }
     85
     86        $blog_id = $this->factory->blog->create();
     87
     88        $this->assertFalse( has_site_icon( $blog_id ) );
    5889    }
    5990
Note: See TracChangeset for help on using the changeset viewer.