'jigoshop_product_categories', 'description' => __( 'A list or dropdown of product categories', 'jigoshop' ), ); // Create the widget parent::__construct( 'jigoshop_product_categories', __( 'Jigoshop: Product Categories', 'jigoshop' ), $options ); // Flush cache after every save 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 * * Display the widget in the sidebar * Save output to the cache if empty * * @param array sidebar arguments * @param array instance */ public function widget( $args, $instance ) { // Get the widget cache from the transient $cache = get_transient( 'jigoshop_widget_cache' ); // If this category widget instance is cached, get from the cache if ( isset( $cache[$this->id] ) ) { echo $cache[$this->id]; return false; } // Otherwise Start buffering and output the Widget ob_start(); extract( $args ); // Set the widget title $title = apply_filters( 'widget_title', ( $instance['title'] ) ? $instance['title'] : __( 'Product Categories', 'jigoshop' ), $instance, $this->id_base ); // Get options $count = (bool) isset( $instance['count'] ) ? $instance['count'] : false; $is_hierarchial = (bool) isset( $instance['hierarchical'] ) ? $instance['hierarchical'] : false; $is_dropdown = (bool) isset( $instance['dropdown'] ) ? $instance['dropdown'] : false; // Print the widget wrapper & title echo $before_widget; echo $before_title . $title . $after_title; // Define options for the list $args = array( 'orderby' => 'name', 'show_count' => $count, 'hierarchical' => $is_hierarchial, 'taxonomy' => 'product_cat', 'title_li' => null, ); // Output as dropdown or unordered list if( $is_dropdown ) { // Set up arguments $args['name'] = 'dropdown_product_cat'; // Print dropdown // wp_dropdown_categories($args); Commented out due to wordpress bug 13258 not supporting custom taxonomies // See: http://core.trac.wordpress.org/ticket/13258 jigoshop_product_dropdown_categories( $args['show_count'], $args['hierarchical'] ); // TODO: Move this javascript to its own file (plugins.js?) ?> '; wp_list_categories(apply_filters('widget_product_categories_args', $args)); echo ''; } // Print closing widget wrapper echo $after_widget; // Flush output buffer and save to transient cache $result = ob_get_flush(); $cache[$this->id] = $result; set_transient( 'jigoshop_widget_cache', $cache, 3600*3 ); // 3 hours ahead } /** * Update * * Handles the processing of information entered in the wordpress admin * Flushes the cache & removes entry from options array * * @param array new instance * @param array old instance * @return array instance */ function update( $new_instance, $old_instance ) { $instance = $old_instance; // Save the new values $instance['title'] = strip_tags( $new_instance['title'] ); $instance['count'] = (bool) isset( $new_instance['count'] ) ? $new_instance['count'] : false; $instance['hierarchical'] = (bool) isset( $new_instance['hierarchical'] ) ? $new_instance['hierarchical'] : false; $instance['dropdown'] = (bool) isset( $new_instance['dropdown'] ) ? $new_instance['dropdown'] : false; // Flush the cache $this->flush_widget_cache(); return $instance; } /** * Flush Widget Cache * * Flushes the cached output */ public function flush_widget_cache() { delete_transient( 'jigoshop_widget_cache' ); } /** * Form * * Displays the form for the wordpress admin * * @param array instance */ function form( $instance ) { // Get values from instance $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : null; $dropdown = (bool) isset($instance['dropdown']) ? $instance['dropdown'] : false; $count = (bool) isset($instance['count']) ? $instance['count'] : false; $hierarchical = (bool) isset($instance['hierarchical']) ? $instance['hierarchical'] : false; // Widget Title echo "
"; // As a dropdown? echo "
";
// Show product count?
echo "
";
// Is hierarchical?
echo "