1: <?php
2: /**
3: * WIDGET :: Author
4: *
5: * @package EPL
6: * @subpackage Widget/Classes/Author
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_Author class
19: *
20: * @since 1.0
21: * @since 3.5 Refactored escaping elements.
22: */
23: class EPL_Widget_Author extends WP_Widget {
24:
25: /**
26: * Construct the widget.
27: *
28: * @since 1.0.0
29: */
30: public function __construct() {
31: parent::__construct( false, $name = esc_html__( 'EPL - Author', 'easy-property-listings' ), array( 'description' => esc_html__( 'Add an Author profile to a sidebar.', 'easy-property-listings' ) ) );
32: // Widget name for filter: epl_author.
33: }
34:
35: /**
36: * Widget function.
37: *
38: * @since 1.0
39: * @since 3.5 Removed unnecessary variables and escaping elements.
40: *
41: * @param array $args Widget arguments.
42: * @param array $instance Widget instance.
43: */
44: public function widget( $args, $instance ) {
45:
46: // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
47:
48: $defaults = array(
49: 'title' => '',
50: 'username' => '',
51: 'display' => 0,
52: 'd_image' => 0,
53: 'd_icons' => 0,
54: 'd_bio' => 0,
55: );
56:
57: $instance = wp_parse_args( (array) $instance, $defaults );
58:
59: foreach ( $args as $arg_key => $arg_val ) {
60: ${$arg_key} = $arg_val;
61: }
62:
63: $title = apply_filters( 'widget_title', $instance['title'] );
64: $username = esc_attr( $instance['username'] );
65: $display = esc_attr( $instance['display'] );
66: $d_image = esc_attr( $instance['d_image'] );
67: $d_icons = esc_attr( $instance['d_icons'] );
68: $d_bio = esc_attr( $instance['d_bio'] );
69:
70: if ( is_epl_post_single() ) {
71: // Only retrieve global $property variable if singluar.
72: global $property;
73: $hide_author_box = $property->get_property_meta( 'property_agent_hide_author_box' );
74: $author_box = apply_filters( 'epl_widget_author_hide_widget', 'off' );
75:
76: if ( 'yes' === $hide_author_box && 'on' === $author_box ) {
77: // Hide Author Box.
78: // Disabled as it makes no sence.
79: } else {
80: echo $before_widget;
81: if ( $title ) {
82: echo $before_title . esc_html( $title ) . $after_title;
83: }
84: epl_property_author_box_simple_card_tall( $instance['d_image'], $instance['d_icons'], $instance['d_bio'], $instance['username'] );
85:
86: echo $after_widget;
87: }
88: } else {
89: echo $before_widget;
90: if ( $title ) {
91: echo $before_title . esc_html( $title ) . $after_title;
92: }
93: epl_property_author_box_simple_card_tall( $instance['d_image'], $instance['d_icons'], $instance['d_bio'], $instance['username'] );
94:
95: echo $after_widget;
96: }
97: }
98:
99: /**
100: * Widget update.
101: *
102: * @param array $new_instance Old values.
103: * @param array $old_instance New values.
104: *
105: * @return array
106: * @since 1.0
107: */
108: public function update( $new_instance, $old_instance ) {
109: $instance = $old_instance;
110:
111: $all_fields = array( 'title', 'username', 'display', 'd_image', 'd_icons', 'd_bio' );
112:
113: foreach ( $all_fields as $all_field ) {
114:
115: if ( isset( $new_instance[ $all_field ] ) ) {
116: $instance[ $all_field ] = epl_strip_tags( $new_instance[ $all_field ] );
117: } else {
118:
119: $instance[ $all_field ] = '';
120:
121: }
122: }
123: return $instance;
124: }
125:
126: /**
127: * Render the widget form.
128: *
129: * @since 1.0
130: * @since 3.5 Added escapoing to elements.
131: * @param array $instance options.
132: */
133: public function form( $instance ) {
134:
135: $defaults = array(
136: 'title' => '',
137: 'username' => '',
138: 'display' => 0,
139: 'd_image' => 0,
140: 'd_icons' => 0,
141: 'd_bio' => 0,
142: );
143:
144: $instance = wp_parse_args( (array) $instance, $defaults );
145:
146: $title = esc_attr( $instance['title'] );
147: $username = esc_attr( $instance['username'] );
148: $display = esc_attr( $instance['display'] );
149: $d_image = esc_attr( $instance['d_image'] );
150: $d_icons = esc_attr( $instance['d_icons'] );
151: $d_bio = esc_attr( $instance['d_bio'] ); ?>
152:
153: <p>
154: <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'easy-property-listings' ); ?></label>
155: <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 ); ?>" />
156: </p>
157:
158: <p>
159: <label for="<?php echo esc_attr( $this->get_field_id( 'username' ) ); ?>"><?php esc_html_e( 'Username:', 'easy-property-listings' ); ?></label>
160: <input autocomplete="off" class="widefat epl-widget-author-username" id="<?php echo esc_attr( $this->get_field_id( 'username' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'username' ) ); ?>" type="text" value="<?php echo esc_attr( $username ); ?>" placeholder="<?php esc_html_e( 'Type to search users', 'easy-property-listings' ); ?>"/>
161: <span class="help"><?php esc_html_e( 'Search for users, supports multiple', 'easy-property-listings' ); ?></span>
162: </p>
163:
164: <p>
165: <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'd_image' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'd_image' ) ); ?>"
166: <?php
167: if ( $instance['d_image'] ) {
168: echo 'checked="checked"';}
169: ?>
170: />
171: <label for="<?php echo esc_attr( $this->get_field_id( 'd_image' ) ); ?>"><?php esc_html_e( 'Display Author Gravatar', 'easy-property-listings' ); ?></label>
172: </p>
173:
174: <p>
175: <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'd_icons' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'd_icons' ) ); ?>"
176: <?php
177: if ( $instance['d_icons'] ) {
178: echo 'checked="checked"';}
179: ?>
180: />
181: <label for="<?php echo esc_attr( $this->get_field_id( 'd_icons' ) ); ?>"><?php esc_html_e( 'Display Icons', 'easy-property-listings' ); ?></label>
182: </p>
183:
184: <p>
185: <input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'd_bio' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'd_bio' ) ); ?>"
186: <?php
187: if ( $instance['d_bio'] ) {
188: echo 'checked="checked"';}
189: ?>
190: />
191: <label for="<?php echo esc_attr( $this->get_field_id( 'd_bio' ) ); ?>"><?php esc_html_e( 'Display Bio', 'easy-property-listings' ); ?></label>
192: </p>
193: <?php
194: }
195: }
196:
197: /**
198: * Register Author Widget.
199: *
200: * Registers the EPL Widgets.
201: *
202: * @since 3.2.2
203: * @return void
204: */
205: function epl_register_widget_author() {
206: register_widget( 'EPL_Widget_Author' );
207: }
208: add_action( 'widgets_init', 'epl_register_widget_author' );
209: