Make WordPress Core

Ticket #29189: 29189.patch

File 29189.patch, 4.8 KB (added by boonebgorges, 10 years ago)
  • src/wp-includes/comment.php

    diff --git src/wp-includes/comment.php src/wp-includes/comment.php
    index a4cc7e2..2053293 100644
    class WP_Comment_Query { 
    249249                        'author_email' => '',
    250250                        'fields' => '',
    251251                        'ID' => '',
     252                        'comment_id__in' => '',
     253                        'comment_id__not_in' => '',
    252254                        'karma' => '',
    253255                        'number' => '',
    254256                        'offset' => '',
    class WP_Comment_Query { 
    257259                        'parent' => '',
    258260                        'post_ID' => '',
    259261                        'post_id' => 0,
     262                        'post_id__in' => '',
     263                        'post_id__not_in' => '',
    260264                        'post_author' => '',
    261265                        'post_name' => '',
    262266                        'post_parent' => '',
    class WP_Comment_Query { 
    389393                        $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
    390394                }
    391395
     396                if ( ! empty( $this->query_vars['comment_id__in'] ) ) {
     397                        $where .= ' AND comment_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['comment_id__in'] ) ) . ' )';
     398                }
     399
     400                if ( ! empty( $this->query_vars['comment_id__not_in'] ) ) {
     401                        $where .= ' AND comment_ID NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['comment_id__not_in'] ) ) . ' )';
     402                }
     403
     404                if ( ! empty( $this->query_vars['post_id__in'] ) ) {
     405                        $where .= ' AND comment_post_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_id__in'] ) ) . ' )';
     406                }
     407
     408                if ( ! empty( $this->query_vars['post_id__not_in'] ) ) {
     409                        $where .= ' AND comment_post_ID NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_id__not_in'] ) ) . ' )';
     410                }
     411
    392412                if ( '' !== $this->query_vars['author_email'] ) {
    393413                        $where .= $wpdb->prepare( ' AND comment_author_email = %s', $this->query_vars['author_email'] );
    394414                }
  • tests/phpunit/tests/comment/query.php

    diff --git tests/phpunit/tests/comment/query.php tests/phpunit/tests/comment/query.php
    index 51140a7..f413fc2 100644
    class Tests_Comment_Query extends WP_UnitTestCase { 
    198198                $this->assertCount( 3, $comment_ids );
    199199                $this->assertEqualSets( array( $comment_1, $comment_2, $comment_3 ), $comment_ids );
    200200        }
     201
     202        /**
     203         * @ticket
     204         */
     205        function test_fields_comment_id__in() {
     206                $comment_1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7, 'comment_approved' => '1' ) );
     207                $comment_2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 1, 'comment_approved' => '1' ) );
     208                $comment_3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 1, 'comment_approved' => '1' ) );
     209
     210                $comment_ids = get_comments( array(
     211                        'fields' => 'ids',
     212                        'comment_id__in' => array( $comment_1, $comment_3 ),
     213                ) );
     214
     215                $this->assertEqualSets( array( $comment_1, $comment_3 ), $comment_ids );
     216        }
     217
     218        /**
     219         * @ticket
     220         */
     221        function test_fields_comment_id__not_in() {
     222                $comment_1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7, 'comment_approved' => '1' ) );
     223                $comment_2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 1, 'comment_approved' => '1' ) );
     224                $comment_3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 1, 'comment_approved' => '1' ) );
     225
     226                $comment_ids = get_comments( array(
     227                        'fields' => 'ids',
     228                        'comment_id__not_in' => array( $comment_2, $comment_3 ),
     229                ) );
     230
     231                $this->assertEqualSets( array( $comment_1 ), $comment_ids );
     232        }
     233
     234        /**
     235         * @ticket
     236         */
     237        function test_fields_post_id__in() {
     238                $p1 = $this->factory->post->create();
     239                $p2 = $this->factory->post->create();
     240                $p3 = $this->factory->post->create();
     241
     242                $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 7, 'comment_approved' => '1' ) );
     243                $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 1, 'comment_approved' => '1' ) );
     244                $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $p3, 'user_id' => 1, 'comment_approved' => '1' ) );
     245
     246                $comment_ids = get_comments( array(
     247                        'fields' => 'ids',
     248                        'post_id__in' => array( $p1, $p2 ),
     249                ) );
     250
     251                $this->assertEqualSets( array( $c1, $c2 ), $comment_ids );
     252        }
     253
     254        /**
     255         * @ticket
     256         */
     257        function test_fields_post_id__not_in() {
     258                $p1 = $this->factory->post->create();
     259                $p2 = $this->factory->post->create();
     260                $p3 = $this->factory->post->create();
     261
     262                $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 7, 'comment_approved' => '1' ) );
     263                $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 1, 'comment_approved' => '1' ) );
     264                $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $p3, 'user_id' => 1, 'comment_approved' => '1' ) );
     265
     266                $comment_ids = get_comments( array(
     267                        'fields' => 'ids',
     268                        'post_id__not_in' => array( $p1, $p2 ),
     269                ) );
     270
     271                $this->assertEqualSets( array( $c3 ), $comment_ids );
     272        }
    201273}