'moesia_facts_widget', 'description' => __( 'Show your visitors some facts about your company.', 'moesia') );
parent::WP_Widget(false, $name = __('Moesia FP: Facts', 'moesia'), $widget_ops);
$this->alt_option_name = 'moesia_facts_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'] ) : '';
$fact_one = isset( $instance['fact_one'] ) ? esc_html( $instance['fact_one'] ) : '';
$fact_one_max = isset( $instance['fact_one_max'] ) ? absint( $instance['fact_one_max'] ) : '';
$fact_two = isset( $instance['fact_two'] ) ? esc_attr( $instance['fact_two'] ) : '';
$fact_two_max = isset( $instance['fact_two_max'] ) ? absint( $instance['fact_two_max'] ) : '';
$fact_three = isset( $instance['fact_three'] ) ? esc_attr( $instance['fact_three'] ) : '';
$fact_three_max= isset( $instance['fact_three_max'] ) ? absint( $instance['fact_three_max'] ) : '';
$fact_four = isset( $instance['fact_four'] ) ? esc_attr( $instance['fact_four'] ) : '';
$fact_four_max = isset( $instance['fact_four_max'] ) ? absint( $instance['fact_four_max'] ) : '';
$image_uri = isset( $instance['image_uri'] ) ? esc_url( $instance['image_uri'] ) : '';
?>
';
endif;
?>
flush_widget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' );
if ( isset($alloptions['moesia_facts']) )
delete_option('moesia_facts');
return $instance;
}
function flush_widget_cache() {
wp_cache_delete('moesia_facts', 'widget');
}
// display widget
function widget($args, $instance) {
$cache = array();
if ( ! $this->is_preview() ) {
$cache = wp_cache_get( 'moesia_facts', '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'] ) ) ? $instance['title'] : __( 'Our facts', 'moesia' );
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$fact_one = isset( $instance['fact_one'] ) ? esc_html( $instance['fact_one'] ) : '';
$fact_one_max = isset( $instance['fact_one_max'] ) ? absint( $instance['fact_one_max'] ) : '';
$fact_two = isset( $instance['fact_two'] ) ? esc_attr( $instance['fact_two'] ) : '';
$fact_two_max = isset( $instance['fact_two_max'] ) ? absint( $instance['fact_two_max'] ) : '';
$fact_three = isset( $instance['fact_three'] ) ? esc_attr( $instance['fact_three'] ) : '';
$fact_three_max= isset( $instance['fact_three_max'] ) ? absint( $instance['fact_three_max'] ) : '';
$fact_four = isset( $instance['fact_four'] ) ? esc_attr( $instance['fact_four'] ) : '';
$fact_four_max = isset( $instance['fact_four_max'] ) ? absint( $instance['fact_four_max'] ) : '';
$image_uri = isset( $instance['image_uri'] ) ? esc_url($instance['image_uri']) : '';
?>
' . $title . '' . $after_title; ?>
is_preview() ) {
$cache[ $args['widget_id'] ] = ob_get_flush();
wp_cache_set( 'moesia_facts', $cache, 'widget' );
} else {
ob_end_flush();
}
}
}