'widget_affiliate_links_recent', 'description' => esc_html__( 'The most recent affiliate links on your site', 'affiliate-links' ), ); $this->stat_instance = Affiliate_Links_Pro_Stats::get_instance(); parent::__construct( 'affiliate-links-recent', esc_html__( 'Recent Affiliate Links', 'affiliate-links' ), $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' ) ); } public function widget( $args, $instance ) { $cache = wp_cache_get( 'widget_affiliate_links_recent', 'widget' ); if ( ! is_array( $cache ) ) { $cache = array(); } if ( isset( $cache[ $args['widget_id'] ] ) ) { echo wp_kses_post( $cache[ $args['widget_id'] ] ); return; } ob_start(); extract( $args ); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? esc_html__( 'Recent Links', 'affiliate-links' ) : $instance['title'], $instance, $this->id_base ); $links_ids = $this->stat_instance->get_recent_links( $instance ); if ( ! empty( $links_ids ) ) : echo wp_kses_post( $args['before_widget'] ); if ( $title ) { echo wp_kses_post( $args['before_title'] ) . esc_html( $title ) . wp_kses_post( $args['after_title'] ); } ?>
flush_widget_cache(); delete_option( 'widget_affiliate_links_recent' ); return $instance; } public function flush_widget_cache() { wp_cache_delete( 'widget_affiliate_links_recent', 'widget' ); } public function form( $instance ) { $title = isset( $instance['title'] ) ? $instance['title'] : ''; $number = isset( $instance['number'] ) ? $instance['number'] : 5; $cat = isset( $instance['cat'] ) ? $instance['cat'] : 0; $terms = get_terms( Affiliate_Links::$taxonomy ); ?>