diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index e846b1f31b..b9ffed6da3 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -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' ) ); diff --git a/tests/phpunit/tests/comment/query.php b/tests/phpunit/tests/comment/query.php index 5d0b09cebe..2dc3623608 100644 --- a/tests/phpunit/tests/comment/query.php +++ b/tests/phpunit/tests/comment/query.php @@ -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 ); + + } }