| 1 |
<?php |
| 2 |
|
| 3 |
class Cooked_Widget_Nutrition extends WP_Widget { |
| 4 |
|
| 5 |
public function __construct() { |
| 6 |
$widget_ops = array( |
| 7 |
'classname' => 'cooked_nutrition_widget', |
| 8 |
'description' => 'Display nutrition facts on recipe sidebars.', |
| 9 |
); |
| 10 |
parent::__construct( 'cooked_nutrition_widget', 'Cooked - Nutrition Facts', $widget_ops ); |
| 11 |
} |
| 12 |
|
| 13 |
public function widget( $args, $instance ) { |
| 14 |
|
| 15 |
echo wp_kses_post( $args['before_widget'] ); |
| 16 |
if ( ! empty( $instance['title'] ) ) { |
| 17 |
echo wp_kses_post( $args['before_title'] ) . apply_filters( 'widget_title', $instance['title'] ) . wp_kses_post( $args['after_title'] ); |
| 18 |
} |
| 19 |
echo do_shortcode( '[cooked-nutrition]' ); |
| 20 |
echo wp_kses_post( $args['after_widget'] ); |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
public function form( $instance ) { |
| 25 |
|
| 26 |
$title = ( !empty( $instance['title'] ) ? $instance['title'] : false ); |
| 27 |
|
| 28 |
?> |
| 29 |
|
| 30 |
<p> |
| 31 |
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title (optional):', 'cooked' ); ?></label> |
| 32 |
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>"> |
| 33 |
</p> |
| 34 |
|
| 35 |
<?php |
| 36 |
} |
| 37 |
|
| 38 |
public function update( $new_instance, $old_instance ) { |
| 39 |
$instance = array(); |
| 40 |
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? wp_strip_all_tags( $new_instance['title'] ) : ''; |
| 41 |
return $instance; |
| 42 |
} |
| 43 |
|
| 44 |
} |
| 45 |
|