WordPress.org

Make WordPress Core

Changeset 41606


Ignore:
Timestamp:
09/27/2017 08:35:16 AM (10 months ago)
Author:
swissspidy
Message:

Embeds: Maintain switched state when embedding a post on Multisite.

Props bor0.
Fixes #40673.

Location:
trunk
Files:
2 edited

Legend:

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

    r41600 r41606  
    10721072 */
    10731073function wp_filter_pre_oembed_result( $result, $url, $args ) {
     1074    $switched_blog = false;
     1075
    10741076    if ( is_multisite() ) {
    10751077        $url_parts = wp_parse_args( wp_parse_url( $url ), array(
     
    10951097        if ( $site && (int) $site->blog_id !== get_current_blog_id() ) {
    10961098            switch_to_blog( $site->blog_id );
     1099            $switched_blog = true;
    10971100        }
    10981101    }
     
    11121115    $data = _wp_oembed_get_object()->data2html( (object) $data, $url );
    11131116
    1114     if ( is_multisite() && ms_is_switched() ) {
     1117    if ( $switched_blog ) {
    11151118        restore_current_blog();
    11161119    }
  • trunk/tests/phpunit/tests/oembed/wpOembed.php

    r41600 r41606  
    172172        $this->assertEquals( $this->pre_oembed_result_filtered, $actual );
    173173    }
     174
     175    /**
     176     * @ticket 40673
     177     * @group multisite
     178     * @group ms-required
     179     */
     180    public function test_wp_filter_pre_oembed_result_multisite_preserves_switched_state() {
     181        $user_id = self::factory()->user->create();
     182
     183        $blog_id = self::factory()->blog->create( array( 'user_id' => $user_id ) );
     184        switch_to_blog( $blog_id );
     185
     186        $expected_stack = $GLOBALS['_wp_switched_stack'];
     187
     188        $post_id   = self::factory()->post->create();
     189        $permalink = get_permalink( $post_id );
     190
     191        add_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
     192        $actual = $this->oembed->get_html( $permalink );
     193        remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
     194
     195        $actual_stack = $GLOBALS['_wp_switched_stack'];
     196
     197        restore_current_blog();
     198
     199        $this->assertNotNull( $this->pre_oembed_result_filtered );
     200        $this->assertEquals( $this->pre_oembed_result_filtered, $actual );
     201        $this->assertSame( $expected_stack, $actual_stack );
     202    }
    174203}
Note: See TracChangeset for help on using the changeset viewer.