Ticket #11891: 11891.diff
File 11891.diff, 3.2 KB (added by , 11 years ago) |
---|
-
wp-admin/includes/dashboard.php
28 28 wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' ); 29 29 30 30 // Recent Comments Widget 31 if ( !isset( $widget_options['dashboard_recent_comments'] ) || !isset( $widget_options['dashboard_recent_comments']['items'] ) ) { 32 $update = true; 33 $widget_options['dashboard_recent_comments'] = array( 34 'items' => 5, 35 ); 36 } 31 37 $recent_comments_title = __( 'Recent Comments' ); 32 wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments' );38 wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments', 'wp_dashboard_recent_comments_control' ); 33 39 34 40 // Incoming Links Widget 35 41 if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) { … … 481 487 $comments = array(); 482 488 $start = 0; 483 489 490 $widgets = get_option( 'dashboard_widget_options' ); 491 if ( isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] ) ) 492 $total_items = (int) $widgets['dashboard_recent_comments']['items']; 493 else 494 $total_items = 5; 495 484 496 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" ) ) { 485 497 486 498 foreach ( $possible as $comment ) { 487 if ( count( $comments ) >= 5)499 if ( count( $comments ) >= $total_items ) 488 500 break; 489 501 if ( in_array( $comment->comment_approved, $allowed_states ) ) 490 502 $comments[] = $comment; … … 611 623 <?php 612 624 } 613 625 626 /** 627 * The recent comments dashboard widget control. 628 * 629 * @since 3.0.0 630 */ 631 function wp_dashboard_recent_comments_control() { 632 if ( !$widget_options = get_option( 'dashboard_widget_options' ) ) 633 $widget_options = array(); 634 635 if ( !isset($widget_options['dashboard_recent_comments']) ) 636 $widget_options['dashboard_recent_comments'] = array(); 637 638 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-recent-comments']) ) { 639 $number = (int) stripslashes($_POST['widget-recent-comments']['items']); 640 if ( $number < 1 || $number > 10 ) 641 $number = 5; 642 $widget_options['dashboard_recent_comments']['items'] = $number; 643 update_option( 'dashboard_widget_options', $widget_options ); 644 } 645 646 $number = isset( $widget_options['dashboard_recent_comments']['items'] ) ? (int) $widget_options['dashboard_recent_comments']['items'] : ''; 647 648 echo '<p><label for="comments-number">' . __('Number of comments to show:') . '</label>'; 649 echo '<input id="comments-number" name="widget-recent-comments[items]" type="text" value="' . $number . '" size="3" /> <small>(up to 10)</p>'; 650 651 } 652 614 653 function wp_dashboard_incoming_links() { 615 654 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>'; 616 655 }