WordPress.org

Make WordPress Core

Ticket #19664: recent-comments-fix.diff

File recent-comments-fix.diff, 1.7 KB (added by joehoyle, 2 years ago)
  • wp-admin/includes/dashboard.php

     
    619619                $allowed_states = array('0', '1'); 
    620620        else 
    621621                $allowed_states = array('1'); 
    622  
     622                 
     623        foreach ( $allowed_states as $s ) 
     624                $allowed_states_sql[] = "comment_approved = '$s'"; 
     625         
     626        $allowed_states_sql = 'AND ( ' . implode( ' OR ', $allowed_states_sql ) . ' )'; 
     627         
    623628        // Select all comment types and filter out spam later for better query performance. 
    624629        $comments = array(); 
    625630        $start = 0; 
     
    627632        $widgets = get_option( 'dashboard_widget_options' ); 
    628633        $total_items = isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] ) 
    629634                ? absint( $widgets['dashboard_recent_comments']['items'] ) : 5; 
     635                 
     636        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' $allowed_states_sql ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) { 
    630637 
    631         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" ) ) { 
    632  
    633638                foreach ( $possible as $comment ) { 
    634639                        if ( count( $comments ) >= $total_items ) 
    635640                                break; 
    636                         if ( in_array( $comment->comment_approved, $allowed_states ) && current_user_can( 'read_post', $comment->comment_post_ID ) ) 
     641                        if ( current_user_can( 'read_post', $comment->comment_post_ID ) ) 
    637642                                $comments[] = $comment; 
    638643                } 
    639644