'bldr_projects_widget', 'description' => __( 'With this widget you can display all those projects you are proud of.', 'bldr') ); parent::__construct(false, $name = __('Home Page Projects', 'bldr'), $widget_ops); $this->alt_option_name = 'bldr_projects_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'] ) : ''; ?>
flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset($alloptions['bldr_projects']) ) delete_option('bldr_projects'); return $instance; } function flush_widget_cache() { wp_cache_delete('bldr_projects', 'widget'); } // display widget function widget($args, $instance) { $cache = array(); if ( ! $this->is_preview() ) { $cache = wp_cache_get( 'bldr_projects', '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_html( $instance['title'] ) : __( 'Projects', 'bldr' ); /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters( 'widget_title', esc_html( $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; } $mt = new WP_Query( apply_filters( 'widget_posts_args', array( 'no_found_rows' => true, 'post_status' => 'publish', 'post_type' => 'projects', 'posts_per_page' => -1, 'posts_per_page' => $number ) ) ); if ($mt->have_posts()) : ?>