'widget_fruit_shake_recipe', 'description' => esc_html__( 'Use this widget to display a recipe in your sidebar that perfectly matches your fruitylicious blog.', 'fruit-shake' ) ) ); $this->alt_option_name = 'widget_fruit_shake_recipe'; 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' ) ); } /** * Outputs the HTML for this widget. * * @param array An array of standard parameters for widgets in this theme. * @param array An array of settings for this widget instance. * @return void Echoes its output. **/ function widget( $args, $instance ) { if ( $cache = get_transient( 'widget_fruit_shake_recipe' ) ) { echo $cache; return; } ob_start(); extract( $args, EXTR_SKIP ); // Get the current fruit scheme. $fruit_scheme = fruit_shake_current_fruit_scheme(); $fruit_title = mb_convert_case( $fruit_scheme, MB_CASE_TITLE ); $fruit_title = str_replace( '-', ' ', $fruit_title ); // Whatever the current fruit scheme is, set a title $recipe_title = sprintf( __( '%s Shake', 'fruit-shake' ), $fruit_title ); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? $recipe_title : $instance['title'], $instance, $this->id_base); echo $before_widget; echo $before_title; echo $title; // Can set this with a widget option, or omit altogether. echo $after_title; // Whatever the current fruit scheme is, set a recipe. switch ( $fruit_scheme ) { case 'blueberry': ?>

flush_widget_cache(); return $new_instance; } function flush_widget_cache() { delete_transient( 'widget_fruit_shake_recipe' ); } } function fruit_shake_register_widget() { register_widget( 'Fruit_Shake_Recipe_Widget' ); } add_action( 'widgets_init', 'fruit_shake_register_widget' );