Embeds: In switched state, restore previous state if no post ID is found.

Fixes #40673.

git-svn-id: https://develop.svn.wordpress.org/trunk@41634 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2017-09-28 16:28:46 +00:00
parent bbf0683deb
commit c8ff7f6592
2 changed files with 28 additions and 0 deletions

View File

@ -1106,6 +1106,10 @@ function wp_filter_pre_oembed_result( $result, $url, $args ) {
$post_id = apply_filters( 'oembed_request_post_id', $post_id, $url );
if ( ! $post_id ) {
if ( $switched_blog ) {
restore_current_blog();
}
return $result;
}

View File

@ -200,4 +200,28 @@ class Tests_WP_oEmbed extends WP_UnitTestCase {
$this->assertEquals( $this->pre_oembed_result_filtered, $actual );
$this->assertSame( $expected_stack, $actual_stack );
}
/**
* @ticket 40673
* @group multisite
* @group ms-required
*/
public function test_wp_filter_pre_oembed_result_multisite_restores_state_if_no_post_is_found() {
$current_blog_id = get_current_blog_id();
$user_id = self::factory()->user->create();
$blog_id = self::factory()->blog->create( array(
'user_id' => $user_id,
) );
$permalink = get_home_url( $blog_id, '/foo/' );
add_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
$actual = $this->oembed->get_html( $permalink );
remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
$this->assertNull( $this->pre_oembed_result_filtered );
$this->assertFalse( $actual );
$this->assertSame( $current_blog_id, get_current_blog_id() );
}
}