WordPress.org

Make WordPress Core

Ticket #14222: 14222.diff

File 14222.diff, 2.6 KB (added by nacin, 8 years ago)
  • wp-admin/includes/dashboard.php

     
    595595function wp_dashboard_recent_comments() {
    596596        global $wpdb;
    597597
    598         if ( current_user_can('edit_posts') )
    599                 $allowed_states = array('0', '1');
    600         else
    601                 $allowed_states = array('1');
    602 
    603598        // Select all comment types and filter out spam later for better query performance.
    604599        $comments = array();
    605600        $start = 0;
     
    608603        $total_items = isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] )
    609604                ? absint( $widgets['dashboard_recent_comments']['items'] ) : 5;
    610605
    611         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" ) ) {
     606        $comments_query = array( 'number' => $total_items * 5, 'offset' => 0 );
     607        if ( ! current_user_can( 'edit_posts' ) )
     608                $comments_query['status'] = 'approve';
    612609
     610        while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
    613611                foreach ( $possible as $comment ) {
    614                         if ( count( $comments ) >= $total_items )
    615                                 break;
    616                         if ( in_array( $comment->comment_approved, $allowed_states ) && current_user_can( 'read_post', $comment->comment_post_ID ) )
    617                                 $comments[] = $comment;
     612                        if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
     613                                continue;
     614                        $comments[] = $comment;
     615                        if ( count( $comments ) == $total_items )
     616                                break 2;
    618617                }
    619 
    620                 $start = $start + 50;
     618                $comments_query['offset'] += $total_items * 10;
    621619        }
    622620
    623         if ( $comments ) :
    624 ?>
    625 
    626                 <div id="the-comment-list" class="list:comment">
    627 <?php
     621        if ( $comments ) {
     622                echo '<div id="the-comment-list" class="list:comment">';
    628623                foreach ( $comments as $comment )
    629624                        _wp_dashboard_recent_comments_row( $comment );
    630 ?>
     625                echo '</div>';
    631626
    632                 </div>
     627                if ( current_user_can('edit_posts') )
     628                        _get_list_table('WP_Comments_List_Table')->views();
    633629
    634 <?php
    635                 if ( current_user_can('edit_posts') ) { ?>
    636                         <?php _get_list_table('WP_Comments_List_Table')->views(); ?>
    637 <?php   }
    638 
    639630                wp_comment_reply( -1, false, 'dashboard', false );
    640631                wp_comment_trashnotice();
    641 
    642         else :
    643 ?>
    644 
    645         <p><?php _e( 'No comments yet.' ); ?></p>
    646 
    647 <?php
    648         endif; // $comments;
     632        } else {
     633                echo '<p>' . __( 'No comments yet.' ) . '</p>';
     634        }
    649635}
    650636
    651637function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {