WordPress.org

Make WordPress Core

Ticket #14222: 14222.4.patch

File 14222.4.patch, 1.6 KB (added by SergeyBiryukov, 21 months ago)
  • wp-admin/includes/dashboard.php

     
    612612        global $wpdb; 
    613613 
    614614        if ( current_user_can('edit_posts') ) 
    615                 $allowed_states = array('0', '1'); 
     615                $allowed_states = "c.comment_approved IN ('0','1') AND"; 
    616616        else 
    617                 $allowed_states = array('1'); 
     617                $allowed_states = "c.comment_approved = '1' AND"; 
    618618 
    619         // Select all comment types and filter out spam later for better query performance. 
    620619        $comments = array(); 
    621620        $start = 0; 
    622621 
     
    624623        $total_items = isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] ) 
    625624                ? absint( $widgets['dashboard_recent_comments']['items'] ) : 5; 
    626625 
    627         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 p.post_status != 'trash' ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) { 
     626        while ( count( $comments ) < $total_items && $possible = $wpdb->get_results( "SELECT c.* 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" ) ) { 
    628627 
    629628                foreach ( $possible as $comment ) { 
    630629                        if ( count( $comments ) >= $total_items ) 
    631630                                break; 
    632                         if ( in_array( $comment->comment_approved, $allowed_states ) && current_user_can( 'read_post', $comment->comment_post_ID ) ) 
     631                        if ( current_user_can( 'read_post', $comment->comment_post_ID ) ) 
    633632                                $comments[] = $comment; 
    634633                } 
    635634