From 1a4072f2e7d44397c0ba29cd9777cd436fb689db Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sat, 13 Feb 2010 04:39:39 +0000 Subject: [PATCH] Make Recent Comments dashboard widget configurable. Allows user to choose how many comments to display, see #11891. git-svn-id: https://develop.svn.wordpress.org/trunk@13084 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/dashboard.php | 42 +++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index 2b43f73da6..6189240e01 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -28,8 +28,14 @@ function wp_dashboard_setup() { wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' ); // Recent Comments Widget + if ( !isset( $widget_options['dashboard_recent_comments'] ) || !isset( $widget_options['dashboard_recent_comments']['items'] ) ) { + $update = true; + $widget_options['dashboard_recent_comments'] = array( + 'items' => 5, + ); + } $recent_comments_title = __( 'Recent Comments' ); - wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments' ); + wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments', 'wp_dashboard_recent_comments_control' ); // Incoming Links Widget if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) { @@ -482,10 +488,16 @@ function wp_dashboard_recent_comments() { $comments = array(); $start = 0; + $widgets = get_option( 'dashboard_widget_options' ); + if ( isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] ) ) + $total_items = (int) $widgets['dashboard_recent_comments']['items']; + else + $total_items = 5; + while ( count( $comments ) < 5 && $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" ) ) { foreach ( $possible as $comment ) { - if ( count( $comments ) >= 5 ) + if ( count( $comments ) >= $total_items ) break; if ( in_array( $comment->comment_approved, $allowed_states ) ) $comments[] = $comment; @@ -615,6 +627,32 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { 15 ) + $number = 5; + $widget_options['dashboard_recent_comments']['items'] = $number; + update_option( 'dashboard_widget_options', $widget_options ); + } + + $number = isset( $widget_options['dashboard_recent_comments']['items'] ) ? (int) $widget_options['dashboard_recent_comments']['items'] : ''; + + echo '

'; + echo ' ' . __( '(at most 15)' ) . '

'; +} + function wp_dashboard_incoming_links() { echo '

' . __( 'Loading…' ) . '

' . __('This widget requires JavaScript.') . '

'; }