'usces_recent_entries', 'description' => ( __( 'Your site’s most recent posts.', 'usces' ) . __( 'Non-item', 'usces' ) ), ); parent::__construct( 'usces-recent-posts', 'Welcart ' . __( 'Recent Posts', 'usces' ), $widget_ops ); $this->alt_option_name = 'usces_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' ) ); } /** * Echoes the widget content. * * @see WP_Widget::widget * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance The settings for the particular instance of the widget. */ public function widget( $args, $instance ) { $cache = wp_cache_get( 'usces_recent_posts', 'widget' ); if ( ! is_array( $cache ) ) { $cache = array(); } if ( ! isset( $args['widget_id'] ) ) { $args['widget_id'] = $this->id; } if ( isset( $cache[ $args['widget_id'] ] ) ) { wel_esc_script_e( $cache[ $args['widget_id'] ] ); return; } usces_remove_filter(); ob_start(); extract( $args ); $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); $number = ( isset( $instance['number'] ) ) ? (int) $instance['number'] : 10; if ( ! $number ) { $number = 10; } elseif ( $number < 1 ) { $number = 1; } elseif ( $number > 15 ) { $number = 15; } $r = new WP_Query( array( 'showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'cat' => -( USCES_ITEM_CAT_PARENT_ID ), 'order' => 'DESC', 'orderby' => 'date', ) ); if ( $r->have_posts() ) : wel_esc_script_e( $before_widget ); if ( ! empty( $title ) ) { wel_esc_script_e( $before_title . esc_html( $title ) . $after_title ); } ?> flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset( $alloptions['usces_recent_entries'] ) ) { delete_option( 'usces_recent_entries' ); } return $instance; } /** * Flushes the Recent Comments widget cache. */ public function flush_widget_cache() { wp_cache_delete( 'usces_recent_posts', 'widget' ); } /** * Outputs the settings update form. * * @see WP_Widget::form * @param array $instance Current settings. */ public function form( $instance ) { $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; if ( ! isset( $instance['number'] ) || ! $number = (int) $instance['number'] ) { $number = 5; } ?>