WordPress.org

Make WordPress Core

Ticket #8973: 8973-1.diff

File 8973-1.diff, 3.3 KB (added by dossy, 5 years ago)

Test and updated patch to implement this for 4.4-4.5

  • src/wp-includes/comment.php

     
    858858        if ( !$comment = get_comment( $comment_ID ) )
    859859                return;
    860860
    861         $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
     861        $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '', 'include_unapproved' => '' );
    862862        $args = wp_parse_args( $args, $defaults );
    863863        $original_args = $args;
    864864
     
    900900                        'fields'     => 'ids',
    901901                        'count'      => true,
    902902                        'status'     => 'approve',
     903                        'include_unapproved' => $args['include_unapproved'],
    903904                        'parent'     => 0,
    904905                        'date_query' => array(
    905906                                array(
  • tests/phpunit/tests/comment/getPageOfComment.php

     
    238238
    239239                $this->assertEquals( 2, get_page_of_comment( $c1 ) );
    240240        }
     241
     242  /**
     243   * @ticket 8973
     244   */
     245        public function test_page_number_when_user_has_unapproved_comments() {
     246                $p = self::factory()->post->create();
     247
     248    // page 3
     249                $comment_last = self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_date' => '2013-09-20 00:00:00' ) );
     250
     251                // page 2
     252                self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_approved' => 0, 'comment_date' => '2013-09-19 00:00:00' ) );
     253                self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_approved' => 0, 'comment_date' => '2013-09-18 00:00:00' ) );
     254                self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_approved' => 0, 'comment_date' => '2013-09-17 00:00:00' ) );
     255
     256                // page 1
     257                $unapproved = self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_approved' => 0, 'comment_date' => '2013-09-16 00:00:00' ) );
     258                self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_date' => '2013-09-15 00:00:00' ) );
     259                self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_date' => '2013-09-14 00:00:00' ) );
     260
     261                $this->assertEquals( 1, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3 ) ) );
     262                $this->assertEquals( 3, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3, 'include_unapproved' => 'example@example.com' ) ) );
     263
     264                self::factory()->comment->update_object( $unapproved[0], array( 'comment_approved' => 1 ));
     265
     266                $this->assertEquals( 2, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3 ) ) );
     267                $this->assertEquals( 3, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3, 'include_unapproved' => 'example@example.com' ) ) );
     268        }
    241269}