diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 51ce4c0cf7..c169bd7541 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -687,7 +687,7 @@ function post_exists($title, $content = '', $date = '') { } if ( !empty ( $content ) ) { - $query .= 'AND post_content = %s'; + $query .= ' AND post_content = %s'; $args[] = $post_content; } diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 686cff6242..c9e92f06aa 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -481,6 +481,20 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $this->assertSame( $p, post_exists( $title, $content ) ); } + /** + * @ticket 35246 + */ + public function test_post_exists_should_match_content_with_no_title() { + $title = ''; + $content = 'Foo Bar Baz'; + $p = self::factory()->post->create( array( + 'post_title' => $title, + 'post_content' => $content, + ) ); + + $this->assertSame( $p, post_exists( $title, $content ) ); + } + public function test_post_exists_should_not_match_when_nonempty_content_doesnt_match() { $title = 'Foo Bar'; $content = 'Foo Bar Baz';