diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php index b8b3e9790a..407af8f586 100644 --- a/wp-includes/default-widgets.php +++ b/wp-includes/default-widgets.php @@ -487,91 +487,88 @@ class WP_Widget_Categories extends WP_Widget { } /** - * Display recent entries widget. + * Recent_Posts widget class * - * @since 2.2.0 - * - * @param array $args Widget arguments. - * @return int Displayed cache. + * @since 2.8.0 */ -function wp_widget_recent_entries($args) { - if ( '%BEG_OF_TITLE%' != $args['before_title'] ) { - if ( $output = wp_cache_get('widget_recent_entries', 'widget') ) - return print($output); - ob_start(); +class WP_Widget_Recent_Posts extends WP_Widget { + + function WP_Widget_Recent_Posts() { + $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your blog") ); + $this->WP_Widget('recent_posts', __('Recent Posts'), $widget_ops); + + add_action( 'save_post', array(&$this, 'flush_widget_cache') ); + add_action( 'deleted_post', array(&$this, 'flush_widget_cache') ); + add_action( 'switch_theme', array(&$this, 'flush_widget_cache') ); } - extract($args); - $options = get_option('widget_recent_entries'); - $title = empty($options['title']) ? __('Recent Posts') : apply_filters('widget_title', $options['title']); - if ( !$number = (int) $options['number'] ) - $number = 10; - else if ( $number < 1 ) - $number = 1; - else if ( $number > 15 ) - $number = 15; + function widget($args, $instance) { + if ( $output = wp_cache_get('widget_recent_entries', 'widget') ) + return print($output); - $r = new WP_Query(array('showposts' => $number, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1)); - if ($r->have_posts()) : + ob_start(); + + extract($args); + + $title = empty($instance['title']) ? __('Recent Posts') : apply_filters('widget_title', $instance['title']); + if ( !$number = (int) $instance['number'] ) + $number = 10; + else if ( $number < 1 ) + $number = 1; + else if ( $number > 15 ) + $number = 15; + + $r = new WP_Query(array('showposts' => $number, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1)); + if ($r->have_posts()) : ?> - +
- + flush_widget_cache(); + + return $instance; } - $title = attribute_escape($options['title']); - if ( !$number = (int) $options['number'] ) - $number = 5; + + function flush_widget_cache() { + wp_cache_delete('widget_recent_entries', 'widget'); + } + + function form( $instance ) { + $title = attribute_escape($instance['title']); + if ( !$number = (int) $instance['number'] ) + $number = 5; ?> - - -
-
-
-
-
+ +
+
+
+
+