Return an empty array from get_approved_comments() when $post_id is empty.

This behavior was broken when moving the internals to `WP_Comment_Query` in
[30098]. As a result, `get_approved_comments( 0 )` was fetching *all* approved
comments, causing performance issues.

Props dd32.
Fixes #30412.

git-svn-id: https://develop.svn.wordpress.org/trunk@30402 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2014-11-20 01:51:38 +00:00
parent 78f496f378
commit 10b611b0c3
3 changed files with 29 additions and 1 deletions

View File

@@ -30,6 +30,18 @@ class Tests_Comment_Query extends WP_UnitTestCase {
$this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
}
public function test_query_post_id_0() {
$c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
$q = new WP_Comment_Query();
$found = $q->query( array(
'post_id' => 0,
'fields' => 'ids',
) );
$this->assertEqualSets( array( $c1 ), $found );
}
/**
* @ticket 12668
*/