PluginProbe
Cooked – Recipe Management / 1.16.1
Cooked – Recipe Management v1.16.1
1.16.1 1.16.0 1.15.0 trunk 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.12.0 1.13.0 1.14.0 1.7.10 1.7.11 1.7.12 1.7.13 1.7.15.1 1.7.15.3 1.7.15.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 All 37 releases
cooked / includes / widgets / recipe-categories.php

recipe-categories.php in Cooked – Recipe Management 1.16.1, at includes/widgets/recipe-categories.php

89 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Recipe Categories Widget
4 *
5 * @package Cooked
6 * @subpackage Widgets
7 * @since 1.6.4
8 */
9
10 /**
11 * Cooked_Widget_Recipe_Categories Class
12 *
13 * This class handles the Recipe Categories widget display.
14 *
15 * @since 1.6.4
16 */
17
18 class Cooked_Widget_Recipe_Categories extends WP_Widget {
19
20 public function __construct() {
21 $widget_ops = [
22 'classname' => 'cooked_widget_recipe_categories',
23 'description' => 'Display a list of recipe categories.',
24 ];
25 parent::__construct( 'cooked_widget_recipe_categories', 'Cooked - Recipe Categories', $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
35 $width = isset($instance['width']) && $instance['width'] ? ' width="' . esc_attr( $instance['width'] ) . '"' : '';
36 $child_of = isset($instance['child_of']) && $instance['child_of'] ? ' child_of="' . esc_attr( $instance['child_of'] ) . '"' : '';
37 $hide_empty = isset($instance['hide_empty']) && $instance['hide_empty'] ? ' hide_empty="' . esc_attr( $instance['hide_empty'] ) . '"' : '';
38 $show_description = isset($instance['show_description']) && $instance['show_description'] ? ' show_description="' . esc_attr( $instance['show_description'] ) . '"' : '';
39
40 echo do_shortcode( '[cooked-categories' . esc_attr( $width . $child_of . $hide_empty . $show_description ) . ' style="list"]' );
41 echo wp_kses_post( $args['after_widget'] );
42
43 }
44
45 public function form( $instance ) {
46
47 $title = !empty( $instance['title'] ) ? $instance['title'] : false;
48 $child_of = !empty( $instance['child_of'] ) ? $instance['child_of'] : false;
49 $hide_empty = !empty( $instance['hide_empty'] ) ? $instance['hide_empty'] : false;
50 $categories_array = Cooked_Settings::terms_array( 'cp_recipe_category', false, false, false, false, false );
51
52 ?>
53
54 <p>
55 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Widget Title (optional):', 'cooked' ); ?></label>
56 <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 ); ?>">
57 </p>
58
59 <p>
60 <label for="<?php echo esc_attr( $this->get_field_id( 'child_of' ) ); ?>"><?php esc_attr_e( 'Parent Category', 'cooked' ); ?></label>
61 <select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'child_of' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'child_of' ) ); ?>">
62 <?php if ( !empty($categories_array) ):
63 ?><option value=""<?php echo !$child_of ? ' selected' : ''; ?>><?php esc_html_e( 'All Categories', 'cooked' ); ?></option><?php
64 foreach( $categories_array as $key => $val ):
65 ?><option value="<?php echo esc_attr( $key ); ?>"<?php echo $child_of == $key ? ' selected' : ''; ?>><?php echo esc_html( $val ); ?></option><?php
66 endforeach;
67 endif; ?>
68 </select>
69 </p>
70
71 <p>
72 <input id="<?php echo esc_attr( $this->get_field_id( 'hide_empty' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'hide_empty' ) ); ?>"<?php echo $hide_empty ? ' checked' : ''; ?> type="checkbox" value="1">
73 <label for="<?php echo esc_attr( $this->get_field_id( 'hide_empty' ) ); ?>"><?php esc_attr_e( 'Hide Empty Categories', 'cooked' ); ?></label>
74 </p>
75
76 <?php
77 }
78
79 public function update( $new_instance, $old_instance ) {
80
81 $instance = [];
82 $instance['title'] = !empty( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : '';
83 $instance['child_of'] = !empty( $new_instance['child_of'] ) ? wp_strip_all_tags( $new_instance['child_of'] ) : false;
84 $instance['hide_empty'] = !empty( $new_instance['hide_empty'] ) ? wp_strip_all_tags( $new_instance['hide_empty'] ) : false;
85 return $instance;
86 }
87
88 }
89