Make WordPress Core

Ticket #47824: 47824.2.diff

File 47824.2.diff, 1.0 KB (added by SergeyBiryukov, 4 years ago)
  • src/wp-includes/post-template.php

     
    276276                return '';
    277277        }
    278278
    279         if ( null === $post ) {
     279        if ( null === $post && in_the_loop() ) {
    280280                $elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
    281281        } else {
    282282                $elements = generate_postdata( $_post );
  • tests/phpunit/tests/post/getTheContent.php

     
    7575
    7676                $this->assertSame( 'Bang', $found );
    7777        }
     78
     79        /**
     80         * @ticket 47824
     81         */
     82        public function test_should_fall_back_to_post_global_outside_of_the_loop() {
     83                $GLOBALS['post'] = self::factory()->post->create( array( 'post_content' => 'Foo' ) );
     84
     85                $this->assertSame( 'Foo', get_the_content() );
     86        }
    7887}