Make WordPress Core

Changeset 50401


Ignore:
Timestamp:
02/22/2021 01:21:26 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

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

    r50371 r50401  
    510510 * @param WP_Post|int $post  Post object or ID.
    511511 * @param int         $width The requested width.
    512  * @return array|false Response data on success, false if post doesn't exist.
     512 * @return array|false Response data on success, false if post doesn't exist
     513 *                     or is not publicly viewable.
    513514 */
    514515function get_oembed_response_data( $post, $width ) {
     
    520521    }
    521522
    522     if ( 'publish' !== get_post_status( $post ) ) {
     523    if ( ! is_post_publicly_viewable( $post ) ) {
    523524        return false;
    524525    }
  • trunk/tests/phpunit/tests/oembed/getResponseData.php

    r48939 r50401  
    33/**
    44 * @group oembed
     5 * @covers ::get_oembed_response_data
    56 */
    67class Tests_oEmbed_Response_Data extends WP_UnitTestCase {
     
    129130    }
    130131
     132    /**
     133     * @ticket 47574
     134     */
     135    function test_get_oembed_response_data_with_public_true_custom_post_status() {
     136        // Custom status with 'public' => true.
     137        register_post_status( 'public', array( 'public' => true ) );
     138
     139        $post = self::factory()->post->create_and_get(
     140            array(
     141                'post_status' => 'public',
     142            )
     143        );
     144
     145        $this->assertNotFalse( get_oembed_response_data( $post, 100 ) );
     146    }
     147
     148    /**
     149     * @ticket 47574
     150     */
     151    function test_get_oembed_response_data_with_public_false_custom_post_status() {
     152        // Custom status with 'public' => false.
     153        register_post_status( 'private_foo', array( 'public' => false ) );
     154
     155        $post = self::factory()->post->create_and_get(
     156            array(
     157                'post_status' => 'private_foo',
     158            )
     159        );
     160
     161        $this->assertFalse( get_oembed_response_data( $post, 100 ) );
     162    }
     163
     164    /**
     165     * @ticket 47574
     166     */
     167    function test_get_oembed_response_data_with_unregistered_custom_post_status() {
     168        $post = self::factory()->post->create_and_get(
     169            array(
     170                'post_status' => 'unknown_foo',
     171            )
     172        );
     173
     174        $this->assertFalse( get_oembed_response_data( $post, 100 ) );
     175    }
     176
    131177    function test_get_oembed_response_data_maxwidth_too_high() {
    132178        $post = self::factory()->post->create_and_get();
Note: See TracChangeset for help on using the changeset viewer.