| 1 |
<?php |
| 2 |
/** |
| 3 |
* Nutrition Facts Widget |
| 4 |
* |
| 5 |
* @package Cooked |
| 6 |
* @subpackage Widgets |
| 7 |
* @since 1.2.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* Cooked_Widget_Nutrition Class |
| 12 |
* |
| 13 |
* This class handles the Nutrition Facts widget display. |
| 14 |
* |
| 15 |
* @since 1.2.0 |
| 16 |
*/ |
| 17 |
|
| 18 |
class Cooked_Widget_Nutrition extends WP_Widget { |
| 19 |
|
| 20 |
public function __construct() { |
| 21 |
$widget_ops = array( |
| 22 |
'classname' => 'cooked_nutrition_widget', |
| 23 |
'description' => 'Display nutrition facts on recipe sidebars.', |
| 24 |
); |
| 25 |
parent::__construct( 'cooked_nutrition_widget', 'Cooked - Nutrition Facts', $widget_ops ); |
| 26 |
} |
| 27 |
|
| 28 |
public function widget( $args, $instance ) { |
| 29 |
|
| 30 |
echo wp_kses_post( $args['before_widget'] ); |
| 31 |
if ( ! empty( $instance['title'] ) ) { |
| 32 |
echo wp_kses_post( $args['before_title'] ) . esc_html( apply_filters( 'widget_title', $instance['title'] ) ) . wp_kses_post( $args['after_title'] ); |
| 33 |
} |
| 34 |
echo do_shortcode( '[cooked-nutrition]' ); |
| 35 |
echo wp_kses_post( $args['after_widget'] ); |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
public function form( $instance ) { |
| 40 |
|
| 41 |
$title = ( !empty( $instance['title'] ) ? $instance['title'] : false ); |
| 42 |
|
| 43 |
?> |
| 44 |
|
| 45 |
<p> |
| 46 |
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title (optional):', 'cooked' ); ?></label> |
| 47 |
<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 ); ?>"> |
| 48 |
</p> |
| 49 |
|
| 50 |
<?php |
| 51 |
} |
| 52 |
|
| 53 |
public function update( $new_instance, $old_instance ) { |
| 54 |
$instance = array(); |
| 55 |
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? wp_strip_all_tags( $new_instance['title'] ) : ''; |
| 56 |
return $instance; |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|