Ticket #14222: 14222.diff

File 14222.diff, 2.6 KB (added by nacin, 13 months ago)
Line 
1Index: wp-admin/includes/dashboard.php
2===================================================================
3--- wp-admin/includes/dashboard.php     (revision 20595)
4+++ wp-admin/includes/dashboard.php     (working copy)
5@@ -595,11 +595,6 @@
6 function wp_dashboard_recent_comments() {
7        global $wpdb;
8 
9-       if ( current_user_can('edit_posts') )
10-               $allowed_states = array('0', '1');
11-       else
12-               $allowed_states = array('1');
13-
14        // Select all comment types and filter out spam later for better query performance.
15        $comments = array();
16        $start = 0;
17@@ -608,44 +603,35 @@
18        $total_items = isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] )
19                ? absint( $widgets['dashboard_recent_comments']['items'] ) : 5;
20 
21-       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" ) ) {
22+       $comments_query = array( 'number' => $total_items * 5, 'offset' => 0 );
23+       if ( ! current_user_can( 'edit_posts' ) )
24+               $comments_query['status'] = 'approve';
25 
26+       while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
27                foreach ( $possible as $comment ) {
28-                       if ( count( $comments ) >= $total_items )
29-                               break;
30-                       if ( in_array( $comment->comment_approved, $allowed_states ) && current_user_can( 'read_post', $comment->comment_post_ID ) )
31-                               $comments[] = $comment;
32+                       if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
33+                               continue;
34+                       $comments[] = $comment;
35+                       if ( count( $comments ) == $total_items )
36+                               break 2;
37                }
38-
39-               $start = $start + 50;
40+               $comments_query['offset'] += $total_items * 10;
41        }
42 
43-       if ( $comments ) :
44-?>
45-
46-               <div id="the-comment-list" class="list:comment">
47-<?php
48+       if ( $comments ) {
49+               echo '<div id="the-comment-list" class="list:comment">';
50                foreach ( $comments as $comment )
51                        _wp_dashboard_recent_comments_row( $comment );
52-?>
53+               echo '</div>';
54 
55-               </div>
56+               if ( current_user_can('edit_posts') )
57+                       _get_list_table('WP_Comments_List_Table')->views();
58 
59-<?php
60-               if ( current_user_can('edit_posts') ) { ?>
61-                       <?php _get_list_table('WP_Comments_List_Table')->views(); ?>
62-<?php  }
63-
64                wp_comment_reply( -1, false, 'dashboard', false );
65                wp_comment_trashnotice();
66-
67-       else :
68-?>
69-
70-       <p><?php _e( 'No comments yet.' ); ?></p>
71-
72-<?php
73-       endif; // $comments;
74+       } else {
75+               echo '<p>' . __( 'No comments yet.' ) . '</p>';
76+       }
77 }
78 
79 function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {