'widget_just_announced', 'description' => __( 'Your most recent events from Eventbrite', 'eventbrite-parent' ) ); parent::__construct( 'just-announced', __( 'Eventbrite: Just Announced', 'eventbrite-parent' ), $widget_ops ); $this->alt_option_name = 'widget_just_announced'; 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' ) ); } /** * Update function for widget * @param type $new_instance * @param type $old_instance * @return type */ function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $this->flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset( $alloptions['widget_just_announced'] ) ) delete_option( 'widget_just_announced' ); return $instance; } /** * Delete widget cache */ function flush_widget_cache() { wp_cache_delete( 'widget_just_announced', 'widget' ); } /** * Display function for widget * @param type $args * @param type $instance * @return type */ function widget( $args, $instance ) { if ( ! Voce_Eventbrite_API::get_auth_service() ) return; $cache = wp_cache_get( 'widget_just_announced', 'widget' ); if ( ! is_array( $cache ) ) $cache = array(); if ( ! isset( $args['widget_id'] ) ) $args['widget_id'] = $this->id; if ( isset( $cache[ $args['widget_id'] ] ) ) { echo wp_kses( $cache[ $args['widget_id'] ], wp_kses_allowed_html( 'post' ) ); return; } ob_start(); extract( $args ); $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Just Announced', 'eventbrite-parent' ); $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $recent_events = Voce_Eventbrite_API::get_user_events( array( 'count' => 5, 'orderby' => 'created', 'order' => 'desc' ) ); if ( ! empty( $recent_events ) ) : ?>