1: <?php
2: /**
3: * Render HTML Fields
4: *
5: * @package EPL
6: * @subpackage Classes/RenderFields
7: * @copyright Copyright (c) 2020, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 2.3
10: * @since 3.4.29 Moved from meta-boxes into its own class for more extensibility.
11: * @since 3.4.44 Added help field type in meta boxes fields.
12: */
13:
14: // Exit if accessed directly.
15: if ( ! defined( 'ABSPATH' ) ) {
16: exit;
17: }
18:
19: /**
20: * EPL_Render_Fields class.
21: *
22: * Handles rendering of html fields for EPL settings, meta boxes etc.
23: *
24: * @since 2.3
25: * @since 3.4.29 Moved from meta-boxes into its own class for more extensibility.
26: * @since 3.4.48 New: Field type textarea_html which works like the editor field type but without loading the MCE buttons.
27: */
28: class EPL_Render_Fields {
29:
30: /**
31: * Default class prefix.
32: *
33: * @var string $class_prefix
34: */
35: public $class_prefix = 'epl-form-field-';
36:
37: /**
38: * Post object.
39: *
40: * @var array $post
41: */
42: public $post;
43:
44: /**
45: * Constructs a new instance.
46: */
47: public function __construct() {
48:
49: add_action( 'epl_render_field_select', array( $this, 'select' ), 10, 2 );
50: add_action( 'epl_render_field_select_multiple', array( $this, 'select' ), 10, 2 );
51: add_action( 'epl_render_field_checkbox', array( $this, 'checkbox' ), 10, 2 );
52: add_action( 'epl_render_field_checkbox_option', array( $this, 'checkbox_option' ), 10, 2 );
53: add_action( 'epl_render_field_checkbox_single', array( $this, 'checkbox_single' ), 10, 2 );
54: add_action( 'epl_render_field_radio', array( $this, 'radio' ), 10, 2 );
55: add_action( 'epl_render_field_file', array( $this, 'file' ), 10, 2 ); // File and image.
56: add_action( 'epl_render_field_image', array( $this, 'file' ), 10, 2 ); // File and image.
57: add_action( 'epl_render_field_editor', array( $this, 'editor' ), 10, 2 );
58: add_action( 'epl_render_field_textarea', array( $this, 'textarea' ), 10, 2 );
59: add_action( 'epl_render_field_textarea_html', array( $this, 'textarea_html' ), 10, 2 );
60: add_action( 'epl_render_field_decimal', array( $this, 'render_default' ), 10, 2 );
61: add_action( 'epl_render_field_number', array( $this, 'render_default' ), 10, 2 );
62: add_action( 'epl_render_field_date', array( $this, 'render_default' ), 10, 2 );
63: add_action( 'epl_render_field_auction-date', array( $this, 'render_default' ), 10, 2 );
64: add_action( 'epl_render_field_sold-date', array( $this, 'render_default' ), 10, 2 );
65: add_action( 'epl_render_field_email', array( $this, 'render_default' ), 10, 2 );
66: add_action( 'epl_render_field_url', array( $this, 'render_default' ), 10, 2 );
67: add_action( 'epl_render_field_button', array( $this, 'render_default' ), 10, 2 );
68: add_action( 'epl_render_field_color', array( $this, 'render_default' ), 10, 2 );
69: add_action( 'epl_render_field_text', array( $this, 'render_default' ), 10, 2 );
70: add_action( 'epl_render_field_hidden', array( $this, 'render_default' ), 10, 2 );
71: add_action( 'epl_render_field_submit', array( $this, 'render_default' ), 10, 2 );
72: add_action( 'epl_render_field_password', array( $this, 'render_default' ), 10, 2 );
73: add_action( 'epl_render_field_locked', array( $this, 'locked' ), 10, 2 );
74: add_action( 'epl_render_field_help', array( $this, 'help' ), 10, 2 );
75: add_action( 'epl_render_field_html', array( $this, 'html' ), 10, 2 );
76: }
77:
78: /**
79: * Process field paramaters.
80: *
81: * @param array $field The field.
82: * @param string $val The value.
83: *
84: * @return array The array of fields.
85: */
86: public function process_field_params( $field, $val ) {
87:
88: $field = apply_filters( 'pre_process_field_params', $field );
89:
90: if ( 'date' === $field['type'] ) {
91: $field['data-format'] = isset( $field['format'] ) ? $field['format'] : 'Y-m-d';
92: $field['data-timepicker'] = isset( $field['timepicker'] ) ? $field['timepicker'] : false;
93: }
94:
95: $field['id'] = $this->get_id( $field );
96: $field['name'] = $this->get_name( $field );
97: $field['class'] = $this->get_class( $field );
98: $field['data'] = $this->get_data_attributes( $field );
99: $field['min'] = $this->get_min( $field );
100: $field['max'] = $this->get_max( $field );
101: $field['maxlength'] = $this->get_maxlength( $field );
102: $field['placeholder'] = $this->get_placeholder( $field );
103: $field['autocomplete'] = $this->get_autocomplete( $field );
104: $field['multiple'] = $this->is_multiple( $field );
105: $field['required'] = $this->is_required( $field );
106: $field['value'] = 'button' === $field['type'] ? $field['value'] : $val;
107: return apply_filters( 'post_process_field_params', $field );
108: }
109:
110: /**
111: * Gets the minimum.
112: *
113: * @param array $field The field.
114: *
115: * @return string The minimum.
116: */
117: public function get_min( $field ) {
118: return isset( $field['min'] ) ? $field['min'] : '';
119: }
120:
121: /**
122: * Determines whether the specified field is multiple.
123: *
124: * @param array $field The field.
125: *
126: * @return boolean True if the specified field is multiple, False otherwise.
127: */
128: public function is_multiple( $field ) {
129: return 'select_multiple' === $field['type'] ? ' multiple ' : '';
130: }
131:
132: /**
133: * Gets the maximum.
134: *
135: * @param array $field The field.
136: *
137: * @return string The maximum.
138: */
139: public function get_max( $field ) {
140: return isset( $field['max'] ) ? $field['max'] : '';
141: }
142:
143: /**
144: * Gets the maxlength.
145: *
146: * @param array $field The field.
147: *
148: * @return string The maxlength.
149: */
150: public function get_maxlength( $field ) {
151: return isset( $field['maxlength'] ) ? (int) $field['maxlength'] : '';
152: }
153:
154: /**
155: * Gets the placeholder.
156: *
157: * @param array $field The field.
158: *
159: * @return string The placeholder.
160: */
161: public function get_placeholder( $field ) {
162: return isset( $field['placeholder'] ) ? $field['placeholder'] : '';
163: }
164:
165: /**
166: * Gets the autocomplete.
167: *
168: * @param array $field The field.
169: *
170: * @return string The autocomplete.
171: */
172: public function get_autocomplete( $field ) {
173: return isset( $field['autocomplete'] ) ? $field['autocomplete'] : '';
174: }
175:
176: /**
177: * Determines whether the specified field is required.
178: *
179: * @param array $field The field.
180: *
181: * @return boolean True if the specified field is required, False otherwise.
182: */
183: public function is_required( $field ) {
184: return ! empty( $field['required'] ) ? ' required ' : '';
185: }
186:
187: /**
188: * Gets the identifier.
189: *
190: * @param array $field The field.
191: *
192: * @return boolean The identifier.
193: */
194: public function get_id( $field ) {
195: $id = isset( $field['id'] ) ? $field['id'] : '';
196:
197: if ( empty( $id ) ) {
198: $id = isset( $field['name'] ) ? $field['name'] : '';
199: }
200:
201: return $id;
202: }
203:
204: /**
205: * Gets the name.
206: *
207: * @param array $field The field.
208: *
209: * @return string The name.
210: */
211: public function get_name( $field ) {
212: return isset( $field['name'] ) ? $field['name'] : '';
213: }
214:
215: /**
216: * Gets the decimal validation class.
217: *
218: * @param array $field The field.
219: *
220: * @return string The decimal validation class.
221: */
222: public function get_decimal_validation_class( $field = array() ) {
223: return apply_filters( 'epl_form_field_decimal_validation_class', 'validate[custom[onlyNumberWithDecimal]]', $field );
224: }
225:
226: /**
227: * Gets the number validation class.
228: *
229: * @param array $field The field.
230: *
231: * @return string The number validation class.
232: */
233: public function get_number_validation_class( $field = array() ) {
234: return apply_filters( 'epl_form_field_number_validation_class', 'validate[custom[onlyNumber]]', $field );
235: }
236:
237: /**
238: * Gets the email validation class.
239: *
240: * @param array $field The field.
241: *
242: * @return string The email validation class.
243: */
244: public function get_email_validation_class( $field = array() ) {
245: return apply_filters( 'epl_form_field_number_validation_class', 'validate[custom[email]]', $field );
246: }
247:
248: /**
249: * Gets the url validation class.
250: *
251: * @param array $field The field.
252: *
253: * @return string The The url validation class.
254: */
255: public function get_url_validation_class( $field = array() ) {
256: return apply_filters( 'epl_form_field_number_validation_class', 'validate[custom[url]]', $field );
257: }
258:
259: /**
260: * Gets the class.
261: *
262: * @param array $field The field.
263: *
264: * @return boolean The class.
265: */
266: public function get_class( $field ) {
267:
268: $classes = isset( $field['class'] ) ? $field['class'] : '';
269:
270: if ( ! is_array( $classes ) ) {
271: $classes = explode( ' ', $classes );
272: }
273: $classes = implode( ' ', array_map( 'sanitize_html_class', $classes ) );
274:
275: // Append validation classes.
276: if ( 'decimal' === $field['type'] ) {
277: $classes .= ' ' . $this->get_decimal_validation_class( $field );
278: } elseif ( 'number' === $field['type'] ) {
279: $classes .= ' ' . $this->get_number_validation_class( $field );
280: } elseif ( 'email' === $field['type'] ) {
281: $classes .= ' ' . $this->get_email_validation_class( $field );
282: } elseif ( 'url' === $field['type'] ) {
283: $classes .= ' ' . $this->get_url_validation_class( $field );
284: } elseif ( 'date' === $field['type'] ) {
285: $classes .= ' epldatepicker ';
286: }
287:
288: // Append type class.
289: $classes .= ' ' . $this->class_prefix . sanitize_text_field( $field['type'] );
290: return $classes;
291: }
292:
293: /**
294: * Gets the data attributes.
295: *
296: * @param array $field The field.
297: *
298: * @return string
299: */
300: public function get_data_attributes( $field ) {
301:
302: $atts_html = '';
303: if ( ! empty( $field['data'] ) ) {
304: foreach ( $field['data'] as $data_key => $data_value ) {
305:
306: if ( ! epl_starts_with( $data_key, 'data-' ) ) {
307: $data_key = 'data-' . $data_key;
308: }
309:
310: if ( ! is_array( $data_value ) && ! is_object( $data_value ) ) {
311: $atts_html .= $data_key . "='" . $data_value . "'";
312: } else {
313: $atts_html .= $data_key . "='" . wp_json_encode( $data_value ) . "'";
314: }
315: }
316: }
317:
318: foreach ( $field as $key => $value ) {
319:
320: if ( epl_starts_with( $key, 'data-' ) ) {
321: if ( ! is_array( $value ) && ! is_object( $value ) ) {
322: $atts_html .= $key . "='" . $value . "'";
323: } else {
324: $atts_html .= $key . "='" . wp_json_encode( $value ) . "'";
325: }
326: }
327: }
328:
329: return $atts_html;
330: }
331:
332: /**
333: * Determines whether the specified field is name array.
334: *
335: * @param array $field The field.
336: *
337: * @return boolean True if the specified field is name array, False otherwise.
338: */
339: public function is_name_array( $field ) {
340:
341: $name_arrays = apply_filters( 'epl_form_field_name_arrays', array( 'select_multiple', 'checkbox' ) );
342: return in_array( $field['type'], $name_arrays, true ) ? true : false;
343: }
344:
345: /**
346: * Gets the opening field tag.
347: *
348: * @param string $tag The tag.
349: * @param array $field The field.
350: * @param boolean $self_close The self close.
351: *
352: * @return string The opening field tag.
353: *
354: * @since 2.3.0
355: * @since 3.4.38 PHP 8.0 fix for Required parameter $field follows optional parameter $tag.
356: * @since 3.5 data attributes support for field type help.
357: */
358: public function get_opening_field_tag( $tag = 'input', $field = array(), $self_close = false ) {
359:
360: $tag = sanitize_key( $tag );
361:
362: $html = '<' . $tag . ' ';
363:
364: if ( ! empty( $field['type'] ) && ! in_array( $field['type'], array( 'select', 'select_multiple', 'textarea', 'help' ), true ) ) {
365: $html .= ' type ="' . esc_attr( $field['type'] ) . '" ';
366: $html .= ' value ="' . esc_attr( stripslashes( $field['value'] ) ) . '" ';
367: }
368:
369: if ( ! empty( $field['multiple'] ) ) {
370: $html .= esc_attr( $field['multiple'] );
371: }
372:
373: if ( ! empty( $field['min'] ) ) {
374: $html .= ' min ="' . esc_attr( $field['min'] ) . '" ';
375: }
376:
377: if ( ! empty( $field['max'] ) ) {
378: $html .= ' max ="' . esc_attr( $field['max'] ) . '" ';
379: }
380:
381: if ( ! empty( $field['maxlength'] ) ) {
382: $html .= ' maxlength ="' . esc_attr( $field['maxlength'] ) . '" ';
383: }
384:
385: if ( ! empty( $field['class'] ) ) {
386: $html .= ' class ="' . esc_attr( $field['class'] ) . '" ';
387: }
388:
389: if ( ! empty( $field['name'] ) ) {
390: $name = esc_attr( $field['name'] );
391: if ( $this->is_name_array( $field ) ) {
392: $name .= '[]';
393: }
394: $html .= ' name ="' . $name . '" ';
395: }
396:
397: if ( ! empty( $field['id'] ) ) {
398: $html .= ' id ="' . esc_attr( $field['id'] ) . '" ';
399: }
400:
401: if ( ! empty( $field['placeholder'] ) ) {
402: $html .= ' placeholder ="' . esc_attr( $field['placeholder'] ) . '" ';
403: }
404:
405: if ( ! empty( $field['autocomplete'] ) ) {
406: $html .= ' autocomplete ="' . esc_attr( $field['autocomplete'] ) . '" ';
407: }
408:
409: if ( ! empty( $field['data'] ) ) {
410: $html .= ' ' . wp_kses_post( $field['data'] );
411: }
412:
413: $html .= $self_close ? '/>' : '>';
414:
415: return $html;
416: }
417:
418: /**
419: * Renders the field based on field type
420: *
421: * @param array $field The field.
422: * @param string $val The value.
423: */
424: public function render( $field = array(), $val = '' ) {
425:
426: global $post;
427:
428: if ( ! is_null( $post ) ) {
429: $this->post = $post;
430: }
431:
432: $type = sanitize_text_field( $field['type'] );
433: $field = $this->process_field_params( $field, $val );
434: do_action( 'epl_render_field_' . $type, $field, $val );
435:
436: if ( isset( $field['geocoder'] ) ) {
437: if ( 'true' == $field['geocoder'] ) { //phpcs:ignore
438: echo '<span class="epl-geocoder-button"></span>';
439: }
440:
441: do_action( 'epl_admin_listing_map', esc_attr( stripslashes( $val ) ) );
442: }
443:
444: if ( isset( $field['help'] ) ) {
445: $field['help'] = trim( $field['help'] );
446: if ( ! empty( $field['help'] ) ) {
447: echo '<span class="epl-help-text">' . wp_kses_post( $field['help'] ) . '</span>';
448: }
449: }
450: }
451:
452: /**
453: * Renders select
454: *
455: * @param array $field The field.
456: * @param string $val The value.
457: */
458: public function select( $field, $val ) {
459:
460: if ( $this->is_multiple( $field ) ) {
461: $val = (array) $val;
462: }
463:
464: echo $this->get_opening_field_tag( 'select', $field ); //phpcs:ignore
465:
466: if ( isset( $field['opts'] ) && ! empty( $field['opts'] ) ) {
467:
468: foreach ( $field['opts'] as $k => $v ) {
469: $selected = '';
470:
471: if ( $this->is_multiple( $field ) ) {
472: if ( in_array( $k, $val ) ) { //phpcs:ignore
473: $selected = 'selected';
474: }
475: } else {
476: if ( $val == $k ) { //phpcs:ignore
477: $selected = 'selected';
478: }
479: }
480:
481: if ( is_array( $v ) ) {
482: if ( isset( $v['exclude'] ) && ! empty( $v['exclude'] ) ) {
483: if ( ! is_null( $this->post ) && in_array( $this->post->post_type, $v['exclude'], true ) ) {
484: continue;
485: }
486: }
487:
488: if ( isset( $v['include'] ) && ! empty( $v['include'] ) ) {
489: if ( ! is_null( $this->post ) && ! in_array( $this->post->post_type, $v['include'], true ) ) {
490: continue;
491: }
492: }
493: $v = $v['label'];
494: }
495:
496: echo '<option value="' . esc_attr( $k ) . '" ' . esc_attr( $selected ) . '>' . esc_html( $v ) . '</option>';
497: }
498: } else {
499: echo '<option value=""> </option>';
500: }
501: echo '</select>';
502: }
503:
504: /**
505: * Renders checkbox
506: *
507: * @param array $field The field.
508: * @param string $val The value.
509: */
510: public function checkbox( $field, $val ) {
511:
512: if ( ! empty( $field['opts'] ) ) {
513: foreach ( $field['opts'] as $k => $v ) {
514: $checked = '';
515:
516: if ( ! empty( $val ) ) {
517:
518: $val = (array) $val;
519: if ( in_array( $k, $val ) ) { //phpcs:ignore
520: $checked = 'checked';
521: }
522: }
523: echo '<span class="epl-field-row">
524: <input type="checkbox" name="' . esc_attr( $field['name'] ) . '[]"
525: ' . wp_kses_post( $field['data'] ) . '
526: class="' . esc_attr( $field['class'] ) . '"
527: id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '"
528: value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' />
529: <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label>
530: </span>';
531: }
532: }
533: }
534:
535: /**
536: * Renders checkbox single
537: *
538: * @param array $field The field.
539: * @param string $val The value.
540: *
541: * @since 3.4.34 Tweak: Added hidden empty field for checkboxes so that they always show up in $_POST data while saving.
542: */
543: public function checkbox_single( $field, $val ) {
544:
545: if ( ! empty( $field['opts'] ) ) {
546: foreach ( $field['opts'] as $k => $v ) {
547: $checked = '';
548: if ( ! empty( $val ) ) {
549: $checkbox_single_options = apply_filters( 'epl_checkbox_single_check_options', array( 1, 'yes', 'on', 'true', '1' ) );
550: if ( $k == $val || in_array( $val, $checkbox_single_options, true ) ) { //phpcs:ignore
551: $checked = 'checked';
552: }
553: }
554: if ( 1 === count( $field['opts'] ) ) {
555: $v = $field['label'];
556: }
557: echo '<span class="epl-field-row">
558: <input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="" />
559: <input type="checkbox" name="' . esc_attr( $field['name'] ) . '" class="' . esc_attr( $field['class'] ) . '" ' . wp_kses_post( $field['data'] ) . ' id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label></span>';
560: }
561: }
562: }
563:
564: /**
565: * Renders checkbox option
566: *
567: * @param array $field The field.
568: * @param string $val The value.
569: *
570: * @since 3.4.34 Tweak: Added hidden empty field for checkboxes so that they always show up in $_POST data while saving.
571: */
572: public function checkbox_option( $field, $val ) {
573:
574: if ( ! empty( $field['opts'] ) ) {
575: foreach ( $field['opts'] as $k => $v ) {
576: $checked = '';
577: if ( ! empty( $val ) ) {
578: if ( $k == $val ) { //phpcs:ignore
579: $checked = 'checked';
580: }
581: }
582: echo '<span class="epl-field-row">
583: <input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="" />
584: <input type="checkbox" name="' . esc_attr( $field['name'] ) . '" ' . wp_kses_post( $field['data'] ) . ' id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" class="' . esc_attr( $field['class'] ) . '" value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label></span>';
585: }
586: }
587: }
588:
589: /**
590: * Renders radio
591: *
592: * @param array $field The field.
593: * @param string $val The value.
594: */
595: public function radio( $field, $val ) {
596:
597: if ( ! empty( $field['opts'] ) ) {
598: foreach ( $field['opts'] as $k => $v ) {
599: $checked = '';
600: if ( $val == $k ) { //phpcs:ignore
601: $checked = 'checked';
602: }
603: echo '<span class="epl-field-row"><input type="radio" name="' . esc_attr( $field['name'] ) . '" ' . wp_kses_post( $field['data'] ) . ' class="' . esc_attr( $field['class'] ) . '" id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label></span>';
604: }
605: }
606: }
607:
608: /**
609: * Renders file / image
610: *
611: * @param array $field The field.
612: * @param string $val The value.
613: */
614: public function file( $field, $val ) {
615: if ( is_array( $val ) ) {
616: $val = isset( $val['image_url_or_path'] ) ? $val['image_url_or_path'] : '';
617: }
618:
619: if ( ! empty( $val ) ) {
620: $img = esc_attr( stripslashes( $val ) );
621: } else {
622: $img = plugin_dir_url( __DIR__ ) . 'assets/images/no_image.png'; //phpcs:ignore
623: }
624:
625: echo '
626: <div class="epl-media-row">
627: <input type="text" ' . wp_kses_post( $field['data'] ) . ' class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( stripslashes( $val ) ) . '" />
628: &nbsp;&nbsp;<input type="button" name="epl_upload_button" class="button" value="' . esc_html__( 'Add File', 'easy-property-listings' ) . '" />';
629:
630: if ( in_array( pathinfo( $img, PATHINFO_EXTENSION ), array( 'jpg', 'jpeg', 'png', 'gif' ), true ) ) {
631: echo '&nbsp;&nbsp;<img src="' . esc_url( $img ) . '" alt="" />';
632: }
633: echo '<div class="epl-clear"></div>
634: </div>
635: ';
636: }
637:
638: /**
639: * Renders editor
640: *
641: * @param array $field The field.
642: * @param string $val The value.
643: */
644: public function editor( $field, $val ) {
645: wp_editor(
646: stripslashes( $val ),
647: esc_attr( $field['id'] ),
648: $settings = array(
649: 'textarea_rows' => 5,
650: 'editor_class' => $field['class'],
651: )
652: );
653: }
654:
655: /**
656: * Renders textarea
657: *
658: * @param array $field The field.
659: * @param string $val The value.
660: */
661: public function textarea( $field, $val ) {
662: echo $this->get_opening_field_tag( 'textarea', $field ); //phpcs:ignore
663: echo wp_kses_post( stripslashes( $val ) );
664: echo '</textarea>';
665: }
666:
667: /**
668: * Renders textarea_html
669: *
670: * @param array $field The field.
671: * @param string $val The value.
672: *
673: * @since 3.4.48
674: */
675: public function textarea_html( $field, $val ) {
676: echo $this->get_opening_field_tag( 'textarea', $field ); //phpcs:ignore
677: echo esc_textarea( $val );
678: echo '</textarea>';
679: }
680:
681: /**
682: * Renders locked
683: *
684: * @param array $field The field.
685: * @param string $val The value.
686: */
687: public function locked( $field, $val ) {
688: echo '<span>' . esc_attr( stripslashes( $field['value'] ) ) . '</span>';
689: }
690:
691: /**
692: * Renders help
693: *
694: * @param array $field The field.
695: * @param string $val The value.
696: *
697: * @since 3.4.48 Added escaping on id.
698: */
699: public function help( $field, $val ) {
700:
701: $content = isset( $field['content'] ) ? $field['content'] : '';
702: $help_id = isset( $field['name'] ) ? sanitize_key( $field['name'] ) : '';
703: echo '<div class="epl-help-container">';
704: echo $this->get_opening_field_tag( 'div', $field ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Attributes are escaped in get_opening_field_tag().
705: echo wp_kses_post( $content );
706: echo '</div></div>';
707: }
708:
709: /**
710: * Renders html
711: *
712: * @param array $field The field.
713: * @param string $val The value.
714: *
715: * @since 3.4.48 Added escaping on id.
716: */
717: public function html( $field, $val ) {
718:
719: $content = isset( $field['content'] ) ? $field['content'] : '';
720: $help_id = isset( $field['name'] ) ? sanitize_key( $field['name'] ) : '';
721: //phpcs:ignore
722: echo '<div class="epl-html-container" id="' . esc_attr( $help_id ) . '">
723: ' . wp_kses_post( $content ) . '
724: </div>';
725: }
726:
727: /**
728: * Renders default input types
729: *
730: * @param array $field The field.
731: * @param string $val The value.
732: * @since 3.4.35 fixed hidden field rendering.
733: */
734: public function render_default( $field, $val ) {
735:
736: if ( ! in_array( $field['type'], array( 'button', 'number', 'color', 'submit' ), true ) ) {
737: $field['type'] = 'text';
738: }
739: echo $this->get_opening_field_tag( 'input', $field, true ); //phpcs:ignore
740: }
741: }
742: