From c647bdc9bb7e72ca651aaf50cf5d034691eee965 Mon Sep 17 00:00:00 2001 From: azaozz Date: Sat, 6 Dec 2008 21:23:36 +0000 Subject: [PATCH] Improve the recent comments dashboard widget, props matt, fixes #8510 git-svn-id: http://svn.automattic.com/wordpress/trunk@10090 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/dashboard.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index fa61eb0ebf..89ad803b48 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -404,21 +404,28 @@ function wp_dashboard_recent_comments() { $allowed_states = array('1'); // Select all comment types and filter out spam later for better query performance. - $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments ORDER BY comment_date_gmt DESC LIMIT 0, 50" ); + $comments = array(); + $start = 0; + + while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments ORDER BY comment_date_gmt DESC LIMIT $start, 50" ) ) { + + foreach ( $possible as $comment ) { + if ( count( $comments ) >= 5 ) + break; + if ( in_array( $comment->comment_approved, $allowed_states ) ) + $comments[] = $comment; + } + + $start = $start + 50; + } if ( $comments ) : ?>
= 5 ) - break; - if ( in_array($comment->comment_approved, $allowed_states) ) - _wp_dashboard_recent_comments_row( $comment ); - $count++; - } + foreach ( $comments as $comment ) + _wp_dashboard_recent_comments_row( $comment ); ?>