From f4c1734b601ba453907d9288538f6489b3837623 Mon Sep 17 00:00:00 2001
From: nacin
Date: Tue, 14 Dec 2010 17:58:47 +0000
Subject: [PATCH] Remove ceilings on recent comments and posts widgets and
dashboard widgets. fixes #14543.
git-svn-id: http://svn.automattic.com/wordpress/trunk@16922 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
wp-admin/includes/dashboard.php | 12 ++++--------
wp-includes/default-widgets.php | 19 +++++--------------
2 files changed, 9 insertions(+), 22 deletions(-)
diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php
index d27c2eb1d..129c4ecd1 100644
--- a/wp-admin/includes/dashboard.php
+++ b/wp-admin/includes/dashboard.php
@@ -606,10 +606,8 @@ function wp_dashboard_recent_comments() {
$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;
+ $total_items = isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] )
+ ? absint( $widgets['dashboard_recent_comments']['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" ) ) {
@@ -757,9 +755,7 @@ function wp_dashboard_recent_comments_control() {
$widget_options['dashboard_recent_comments'] = array();
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-recent-comments']) ) {
- $number = (int) stripslashes($_POST['widget-recent-comments']['items']);
- if ( $number < 1 || $number > 30 )
- $number = 5;
+ $number = absint( stripslashes($_POST['widget-recent-comments']['items']) );
$widget_options['dashboard_recent_comments']['items'] = $number;
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'] : '';
echo '';
- echo ' ' . __( '(at most 30)' ) . '
';
+ echo '
';
}
function wp_dashboard_incoming_links() {
diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php
index 047728bff..7a7598376 100644
--- a/wp-includes/default-widgets.php
+++ b/wp-includes/default-widgets.php
@@ -1,5 +1,4 @@
id_base);
- if ( !$number = (int) $instance['number'] )
- $number = 10;
- else if ( $number < 1 )
- $number = 1;
- else if ( $number > 15 )
- $number = 15;
+ if ( ! $number = absint( $instance['number'] ) )
+ $number = 10;
$r = new WP_Query(array('posts_per_page' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
if ($r->have_posts()) :
@@ -582,15 +577,13 @@ class WP_Widget_Recent_Posts extends WP_Widget {
function form( $instance ) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
- if ( !isset($instance['number']) || !$number = (int) $instance['number'] )
- $number = 5;
+ $number = isset($instance['number']) ? absint($instance['number']) : 5;
?>
-
$number, 'status' => 'approve' ) );
$output .= $before_widget;
@@ -671,7 +662,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
- $instance['number'] = (int) $new_instance['number'];
+ $instance['number'] = absint( $new_instance['number'] );
$this->flush_widget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' );