PluginProbe
Cooked – Recipe Management / trunk
Cooked – Recipe Management vtrunk
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 1.8.5 All 36 releases
cooked / includes / widgets / search.php

search.php in Cooked – Recipe Management trunk, at includes/widgets/search.php

87 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Search Widget
4 *
5 * @package Cooked
6 * @subpackage Widgets
7 * @since 1.2.0
8 */
9
10 /**
11 * Cooked_Widget_Search Class
12 *
13 * This class handles the Search Form widget display.
14 *
15 * @since 1.2.0
16 */
17
18 class Cooked_Widget_Search extends WP_Widget {
19
20 public function __construct() {
21 $widget_ops = [
22 'classname' => 'cooked_widget_search',
23 'description' => 'Display the recipe search form.',
24 ];
25 parent::__construct( 'cooked_widget_search', 'Cooked - Recipe Search', $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'] ) . apply_filters( 'widget_title', $instance['title'] ) . wp_kses_post( $args['after_title'] );
33 }
34 $size = isset($instance['size']) && $instance['size'] == 'compact' ? ' compact="true"' : '';
35 $browse = isset($instance['hide_browse']) && $instance['hide_browse'] ? ' hide_browse="true"' : '';
36 $sorting = isset($instance['hide_sorting']) && $instance['hide_sorting'] ? ' hide_sorting="true"' : '';
37 echo do_shortcode( '[cooked-search' . esc_attr( $size . $browse . $sorting ) . ']' );
38 echo wp_kses_post( $args['after_widget'] );
39
40 }
41
42 public function form( $instance ) {
43
44 $title = !empty( $instance['title'] ) ? $instance['title'] : false;
45 $size = !empty( $instance['size'] ) ? $instance['size'] : 'compact';
46 $hide_browse = isset( $instance['hide_browse'] ) && $instance['hide_browse'] ? true : false;
47 $hide_sorting = isset( $instance['hide_sorting'] ) && $instance['hide_sorting'] ? true : false;
48
49 ?>
50
51 <p>
52 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title (optional):', 'cooked' ); ?></label>
53 <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 ); ?>">
54 </p>
55
56 <p>
57 <label for="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>"><?php esc_attr_e( 'Size:', 'cooked' ); ?></label>
58 <select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'size' ) ); ?>">
59 <option value="compact"<?php echo $size == 'compact' ? ' selected' : ''; ?>><?php esc_html_e( 'Compact', 'cooked' ); ?></option>
60 <option value="wide"<?php echo $size == 'wide' ? ' selected' : ''; ?>><?php esc_html_e( 'Wide', 'cooked' ); ?></option>
61 </select>
62 </p>
63
64 <p>
65 <input id="<?php echo esc_attr( $this->get_field_id( 'hide_browse' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'hide_browse' ) ); ?>"<?php echo ( $hide_browse ? ' checked' : '' ); ?> type="checkbox" value="1">
66 <label for="<?php echo esc_attr( $this->get_field_id( 'hide_browse' ) ); ?>"><?php esc_attr_e( 'Hide "Browse" dropdown', 'cooked' ); ?></label>
67 </p>
68
69 <p>
70 <input id="<?php echo esc_attr( $this->get_field_id( 'hide_sorting' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'hide_sorting' ) ); ?>"<?php echo ( $hide_sorting ? ' checked' : '' ); ?> type="checkbox" value="1">
71 <label for="<?php echo esc_attr( $this->get_field_id( 'hide_sorting' ) ); ?>"><?php esc_attr_e( 'Hide "Sorting" dropdown', 'cooked' ); ?></label>
72 </p>
73
74 <?php
75 }
76
77 public function update( $new_instance, $old_instance ) {
78 $instance = [];
79 $instance['title'] = !empty( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : '';
80 $instance['size'] = !empty( $new_instance['size'] ) ? wp_strip_all_tags( $new_instance['size'] ) : 'compact';
81 $instance['hide_browse'] = !empty( $new_instance['hide_browse'] ) ? 1 : 0;
82 $instance['hide_sorting'] = !empty( $new_instance['hide_sorting'] ) ? 1 : 0;
83 return $instance;
84 }
85
86 }
87