From 16b45f08a94c2289f2ba8f2be0527a66b04137d9 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Mon, 7 Oct 2019 20:27:20 +0000 Subject: [PATCH] Pings/Trackbacks: Avoid adding multiple `_pingme` and `_encloseme` meta entries to a post when it gets updated prior to pings being done. Props rebasaurus, whyisjake Fixes #48014 git-svn-id: https://develop.svn.wordpress.org/trunk@46426 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 4 ++-- tests/phpunit/tests/post.php | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 51e45f2d9277..eb98238d5e18 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -6800,9 +6800,9 @@ function _publish_post_hook( $post_id ) { } if ( get_option( 'default_pingback_flag' ) ) { - add_post_meta( $post_id, '_pingme', '1' ); + add_post_meta( $post_id, '_pingme', '1', true ); } - add_post_meta( $post_id, '_encloseme', '1' ); + add_post_meta( $post_id, '_encloseme', '1', true ); $to_ping = get_to_ping( $post_id ); if ( ! empty( $to_ping ) ) { diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 39a8bae14a61..17f69fe2e105 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -1430,4 +1430,27 @@ public function test_insert_post_should_respect_date_floating_post_status_arg_no $post = get_post( $post_id ); self::assertEquals( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date_gmt ), 'The dates should be equal', 2 ); } + + /** + * @ticket 48014 + */ + public function test_updated_post_should_not_duplicate_enclosure_meta_fields() { + $post_id = self::factory()->post->create(); + + $encloseme_before = get_post_meta( $post_id, '_encloseme' ); + $pingme_before = get_post_meta( $post_id, '_pingme' ); + + $updated = wp_update_post( get_post( $post_id ), true ); + + $encloseme_after = get_post_meta( $post_id, '_encloseme' ); + $pingme_after = get_post_meta( $post_id, '_pingme' ); + + $this->assertSame( $post_id, $updated ); + + $this->assertCount( 1, $encloseme_before ); + $this->assertCount( 1, $encloseme_after ); + + $this->assertCount( 1, $pingme_before ); + $this->assertCount( 1, $pingme_after ); + } }