WordPress.org

Make WordPress Core

Ticket #8973: 8973.2.diff

File 8973.2.diff, 6.1 KB (added by matjack1, 2 years ago)

Updated patch for WP 5.0 and added functionality in templates

  • src/wp-includes/comment-template.php

     
    723723                'per_page'  => '',
    724724                'max_depth' => '',
    725725                'cpage'     => null,
     726                'include_unapproved' => '',
    726727        );
    727728        $args     = wp_parse_args( $args, $defaults );
    728729
     
    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' );
     
    13101320 * @global int        $id
    13111321 * @global WP_Comment $comment
    13121322 * @global string     $user_login
    1313  * @global int        $user_ID
    13141323 * @global string     $user_identity
    13151324 * @global bool       $overridden_cpage
    13161325 * @global bool       $withcomments
     
    13201329 *                                  Default false.
    13211330 */
    13221331function comments_template( $file = '/comments.php', $separate_comments = false ) {
    1323         global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
     1332        global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage;
    13241333
    13251334        if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
    13261335                return;
     
    13321341
    13331342        $req = get_option( 'require_name_email' );
    13341343
    1335         /*
    1336          * Comment author information fetched from the comment cookies.
    1337          */
    1338         $commenter = wp_get_current_commenter();
    1339 
    1340         /*
    1341          * The name of the current comment author escaped for use in attributes.
    1342          * Escaped by sanitize_comment_cookies().
    1343          */
    1344         $comment_author = $commenter['comment_author'];
    1345 
    1346         /*
    1347          * The email address of the current comment author escaped for use in attributes.
    1348          * Escaped by sanitize_comment_cookies().
    1349          */
    1350         $comment_author_email = $commenter['comment_author_email'];
    1351 
    1352         /*
    1353          * The url of the current comment author escaped for use in attributes.
    1354          */
    1355         $comment_author_url = esc_url( $commenter['comment_author_url'] );
    1356 
    13571344        $comment_args = array(
    13581345                'orderby'                   => 'comment_date_gmt',
    13591346                'order'                     => 'ASC',
     
    13691356                $comment_args['hierarchical'] = false;
    13701357        }
    13711358
    1372         if ( $user_ID ) {
    1373                 $comment_args['include_unapproved'] = array( $user_ID );
    1374         } elseif ( ! empty( $comment_author_email ) ) {
    1375                 $comment_args['include_unapproved'] = array( $comment_author_email );
     1359        if ( is_user_logged_in() ) {
     1360                $comment_args['include_unapproved'] = get_current_user_id();
     1361        } else {
     1362                $commenter = wp_get_current_commenter();
     1363                if ( $commenter['comment_author_email'] ) {
     1364                        $comment_args['include_unapproved'] = $commenter['comment_author_email'];
     1365                }
    13761366        }
    13771367
    13781368        $per_page = 0;
  • src/wp-includes/comment.php

     
    10341034                'page'      => '',
    10351035                'per_page'  => '',
    10361036                'max_depth' => '',
     1037                'include_unapproved' => '',
    10371038        );
    10381039        $args          = wp_parse_args( $args, $defaults );
    10391040        $original_args = $args;
     
    10781079                        'fields'     => 'ids',
    10791080                        'count'      => true,
    10801081                        'status'     => 'approve',
     1082                        'include_unapproved' => $args['include_unapproved'],
    10811083                        'parent'     => 0,
    10821084                        'date_query' => array(
    10831085                                array(
  • tests/phpunit/tests/comment/getPageOfComment.php

     
    429429
    430430                $this->assertEquals( 2, get_page_of_comment( $c3 ) );
    431431        }
     432
     433  /**
     434   * @ticket 8973
     435   */
     436        public function test_page_number_when_user_has_unapproved_comments() {
     437                $p = self::factory()->post->create();
     438
     439    // page 3
     440                $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' ) );
     441
     442                // page 2
     443                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' ) );
     444                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' ) );
     445                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' ) );
     446
     447                // page 1
     448                $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' ) );
     449                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' ) );
     450                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' ) );
     451
     452                $this->assertEquals( 1, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3 ) ) );
     453                $this->assertEquals( 3, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3, 'include_unapproved' => 'example@example.com' ) ) );
     454
     455                self::factory()->comment->update_object( $unapproved[0], array( 'comment_approved' => 1 ));
     456
     457                $this->assertEquals( 2, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3 ) ) );
     458                $this->assertEquals( 3, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3, 'include_unapproved' => 'example@example.com' ) ) );
     459        }
    432460}