'bldr_testimonials_widget', 'description' => __( 'What are people saying? Let everyone know.', 'bldr') ); parent::__construct(false, $name = __('Home Page Testimonials', 'bldr'), $widget_ops); $this->alt_option_name = 'bldr_testimonials_widget'; 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') ); } // widget form creation function form($instance) { // Check values $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $number = isset( $instance['number'] ) ? intval( $instance['number'] ) : -1; $see_all = isset( $instance['see_all'] ) ? esc_url_raw( $instance['see_all'] ) : ''; $see_all_text = isset( $instance['see_all_text'] ) ? esc_html( $instance['see_all_text'] ) : ''; $random = isset( $instance['random'] ) ? (bool) $instance['random'] : false; ?>
id="get_field_id( 'random' )); ?>" name="get_field_name( 'random' )); ?>" />
flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset($alloptions['bldr_testimonials']) ) delete_option('bldr_testimonials'); return $instance; } function flush_widget_cache() { wp_cache_delete('bldr_testimonials', 'widget'); } // display widget function widget($args, $instance) { $cache = array(); if ( ! $this->is_preview() ) { $cache = wp_cache_get( 'bldr_testimonials', '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 = ( ! empty( $instance['title'] ) ) ? esc_attr( $instance['title'] ) : __( 'Testimonials', 'bldr' ); $title = apply_filters( 'widget_title', esc_attr( $title ), $instance, $this->id_base ); $see_all = isset( $instance['see_all'] ) ? esc_url($instance['see_all']) : ''; $see_all_text = isset( $instance['see_all_text'] ) ? esc_html($instance['see_all_text']) : ''; $number = ( ! empty( $instance['number'] ) ) ? intval( $instance['number'] ) : -1; if ( ! $number ) { $number = -1; } $random = isset( $instance['random'] ) ? (bool) $instance['random'] : false; if ( $random ) { $random = 'rand'; } else { $random = 'date'; } $mt = new WP_Query(array( 'no_found_rows' => true, 'post_status' => 'publish', 'post_type' => 'testimonial', 'posts_per_page' => intval( $number ), 'orderby' => $random, ) ); if ($mt->have_posts()) : ?>