'chef_recipes_a', 'description' => __( "Show recipes", "chef") ); parent::__construct('recipes-type-a', __( "Chef: Recipes Type A", "chef"), $widget_ops); $this->alt_option_name = 'widget_recipes_a'; 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 = array(); if ( ! $this->is_preview() ) { $cache = wp_cache_get( 'widget_recipes', '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(); $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : ''; /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $course = isset( $instance['course'] ) ? esc_attr($instance['course']) : ''; $cuisine = isset( $instance['cuisine'] ) ? esc_attr($instance['cuisine']) : ''; $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'post_type' => 'recipe', 'course' => $course, 'cuisine' => $cuisine, ) ) ); if ($r->have_posts()) : ?> have_posts() ) : $r->the_post(); //Check if Recipe Hero is active and get the custom fields values if ( class_exists( 'RecipeHero' ) ) { $serves = get_post_meta( $post->ID, '_recipe_hero_detail_serves', true ); $serves_type = get_post_meta( $post->ID, '_recipe_hero_detail_serves_type', true ); $prep_time = recipe_hero_convert_minute_hour( get_post_meta( $post->ID, '_recipe_hero_detail_prep_time', true ) ); $cook_time = recipe_hero_convert_minute_hour( get_post_meta( $post->ID, '_recipe_hero_detail_cook_time', true ) ); } ?>
', esc_url( get_permalink() ) ), '' ); ?>  ' ); ?>

', esc_url( get_permalink() ) ), '' ); ?>
is_preview() ) { $cache[ $args['widget_id'] ] = ob_get_flush(); wp_cache_set( 'widget_recipes', $cache, 'widget' ); } else { ob_end_flush(); } } public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['course'] = strip_tags($new_instance['course']); $instance['cuisine'] = strip_tags($new_instance['cuisine']); $this->flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset($alloptions['chef_recipes']) ) delete_option('chef_recipes'); return $instance; } public function flush_widget_cache() { wp_cache_delete('widget_recipes', 'widget'); } public function form( $instance ) { $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $course = isset( $instance['course'] ) ? esc_attr( $instance['course'] ) : ''; $cuisine = isset( $instance['cuisine'] ) ? esc_attr( $instance['cuisine'] ) : ''; ?>