From 6479ea9af81cdc225149dc1b4e6e614b1d4cbd4b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 22 Feb 2021 13:21:26 +0000 Subject: [PATCH] Embeds: Allow posts with a public custom post status to be embedded. Previously, only posts with the `publish` status could be embedded. Props goaroundagain, peterwilsoncc, poena. Fixes #47574. git-svn-id: https://develop.svn.wordpress.org/trunk@50401 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/embed.php | 5 +- .../phpunit/tests/oembed/getResponseData.php | 46 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php index 7c5ac83f24..8a718ab566 100644 --- a/src/wp-includes/embed.php +++ b/src/wp-includes/embed.php @@ -509,7 +509,8 @@ JS; * * @param WP_Post|int $post Post object or ID. * @param int $width The requested width. - * @return array|false Response data on success, false if post doesn't exist. + * @return array|false Response data on success, false if post doesn't exist + * or is not publicly viewable. */ function get_oembed_response_data( $post, $width ) { $post = get_post( $post ); @@ -519,7 +520,7 @@ function get_oembed_response_data( $post, $width ) { return false; } - if ( 'publish' !== get_post_status( $post ) ) { + if ( ! is_post_publicly_viewable( $post ) ) { return false; } diff --git a/tests/phpunit/tests/oembed/getResponseData.php b/tests/phpunit/tests/oembed/getResponseData.php index 9beaf56e7e..8315d652a4 100644 --- a/tests/phpunit/tests/oembed/getResponseData.php +++ b/tests/phpunit/tests/oembed/getResponseData.php @@ -2,6 +2,7 @@ /** * @group oembed + * @covers ::get_oembed_response_data */ class Tests_oEmbed_Response_Data extends WP_UnitTestCase { function test_get_oembed_response_data_non_existent_post() { @@ -128,6 +129,51 @@ class Tests_oEmbed_Response_Data extends WP_UnitTestCase { $this->assertFalse( get_oembed_response_data( $post, 100 ) ); } + /** + * @ticket 47574 + */ + function test_get_oembed_response_data_with_public_true_custom_post_status() { + // Custom status with 'public' => true. + register_post_status( 'public', array( 'public' => true ) ); + + $post = self::factory()->post->create_and_get( + array( + 'post_status' => 'public', + ) + ); + + $this->assertNotFalse( get_oembed_response_data( $post, 100 ) ); + } + + /** + * @ticket 47574 + */ + function test_get_oembed_response_data_with_public_false_custom_post_status() { + // Custom status with 'public' => false. + register_post_status( 'private_foo', array( 'public' => false ) ); + + $post = self::factory()->post->create_and_get( + array( + 'post_status' => 'private_foo', + ) + ); + + $this->assertFalse( get_oembed_response_data( $post, 100 ) ); + } + + /** + * @ticket 47574 + */ + function test_get_oembed_response_data_with_unregistered_custom_post_status() { + $post = self::factory()->post->create_and_get( + array( + 'post_status' => 'unknown_foo', + ) + ); + + $this->assertFalse( get_oembed_response_data( $post, 100 ) ); + } + function test_get_oembed_response_data_maxwidth_too_high() { $post = self::factory()->post->create_and_get();