Allow user_id to be an array of IDs in WP_Comment_Query.
props mordauk. fixes #27064. git-svn-id: https://develop.svn.wordpress.org/trunk@27258 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
19d7d1dd09
commit
a407ae2363
@ -373,8 +373,13 @@ class WP_Comment_Query {
|
||||
}
|
||||
if ( '' !== $parent )
|
||||
$where .= $wpdb->prepare( ' AND comment_parent = %d', $parent );
|
||||
if ( '' !== $user_id )
|
||||
|
||||
if ( is_array( $user_id ) ) {
|
||||
$where .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $user_id ) ) . ')';
|
||||
} elseif ( '' !== $user_id ) {
|
||||
$where .= $wpdb->prepare( ' AND user_id = %d', $user_id );
|
||||
}
|
||||
|
||||
if ( '' !== $search )
|
||||
$where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) );
|
||||
|
||||
|
@ -156,4 +156,28 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
$this->assertEquals( 10, count( get_comments( array( 'status' => 'trash' ) ) ) );
|
||||
$this->assertEquals( 10, count( get_comments( array( 'status' => 'spam' ) ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 27064
|
||||
*/
|
||||
function test_get_comments_by_user() {
|
||||
$users = $this->factory->user->create_many( 2 );
|
||||
$this->factory->comment->create( array( 'user_id' => $users[0], 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
|
||||
$this->factory->comment->create( array( 'user_id' => $users[0], 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
|
||||
$this->factory->comment->create( array( 'user_id' => $users[1], 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
|
||||
|
||||
$comments = get_comments( array( 'user_id' => $users[0] ) );
|
||||
|
||||
$this->assertCount( 2, $comments );
|
||||
$this->assertEquals( $users[0], $comments[0]->user_id );
|
||||
$this->assertEquals( $users[0], $comments[1]->user_id );
|
||||
|
||||
$comments = get_comments( array( 'user_id' => $users ) );
|
||||
|
||||
$this->assertCount( 3, $comments );
|
||||
$this->assertEquals( $users[0], $comments[0]->user_id );
|
||||
$this->assertEquals( $users[0], $comments[1]->user_id );
|
||||
$this->assertEquals( $users[1], $comments[2]->user_id );
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user