diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php index 4cc857306d..5ceed59165 100644 --- a/src/wp-includes/post-template.php +++ b/src/wp-includes/post-template.php @@ -372,7 +372,7 @@ function get_the_excerpt( $post = null ) { return ''; } - if ( post_password_required() ) { + if ( post_password_required( $post ) ) { return __( 'There is no excerpt because this is a protected post.' ); } diff --git a/tests/phpunit/tests/post/output.php b/tests/phpunit/tests/post/output.php index 63b9aad364..6026a2ba23 100644 --- a/tests/phpunit/tests/post/output.php +++ b/tests/phpunit/tests/post/output.php @@ -199,11 +199,14 @@ EOF; /** * @ticket 27246 + * @ticket 35486 */ public function test_the_excerpt_password_protected_post() { - $GLOBALS['post'] = self::factory()->post->create_and_get( array( 'post_excerpt' => 'Post excerpt', 'post_password' => '1234' ) ); + $post = self::factory()->post->create_and_get( array( 'post_excerpt' => 'Post excerpt', 'post_password' => '1234' ) ); + $this->assertSame( 'There is no excerpt because this is a protected post.', get_the_excerpt( $post ) ); + + $GLOBALS['post'] = $post; $this->assertSame( "
There is no excerpt because this is a protected post.
\n", get_echo( 'the_excerpt' ) ); - $this->assertSame( 'There is no excerpt because this is a protected post.', get_the_excerpt() ); } /**