1: <?php
2: /**
3: * WIDGET :: Property Search
4: *
5: * @package EPL
6: * @subpackage Widget/Classes/Search
7: * @copyright Copyright (c) 2019, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 1.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: /**
18: * EPL_Widget_Property_Search class
19: *
20: * @since 1.0
21: */
22: class EPL_Widget_Property_Search extends WP_Widget {
23:
24: /**
25: * Construct the widget.
26: *
27: * @since 1.0.0
28: */
29: public function __construct() {
30: parent::__construct( false, $name = __( 'EPL - Listing Search', 'easy-property-listings' ), array( 'description' => __( 'Search listings.', 'easy-property-listings' ) ) );
31: // Widget name for filter: epl_property_search.
32: }
33:
34: /**
35: * Widget function.
36: *
37: * @since 1.0
38: * @since 3.5 Added escaping to elements.
39: * @param array $args Widget arguments.
40: * @param array $instance Widget instance.
41: */
42: public function widget( $args, $instance ) {
43:
44: // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
45:
46: $defaults = epl_search_get_defaults();
47: $instance = wp_parse_args( (array) $instance, $defaults );
48:
49: foreach ( $args as $arg_key => $arg_val ) {
50: ${$arg_key} = $arg_val;
51: }
52:
53: echo $before_widget;
54:
55: $title = apply_filters( 'widget_title', $instance['title'] );
56:
57: if ( $title ) {
58: echo $before_title . esc_html( $title ) . $after_title;
59: }
60:
61: echo epl_shortcode_listing_search_callback( $instance );
62:
63: echo $after_widget;
64: }
65:
66: /**
67: * Widget update.
68: *
69: * @param array $new_instance New values.
70: * @param array $old_instance Old values.
71: *
72: * @return array
73: * @since 1.0
74: */
75: public function update( $new_instance, $old_instance ) {
76: $instance = $old_instance;
77: $all_fields = epl_search_widget_fields();
78: foreach ( $all_fields as $all_field ) {
79:
80: if ( isset( $new_instance[ $all_field['key'] ] ) ) {
81: $instance[ $all_field['key'] ] = epl_strip_tags( $new_instance[ $all_field['key'] ] );
82: } else {
83: $instance[ $all_field['key'] ] = '';
84: }
85: }
86: return $instance;
87: }
88:
89: /**
90: * Render the widget form.
91: *
92: * @since 1.0
93: * @param array $instance options.
94: */
95: public function form( $instance ) {
96:
97: // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
98:
99: $defaults = epl_search_get_defaults();
100: $instance = wp_parse_args( (array) $instance, $defaults );
101: $instance = array_map( 'epl_esc_attr', $instance );
102:
103: foreach ( $instance as $in_key => $in_val ) {
104: ${$in_key} = $in_val;
105: }
106:
107: $post_types = $post_type;
108: $fields = epl_search_widget_fields();
109:
110: foreach ( $fields as $field ) {
111: $field_value = ${$field['key']};
112: epl_widget_render_backend_field( $field, $this, $field_value );
113: }
114: }
115: }
116:
117: /**
118: * Register Listing Search Widget.
119: *
120: * Registers the EPL Widgets.
121: *
122: * @since 3.2.2
123: * @return void
124: */
125: function epl_register_widget_property_search() {
126: register_widget( 'EPL_Widget_Property_Search' );
127: }
128: add_action( 'widgets_init', 'epl_register_widget_property_search' );
129: