From 555d7347f9c5d7a4d38c5440e6ea57193d44131f Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 29 Oct 2014 19:50:31 +0000 Subject: [PATCH] Support an empty string passed as a status in `WP_Comment_Query`. The changes in [30084] broke backward compatibility with interfaces that manually passed an empty string for the value of 'status', such as on wp-admin/edit-comments.php. Fixes #29612. git-svn-id: https://develop.svn.wordpress.org/trunk@30093 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment.php | 4 +--- tests/phpunit/tests/comment/query.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index fb501142e8..76715f5f1f 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -355,9 +355,6 @@ class WP_Comment_Query { $statuses = preg_split( '/[\s,]+/', $statuses ); } - // Remove empty statuses. - $statuses = array_filter( $statuses ); - // 'any' overrides other statuses. if ( ! in_array( 'any', $statuses ) ) { foreach ( $statuses as $status ) { @@ -371,6 +368,7 @@ class WP_Comment_Query { break; case 'all' : + case '' : $status_clauses[] = "( comment_approved = '0' OR comment_approved = '1' )"; break; diff --git a/tests/phpunit/tests/comment/query.php b/tests/phpunit/tests/comment/query.php index 07f4822ca6..84073b1ed9 100644 --- a/tests/phpunit/tests/comment/query.php +++ b/tests/phpunit/tests/comment/query.php @@ -15,6 +15,23 @@ class Tests_Comment_Query extends WP_UnitTestCase { $this->post_id = $this->factory->post->create(); } + /** + * @ticket 29612 + */ + public function test_status_empty_string() { + $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) ); + $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) ); + $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => 'spam' ) ); + + $q = new WP_Comment_Query(); + $found = $q->query( array( + 'status' => '', + 'fields' => 'ids', + ) ); + + $this->assertEqualSets( array( $c1, $c2 ), $found ); + } + /** * @ticket 21101 */