From c8ff7f6592b325a89485a3bc7031bf4fb38efe69 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Thu, 28 Sep 2017 16:28:46 +0000 Subject: [PATCH] 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 --- src/wp-includes/embed.php | 4 ++++ tests/phpunit/tests/oembed/wpOembed.php | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php index 6040004bac..176988057b 100644 --- a/src/wp-includes/embed.php +++ b/src/wp-includes/embed.php @@ -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; } diff --git a/tests/phpunit/tests/oembed/wpOembed.php b/tests/phpunit/tests/oembed/wpOembed.php index d8d346de11..1f5043c3f2 100644 --- a/tests/phpunit/tests/oembed/wpOembed.php +++ b/tests/phpunit/tests/oembed/wpOembed.php @@ -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() ); + } }