WordPress.org

Make WordPress Core

Ticket #8973: 8973.diff

File 8973.diff, 2.2 KB (added by solarissmoke, 7 years ago)

Include current user's unmoderated comments when finding comment page

  • wp-includes/comment.php

     
    797797
    798798        $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';
    799799
    800         // Count comments older than this one
    801         $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
     800        // Count comments older than this one, including this user's unmoderated comments
     801        $current_user = wp_get_current_user();
     802        $current_commenter = wp_get_current_commenter();
     803       
     804        if ( $comment->user_id && $comment->user_id == $current_user->id )
     805                $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND ( comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) AND comment_date_gmt < %s" . $comtypewhere, $comment->comment_post_ID, $comment->user_id, $comment->comment_date_gmt ) );
     806        elseif ( $current_commenter['comment_author'] == $comment->comment_author && $current_commenter['comment_author_email'] == $comment->comment_author_email )
     807                $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) AND comment_date_gmt < %s" . $comtypewhere, $comment->comment_post_ID, $comment->comment_author, $comment->comment_author_email, $comment->comment_date_gmt ) );
     808        else
     809                $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < %s" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
    802810
    803811        // No older comments? Then it's page #1.
    804812        if ( 0 == $oldercoms )