diff --git src/wp-includes/post.php src/wp-includes/post.php
index ae688a3470..1d2eceb00b 100644
|
|
|
function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
|
| 3419 | 3419 | * @since 1.0.0 |
| 3420 | 3420 | * @since 4.2.0 Support was added for encoding emoji in the post title, content, and excerpt. |
| 3421 | 3421 | * @since 4.4.0 A 'meta_input' array can now be passed to `$postarr` to add post meta data. |
| | 3422 | * @since 5.3.0 Post excerpt with only whitespaces is no longer being saved. |
| 3422 | 3423 | * |
| 3423 | 3424 | * @see sanitize_post() |
| 3424 | 3425 | * @global wpdb $wpdb WordPress database abstraction object. |
| … |
… |
function wp_insert_post( $postarr, $wp_error = false ) {
|
| 3526 | 3527 | |
| 3527 | 3528 | $post_title = $postarr['post_title']; |
| 3528 | 3529 | $post_content = $postarr['post_content']; |
| | 3530 | |
| | 3531 | /** |
| | 3532 | * Prevent `post_excerpt` from saving only whitespaces. |
| | 3533 | * |
| | 3534 | * @link https://core.trac.wordpress.org/ticket/47849 |
| | 3535 | */ |
| | 3536 | if ( empty( trim( $postarr['post_excerpt'] ) ) ) { |
| | 3537 | $postarr['post_excerpt'] = ''; |
| | 3538 | } |
| | 3539 | |
| 3529 | 3540 | $post_excerpt = $postarr['post_excerpt']; |
| 3530 | 3541 | if ( isset( $postarr['post_name'] ) ) { |
| 3531 | 3542 | $post_name = $postarr['post_name']; |
diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
index 6ef0c8449f..0901dac519 100644
|
|
|
class Tests_Post extends WP_UnitTestCase {
|
| 1394 | 1394 | function filter_pre_wp_unique_post_slug( $default, $slug, $post_ID, $post_status, $post_type, $post_parent ) { |
| 1395 | 1395 | return 'override-slug-' . $post_type; |
| 1396 | 1396 | } |
| | 1397 | |
| | 1398 | /** |
| | 1399 | * @ticket 47849 |
| | 1400 | */ |
| | 1401 | function test_do_not_save_only_whitespaces_on_post_excerpt() { |
| | 1402 | $create_post_with_proper_excerpt = self::factory()->post->create( array( |
| | 1403 | 'post_title' => 'Test post 1', |
| | 1404 | 'post_content' => 'Test post content 1', |
| | 1405 | 'post_excerpt' => ' Test post excerpt 1 ' |
| | 1406 | ) ); |
| | 1407 | |
| | 1408 | $get_post_with_proper_excerpt = get_post( $create_post_with_proper_excerpt ); |
| | 1409 | |
| | 1410 | $this->assertSame( ' Test post excerpt 1 ', $get_post_with_proper_excerpt->post_excerpt ); |
| | 1411 | |
| | 1412 | $create_post_with_whitespaces_excerpt = self::factory()->post->create( array( |
| | 1413 | 'post_title' => 'Test post 1', |
| | 1414 | 'post_content' => 'Test post content 1', |
| | 1415 | 'post_excerpt' => ' ' |
| | 1416 | ) ); |
| | 1417 | |
| | 1418 | $get_post_with_whitespaces_excerpt = get_post( $create_post_with_whitespaces_excerpt ); |
| | 1419 | |
| | 1420 | $this->assertSame( '', $get_post_with_whitespaces_excerpt->post_excerpt ); |
| | 1421 | |
| | 1422 | } |
| | 1423 | |
| 1397 | 1424 | } |