WordPress.org

Make WordPress Core

Ticket #8973: 8973.3.diff

File 8973.3.diff, 6.8 KB (added by matjack1, 16 months ago)
  • src/wp-includes/comment-template.php

    From 26bec5a5b5df846c859c6f7cacded7fb2f5cbae1 Mon Sep 17 00:00:00 2001
    From: Matteo Giaccone <matteo@turnintocoders.it>
    Date: Fri, 6 Apr 2018 16:24:19 +0200
    Subject: [PATCH] Patch 8973
    
    ---
     src/wp-includes/comment-template.php          | 39 +++++++------------
     src/wp-includes/comment.php                   |  2 +
     .../tests/comment/getPageOfComment.php        | 28 +++++++++++++
     3 files changed, 43 insertions(+), 26 deletions(-)
    
    diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php
    index 41031cba93..ae04ba3d27 100644
    a b function get_comment_link( $comment = null, $args = array() ) { 
    723723                'per_page'  => '',
    724724                'max_depth' => '',
    725725                'cpage'     => null,
     726                'include_unapproved' => '',
    726727        );
    727728        $args     = wp_parse_args( $args, $defaults );
    728729
    function get_comment_link( $comment = null, $args = array() ) { 
    745746
    746747                $cpage = $args['page'];
    747748
     749                if ( is_user_logged_in() ) {
     750                        $args['include_unapproved'] = get_current_user_id();
     751                } else {
     752                        $commenter = wp_get_current_commenter();
     753                        if ( $commenter['comment_author_email'] ) {
     754                                $args['include_unapproved'] = $commenter['comment_author_email'];
     755                        }
     756                }
     757
    748758                if ( '' == $cpage ) {
    749759                        if ( ! empty( $in_comment_loop ) ) {
    750760                                $cpage = get_query_var( 'cpage' );
    function wp_comment_form_unfiltered_html_nonce() { 
    13111321 * @global int        $id
    13121322 * @global WP_Comment $comment
    13131323 * @global string     $user_login
    1314  * @global int        $user_ID
    13151324 * @global string     $user_identity
    13161325 * @global bool       $overridden_cpage
    13171326 * @global bool       $withcomments
    function wp_comment_form_unfiltered_html_nonce() { 
    13211330 *                                  Default false.
    13221331 */
    13231332function comments_template( $file = '/comments.php', $separate_comments = false ) {
    1324         global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
     1333        global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage;
    13251334
    13261335        if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
    13271336                return;
    function comments_template( $file = '/comments.php', $separate_comments = false 
    13331342
    13341343        $req = get_option( 'require_name_email' );
    13351344
    1336         /*
    1337          * Comment author information fetched from the comment cookies.
    1338          */
    1339         $commenter = wp_get_current_commenter();
    1340 
    1341         /*
    1342          * The name of the current comment author escaped for use in attributes.
    1343          * Escaped by sanitize_comment_cookies().
    1344          */
    1345         $comment_author = $commenter['comment_author'];
    1346 
    1347         /*
    1348          * The email address of the current comment author escaped for use in attributes.
    1349          * Escaped by sanitize_comment_cookies().
    1350          */
    1351         $comment_author_email = $commenter['comment_author_email'];
    1352 
    1353         /*
    1354          * The url of the current comment author escaped for use in attributes.
    1355          */
    1356         $comment_author_url = esc_url( $commenter['comment_author_url'] );
    1357 
    13581345        $comment_args = array(
    13591346                'orderby'                   => 'comment_date_gmt',
    13601347                'order'                     => 'ASC',
    function comments_template( $file = '/comments.php', $separate_comments = false 
    13701357                $comment_args['hierarchical'] = false;
    13711358        }
    13721359
    1373         if ( $user_ID ) {
    1374                 $comment_args['include_unapproved'] = array( $user_ID );
     1360        if ( is_user_logged_in() ) {
     1361                $comment_args['include_unapproved'] = get_current_user_id();
    13751362        } else {
    13761363                $unapproved_email = wp_get_unapproved_comment_author_email();
    13771364
  • src/wp-includes/comment.php

    diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php
    index 5e89ef7695..89ef6aa2e3 100644
    a b function get_page_of_comment( $comment_ID, $args = array() ) { 
    10471047                'page'      => '',
    10481048                'per_page'  => '',
    10491049                'max_depth' => '',
     1050                'include_unapproved' => '',
    10501051        );
    10511052        $args          = wp_parse_args( $args, $defaults );
    10521053        $original_args = $args;
    function get_page_of_comment( $comment_ID, $args = array() ) { 
    10911092                        'fields'     => 'ids',
    10921093                        'count'      => true,
    10931094                        'status'     => 'approve',
     1095                        'include_unapproved' => $args['include_unapproved'],
    10941096                        'parent'     => 0,
    10951097                        'date_query' => array(
    10961098                                array(
  • tests/phpunit/tests/comment/getPageOfComment.php

    diff --git a/tests/phpunit/tests/comment/getPageOfComment.php b/tests/phpunit/tests/comment/getPageOfComment.php
    index 509ecffad6..23e23aa46e 100644
    a b public function test_should_ignore_default_comment_page() { 
    437437
    438438                $this->assertEquals( 2, get_page_of_comment( $c3 ) );
    439439        }
     440
     441  /**
     442   * @ticket 8973
     443   */
     444        public function test_page_number_when_user_has_unapproved_comments() {
     445                $p = self::factory()->post->create();
     446
     447    // page 3
     448                $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' ) );
     449
     450                // page 2
     451                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' ) );
     452                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' ) );
     453                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' ) );
     454
     455                // page 1
     456                $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' ) );
     457                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' ) );
     458                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' ) );
     459
     460                $this->assertEquals( 1, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3 ) ) );
     461                $this->assertEquals( 3, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3, 'include_unapproved' => 'example@example.com' ) ) );
     462
     463                self::factory()->comment->update_object( $unapproved[0], array( 'comment_approved' => 1 ));
     464
     465                $this->assertEquals( 2, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3 ) ) );
     466                $this->assertEquals( 3, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3, 'include_unapproved' => 'example@example.com' ) ) );
     467        }
    440468}