'widget_fmm_wpmu_recent_entries', 'description' => __( "The most recent posts from the blog of your choosing.") ); $this->WP_Widget('fmm-recent-posts', __('FMM Recent Posts'), $widget_ops); $this->alt_option_name = 'widget_fmm_recent_entries'; 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') ); } function widget($args, $instance) { global $wpdb,$blog_id; $cache = wp_cache_get('widget_fmm_wpmu_recent_entries', 'widget'); if ( !is_array($cache) ) $cache = array(); if ( isset($cache[$args['widget_id']]) ) { echo $cache[$args['widget_id']]; return; } ob_start(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title']); if ( !$number = (int) $instance['number'] ) $number = 10; else if ( $number < 1 ) $number = 1; else if ( $number > 15 ) $number = 15; if ( !$blogs_id = (int) $instance['blogs_id'] ) $blogs_id = $blog_id; $blog_string = 'wp_'.$blogs_id.'_posts'; $counter = 0; $query_results = $wpdb->get_results("SELECT ID FROM $blog_string WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC"); if ($query_results) { ?> flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset($alloptions['widget_fmm_wpmu_recent_entries']) ) delete_option('widget_fmm_wpmu_recent_entries'); return $instance; } function flush_widget_cache() { wp_cache_delete('widget_fmm_wpmu_recent_entries', 'widget'); } function form( $instance ) { $title = isset($instance['title']) ? esc_attr($instance['title']) : ''; $blogs_id = isset($instance['blogs_id']) ? esc_attr($instance['blogs_id']) : ''; if ( !isset($instance['number']) || !$number = (int) $instance['number'] ) $number = 5; ?>