Make WordPress Core

Ticket #47574: 47574.3.diff

File 47574.3.diff, 2.1 KB (added by goaroundagain, 6 years ago)

If the post status is not registered, treat it as a nonpublic

  • src/wp-includes/embed.php

    diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php
    index 76d937cd6c..c0ef9ad10e 100644
    a b function get_oembed_response_data( $post, $width ) { 
    506506                return false;
    507507        }
    508508
    509         if ( 'publish' !== get_post_status( $post ) ) {
     509        $post_status = get_post_status_object( get_post_status( $post ) );
     510
     511        if ( ! $post_status || ! $post_status->public ) {
    510512                return false;
    511513        }
    512514
  • tests/phpunit/tests/oembed/getResponseData.php

    diff --git a/tests/phpunit/tests/oembed/getResponseData.php b/tests/phpunit/tests/oembed/getResponseData.php
    index de96211f87..69596d19e2 100644
    a b class Tests_oEmbed_Response_Data extends WP_UnitTestCase { 
    128128                $this->assertFalse( get_oembed_response_data( $post, 100 ) );
    129129        }
    130130
     131        /**
     132         * @ticket 47574
     133         */
     134        function test_getoembed_response_data_with_public_true_custom_post_status() {
     135                // Custom status with public=true.
     136                register_post_status( 'public', array( 'public' => true ) );
     137
     138                $post = self::factory()->post->create_and_get(
     139                        array(
     140                                'post_status' => 'public',
     141                        )
     142                );
     143
     144                $this->assertNotFalse( get_oembed_response_data( $post, 100 ) );
     145
     146                _unregister_post_status( 'public' );
     147        }
     148
     149        /**
     150         * @ticket 47574
     151         */
     152        function test_getoembed_response_data_with_public_false_custom_post_status() {
     153                // Custom status with public=false.
     154                register_post_status( 'privatfoo', array( 'public' => false ) );
     155
     156                $post = self::factory()->post->create_and_get(
     157                        array(
     158                                'post_status' => 'privatfoo',
     159                        )
     160                );
     161
     162                $this->assertFalse( get_oembed_response_data( $post, 100 ) );
     163
     164                _unregister_post_status( 'privatfoo' );
     165        }
     166
     167        /**
     168         * @ticket 47574
     169         */
     170         function test_getoembed_response_data_with_unregistered_custom_post_status() {
     171
     172                $post = self::factory()->post->create_and_get(
     173                        array(
     174                                'post_status' => 'unkownfoo',
     175                        )
     176                );
     177
     178                $this->assertFalse( get_oembed_response_data( $post, 100 ) );
     179
     180        }
     181
    131182        function test_get_oembed_response_data_maxwidth_too_high() {
    132183                $post = self::factory()->post->create_and_get();
    133184