'bro-recent', 'description' => __( 'A better recent posts widget for your sidebar.', 'bromine' ) ) ); $this->alt_option_name = 'bro-recent'; 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') ); } public static function register_recent_sidebar() { register_widget( 'BRO_Recent_Posts' ); } function widget( $args, $instance ) { $cache = wp_cache_get( 'widget_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'] ] ) ) { echo $cache[ $args['widget_id'] ]; return; } ob_start(); extract( $args ); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Recent Posts', 'bromine' ) : $instance['title'], $instance, $this->id_base ); if( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) ) $number = 3; $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) ); if( $r->have_posts() ) : echo $before_widget; if( $title ) echo $before_title . $title . $after_title; ?>
have_posts() ) : $r->the_post(); ?>
'; ?>

flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if( isset( $alloptions['bro_recent_sidebar'] ) ) delete_option( 'bro_recent_sidebar' ); return $instance; } function flush_widget_cache() { wp_cache_delete( 'widget_recent_posts', 'widget' ); } function form( $instance ) { $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; include( plugin_dir_path( __FILE__ ).'/adm-recent.php' ); } }