diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php index e30094ddfc..ac122a62c9 100644 --- a/src/wp-includes/class-wp-comment-query.php +++ b/src/wp-includes/class-wp-comment-query.php @@ -139,12 +139,14 @@ class WP_Comment_Query { * @since 4.4.0 `$parent__in` and `$parent__not_in` were added. * @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache`, `$no_found_rows`, * `$hierarchical`, and `$update_comment_post_cache` were added. + * @since 4.5.0 `$author_url` was added. * @access public * * @param string|array $query { * Optional. Array or query string of comment query parameters. Default empty. * * @type string $author_email Comment author email address. Default empty. + * @type string $author_url Comment author URL. Default empty. * @type array $author__in Array of author IDs to include comments for. Default empty. * @type array $author__not_in Array of author IDs to exclude comments for. Default empty. * @type array $comment__in Array of comment IDs to include. Default empty. @@ -245,6 +247,7 @@ class WP_Comment_Query { public function __construct( $query = '' ) { $this->query_var_defaults = array( 'author_email' => '', + 'author_url' => '', 'author__in' => '', 'author__not_in' => '', 'include_unapproved' => '', @@ -670,6 +673,10 @@ class WP_Comment_Query { $this->sql_clauses['where']['author_email'] = $wpdb->prepare( 'comment_author_email = %s', $this->query_vars['author_email'] ); } + if ( '' !== $this->query_vars['author_url'] ) { + $this->sql_clauses['where']['author_url'] = $wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] ); + } + if ( '' !== $this->query_vars['karma'] ) { $this->sql_clauses['where']['karma'] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] ); } diff --git a/tests/phpunit/tests/comment/query.php b/tests/phpunit/tests/comment/query.php index 5d250eac90..c00ceee6a3 100644 --- a/tests/phpunit/tests/comment/query.php +++ b/tests/phpunit/tests/comment/query.php @@ -804,6 +804,23 @@ class Tests_Comment_Query extends WP_UnitTestCase { } + /** + * @ticket 35377 + */ + public function test_get_comments_by_author_url() { + $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_author' => 'bar', 'comment_author_email' => 'bar@example.com', 'comment_author_url' => 'http://foo.bar' ) ); + $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_author' => 'bar', 'comment_author_email' => 'bar@example.com', 'comment_author_url' => 'http://foo.bar' ) ); + $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_author' => 'bar', 'comment_author_email' => 'bar@example.com', 'comment_author_url' => 'http://foo.bar/baz' ) ); + + $comments = get_comments( array( + 'author_url' => 'http://foo.bar', + ) ); + + $this->assertCount( 2, $comments ); + $this->assertSame( $c1, (int) $comments[0]->comment_ID ); + $this->assertSame( $c2, (int) $comments[1]->comment_ID ); + } + /** * @ticket 28434 */