WordPress.org

Make WordPress Core

Changeset 36224


Ignore:
Timestamp:
01/08/2016 09:51:50 PM (6 years ago)
Author:
boonebgorges
Message:

Introduce 'author_url' param to WP_Comment_Query.

Props swissspidy.
Fixes #35377.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-comment-query.php

    r35757 r36224  
    140140     * @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache`, `$no_found_rows`,
    141141     *              `$hierarchical`, and `$update_comment_post_cache` were added.
     142     * @since 4.5.0 `$author_url` was added.
    142143     * @access public
    143144     *
     
    146147     *
    147148     *     @type string       $author_email              Comment author email address. Default empty.
     149     *     @type string       $author_url                Comment author URL. Default empty.
    148150     *     @type array        $author__in                Array of author IDs to include comments for. Default empty.
    149151     *     @type array        $author__not_in            Array of author IDs to exclude comments for. Default empty.
     
    246248        $this->query_var_defaults = array(
    247249            'author_email' => '',
     250            'author_url' => '',
    248251            'author__in' => '',
    249252            'author__not_in' => '',
     
    671674        }
    672675
     676        if ( '' !== $this->query_vars['author_url'] ) {
     677            $this->sql_clauses['where']['author_url'] = $wpdb->prepare( 'comment_author_url = %s', $this->query_vars['author_url'] );
     678        }
     679
    673680        if ( '' !== $this->query_vars['karma'] ) {
    674681            $this->sql_clauses['where']['karma'] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] );
  • trunk/tests/phpunit/tests/comment/query.php

    r35512 r36224  
    806806
    807807    /**
     808     * @ticket 35377
     809     */
     810    public function test_get_comments_by_author_url() {
     811        $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' ) );
     812        $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' ) );
     813        $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' ) );
     814
     815        $comments = get_comments( array(
     816            'author_url' => 'http://foo.bar',
     817        ) );
     818
     819        $this->assertCount( 2, $comments );
     820        $this->assertSame( $c1, (int) $comments[0]->comment_ID );
     821        $this->assertSame( $c2, (int) $comments[1]->comment_ID );
     822    }
     823
     824    /**
    808825     * @ticket 28434
    809826     */
Note: See TracChangeset for help on using the changeset viewer.