Make WordPress Core

Ticket #31101: 31101.patch

File 31101.patch, 1.8 KB (added by tyxla, 10 years ago)

Using the right comparison operator when looking for older/newer comments in get_page_of_comment() (depending on the comment order in Settings -> Discussion).

  • src/wp-includes/comment.php

     
    13751375
    13761376        $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';
    13771377
    1378         // Count comments older than this one
    1379         $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 ) );
     1378        // Determine proper date comparison operator based on comment order
     1379        $comment_order = get_option('comment_order');
     1380        if ($comment_order == 'desc') {
     1381                $date_compare = '>';
     1382        } else {
     1383                $date_compare = '<';
     1384        }
    13801385
    1381         // No older comments? Then it's page #1.
    1382         if ( 0 == $oldercoms )
     1386        // Count comments older/newer than this one.
     1387        // If comment order is "desc" (newer at the top), find newer comments.
     1388        // If comment order is "asc" (older at the top), find older comments.
     1389        $foundcoms = $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 " . $date_compare . " '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
     1390
     1391        // No older/newer comments? Then it's page #1.
     1392        if ( 0 == $foundcoms )
    13831393                return 1;
    13841394
    1385         // Divide comments older than this one by comments per page to get this comment's page number
    1386         return ceil( ( $oldercoms + 1 ) / $args['per_page'] );
     1395        // Divide comments older/newer than this one by comments per page to get this comment's page number
     1396        return ceil( ( $foundcoms + 1 ) / $args['per_page'] );
    13871397}
    13881398
    13891399/**