From 3541f7b90b0a57a10458628e5dfb5a07ab49775a Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sat, 16 Jan 2016 10:13:27 +0000 Subject: [PATCH] Posts: Correctly pass `$post` to `post_password_required()` in `get_the_excerpt()`. Corrects the relevant test. Props sebastian.pisula for initial patch. Fixes #35486. git-svn-id: https://develop.svn.wordpress.org/trunk@36329 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post-template.php | 2 +- tests/phpunit/tests/post/output.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) 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() ); } /**