Remove ceilings on recent comments and posts widgets and dashboard widgets. fixes #14543.

git-svn-id: https://develop.svn.wordpress.org/trunk@16922 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2010-12-14 17:58:47 +00:00
parent deea690720
commit dc821cedbf
2 changed files with 9 additions and 22 deletions

View File

@ -606,10 +606,8 @@ function wp_dashboard_recent_comments() {
$start = 0; $start = 0;
$widgets = get_option( 'dashboard_widget_options' ); $widgets = get_option( 'dashboard_widget_options' );
if ( isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] ) ) $total_items = isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] )
$total_items = (int) $widgets['dashboard_recent_comments']['items']; ? absint( $widgets['dashboard_recent_comments']['items'] ) : 5;
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" ) ) { 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" ) ) {
@ -757,9 +755,7 @@ function wp_dashboard_recent_comments_control() {
$widget_options['dashboard_recent_comments'] = array(); $widget_options['dashboard_recent_comments'] = array();
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-recent-comments']) ) { if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-recent-comments']) ) {
$number = (int) stripslashes($_POST['widget-recent-comments']['items']); $number = absint( stripslashes($_POST['widget-recent-comments']['items']) );
if ( $number < 1 || $number > 30 )
$number = 5;
$widget_options['dashboard_recent_comments']['items'] = $number; $widget_options['dashboard_recent_comments']['items'] = $number;
update_option( 'dashboard_widget_options', $widget_options ); update_option( 'dashboard_widget_options', $widget_options );
} }
@ -767,7 +763,7 @@ function wp_dashboard_recent_comments_control() {
$number = isset( $widget_options['dashboard_recent_comments']['items'] ) ? (int) $widget_options['dashboard_recent_comments']['items'] : ''; $number = isset( $widget_options['dashboard_recent_comments']['items'] ) ? (int) $widget_options['dashboard_recent_comments']['items'] : '';
echo '<p><label for="comments-number">' . __('Number of comments to show:') . '</label>'; echo '<p><label for="comments-number">' . __('Number of comments to show:') . '</label>';
echo '<input id="comments-number" name="widget-recent-comments[items]" type="text" value="' . $number . '" size="3" /> <small>' . __( '(at most 30)' ) . '</small></p>'; echo '<input id="comments-number" name="widget-recent-comments[items]" type="text" value="' . $number . '" size="3" /></p>';
} }
function wp_dashboard_incoming_links() { function wp_dashboard_incoming_links() {

View File

@ -1,5 +1,4 @@
<?php <?php
/** /**
* Default Widgets * Default Widgets
* *
@ -535,12 +534,8 @@ class WP_Widget_Recent_Posts extends WP_Widget {
extract($args); extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
if ( !$number = (int) $instance['number'] ) if ( ! $number = absint( $instance['number'] ) )
$number = 10; $number = 10;
else if ( $number < 1 )
$number = 1;
else if ( $number > 15 )
$number = 15;
$r = new WP_Query(array('posts_per_page' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => true)); $r = new WP_Query(array('posts_per_page' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
if ($r->have_posts()) : if ($r->have_posts()) :
@ -582,15 +577,13 @@ class WP_Widget_Recent_Posts extends WP_Widget {
function form( $instance ) { function form( $instance ) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : ''; $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
if ( !isset($instance['number']) || !$number = (int) $instance['number'] ) $number = isset($instance['number']) ? absint($instance['number']) : 5;
$number = 5;
?> ?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label> <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p> <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
<small><?php _e('(at most 15)'); ?></small>
<?php <?php
} }
} }
@ -644,10 +637,8 @@ class WP_Widget_Recent_Comments extends WP_Widget {
$output = ''; $output = '';
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']);
if ( ! $number = (int) $instance['number'] ) if ( ! $number = absint( $instance['number'] ) )
$number = 5; $number = 5;
else if ( $number < 1 )
$number = 1;
$comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) ); $comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) );
$output .= $before_widget; $output .= $before_widget;
@ -671,7 +662,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
function update( $new_instance, $old_instance ) { function update( $new_instance, $old_instance ) {
$instance = $old_instance; $instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']); $instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int) $new_instance['number']; $instance['number'] = absint( $new_instance['number'] );
$this->flush_widget_cache(); $this->flush_widget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' ); $alloptions = wp_cache_get( 'alloptions', 'options' );