$this->widget_cssclass, 'description' => $this->widget_description ); $this->WP_Widget( $this->widget_id, $this->widget_name, $widget_ops ); 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' ) ); } /** * get_cached_widget function. */ function get_cached_widget( $args ) { $cache = wp_cache_get( apply_filters( 'woocommerce_cached_widget_id', $this->widget_id ), 'widget' ); if ( ! is_array( $cache ) ) $cache = array(); if ( isset( $cache[ $args['widget_id'] ] ) ) { echo $cache[ $args['widget_id'] ]; return true; } return false; } /** * Cache the widget */ public function cache_widget( $args, $content ) { $cache[ $args['widget_id'] ] = $content; wp_cache_set( apply_filters( 'woocommerce_cached_widget_id', $this->widget_id ), $cache, 'widget' ); } /** * Flush the cache * @return [type] */ public function flush_widget_cache() { wp_cache_delete( apply_filters( 'woocommerce_cached_widget_id', $this->widget_id ), 'widget' ); } /** * update function. * * @see WP_Widget->update * @access public * @param array $new_instance * @param array $old_instance * @return array */ function update( $new_instance, $old_instance ) { $instance = $old_instance; if ( ! $this->settings ) return $instance; foreach ( $this->settings as $key => $setting ) { if ( isset( $new_instance[ $key ] ) ) { $instance[ $key ] = sanitize_text_field( $new_instance[ $key ] ); } elseif ( 'checkbox' === $setting['type'] ) { $instance[ $key ] = 0; } } $this->flush_widget_cache(); return $instance; } /** * form function. * * @see WP_Widget->form * @access public * @param array $instance * @return void */ function form( $instance ) { if ( ! $this->settings ) return; foreach ( $this->settings as $key => $setting ) { $value = isset( $instance[ $key ] ) ? $instance[ $key ] : $setting['std']; switch ( $setting['type'] ) { case "text" : ?>

/>