1: <?php
2: /**
3: * WIDGET :: Contact Capture
4: *
5: * @package EPL
6: * @subpackage Widget/Classes/ContactCapture
7: * @copyright Copyright (c) 2019, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 3.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: /**
18: * EPL_Widget_Contact_Capture class
19: *
20: * @since 3.0
21: */
22: class EPL_Widget_Contact_Capture 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 - Contact Form', 'easy-property-listings' ), array( 'description' => __( 'Add contact form to a sidebar.', 'easy-property-listings' ) ) );
31: // Widget name for filter: epl_contact_capture.
32: }
33:
34: /**
35: * Widget function.
36: *
37: * @since 1.0
38: * @since 3.5 Added escaping to elements.
39: *
40: * @param array $args Widget arguments.
41: * @param array $instance Widget instance.
42: */
43: public function widget( $args, $instance ) {
44:
45: // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
46:
47: $defaults = epl_contact_capture_get_widget_defaults();
48:
49: $instance = wp_parse_args( (array) $instance, $defaults );
50:
51: foreach ( $args as $arg_key => $arg_val ) {
52: ${$arg_key} = $arg_val;
53: }
54:
55: $title = apply_filters( 'widget_title', $instance['title'] );
56:
57: echo $before_widget;
58: if ( $title ) {
59: echo $before_title . esc_html( $title ) . $after_title;
60: }
61: echo epl_contact_capture_form( $instance );
62:
63: echo $after_widget;
64: }
65:
66: /**
67: * Widget update.
68: *
69: * @param array $new_instance Old values.
70: * @param array $old_instance New 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_contact_capture_widget_form_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'] ], apply_filters( 'epl_contact_form_description_allowed_tags', '<br><p><strong><div><span><hr><img>' ) );
82: } else {
83:
84: $instance[ $all_field['key'] ] = '';
85:
86: }
87: }
88: return $instance;
89: }
90:
91: /**
92: * Render the widget form.
93: *
94: * @since 1.0
95: * @param array $instance options.
96: */
97: public function form( $instance ) {
98: $defaults = epl_contact_capture_get_widget_defaults();
99:
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:
105: ${$in_key} = $in_val;
106: }
107:
108: $fields = epl_contact_capture_widget_form_fields();
109: foreach ( $fields as $field ) {
110: $field_value = ${$field['key']};
111: epl_widget_render_backend_field( $field, $this, $field_value );
112: }
113: }
114: }
115:
116: /**
117: * Register Contact Widget.
118: *
119: * Registers the EPL Widgets.
120: *
121: * @since 3.2.2
122: * @return void
123: */
124: function epl_register_widget_contact_form() {
125: register_widget( 'EPL_Widget_Contact_Capture' );
126: }
127: add_action( 'widgets_init', 'epl_register_widget_contact_form' );
128: