WordPress.org

Make WordPress Core

Ticket #14222: 14222.2.patch

File 14222.2.patch, 1.5 KB (added by Viper007Bond, 11 years ago)

Remove comment, move comment_approved condition earlier (as it's most likely to exclude an item), and make sure the while() returns enough comments when done

  • wp-admin/includes/dashboard.php

     
    523523        global $wpdb;
    524524
    525525        if ( current_user_can('edit_posts') )
    526                 $allowed_states = array('0', '1');
     526                $allowed_states = 'c.comment_approved IN (0,1) AND';
    527527        else
    528                 $allowed_states = array('1');
     528                $allowed_states = 'c.comment_approved = 1 AND' ;
    529529
    530         // Select all comment types and filter out spam later for better query performance.
    531530        $comments = array();
    532531        $start = 0;
    533532
     
    537536        else
    538537                $total_items = 5;
    539538
    540         while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) {
     539        while ( count( $comments ) < $total_items && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE $allowed_states p.post_status != 'trash' ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) {
    541540
    542541                foreach ( $possible as $comment ) {
    543542                        if ( count( $comments ) >= $total_items )
    544543                                break;
    545                         if ( in_array( $comment->comment_approved, $allowed_states ) && current_user_can( 'read_post', $comment->comment_post_ID ) )
     544                        if ( current_user_can( 'read_post', $comment->comment_post_ID ) )
    546545                                $comments[] = $comment;
    547546                }
    548547