Formatting: Make the check for empty text in `wp_trim_excerpt()` more resilient.
This addresses a regression in [47808], which caused excerpts to be generated from post content if an empty string is passed, but not for other values considered empty, e.g. `null` or `false`. Props riaanlom, laxman-prajapati, SergeyBiryukov. Fixes #51042. git-svn-id: https://develop.svn.wordpress.org/trunk@48817 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
1911eae4a1
commit
76c599ced2
|
@ -3808,7 +3808,7 @@ function human_time_diff( $from, $to = 0 ) {
|
|||
function wp_trim_excerpt( $text = '', $post = null ) {
|
||||
$raw_excerpt = $text;
|
||||
|
||||
if ( '' === $text ) {
|
||||
if ( '' === trim( $text ) ) {
|
||||
$post = get_post( $post );
|
||||
$text = get_the_content( '', false, $post );
|
||||
|
||||
|
|
|
@ -66,4 +66,19 @@ class Tests_Formatting_WpTrimExcerpt extends WP_UnitTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 51042
|
||||
*/
|
||||
public function test_should_generate_excerpt_for_empty_values() {
|
||||
$post = self::factory()->post->create(
|
||||
array(
|
||||
'post_content' => 'Post content',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( 'Post content', wp_trim_excerpt( '', $post ) );
|
||||
$this->assertSame( 'Post content', wp_trim_excerpt( null, $post ) );
|
||||
$this->assertSame( 'Post content', wp_trim_excerpt( false, $post ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue