PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.33.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.33.1
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / FrmEntryFormatter.php

FrmEntryFormatter.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.33.1, at classes/models/FrmEntryFormatter.php

993 lines 21.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * @since 2.04
8 */
9 class FrmEntryFormatter {
10
11 /**
12 * @since 2.04
13 *
14 * @var false|stdClass|null
15 */
16 protected $entry;
17
18 /**
19 * @var FrmEntryValues|null
20 *
21 * @since 2.04
22 */
23 protected $entry_values;
24
25 /**
26 * @var bool
27 *
28 * @since 2.04
29 */
30 protected $is_plain_text = false;
31
32 /**
33 * @var bool
34 *
35 * @since 2.04
36 */
37 protected $include_user_info = false;
38
39 /**
40 * @var bool
41 *
42 * @since 2.04
43 */
44 protected $include_blank = false;
45
46 /**
47 * @var string
48 *
49 * @since 2.04
50 */
51 protected $format = 'text';
52
53 /**
54 * @var string
55 *
56 * @since 2.05
57 */
58 protected $array_key = 'key';
59
60 /**
61 * @var string
62 *
63 * @since 2.04
64 */
65 protected $direction = 'ltr';
66
67 /**
68 * @var FrmTableHTMLGenerator|null
69 *
70 * @since 2.04
71 */
72 protected $table_generator;
73
74 /**
75 * @var bool
76 *
77 * @since 2.04
78 */
79 protected $is_clickable = false;
80
81 /**
82 * @var array
83 *
84 * @since 2.04
85 */
86 protected $include_extras = array();
87
88 /**
89 * @var array
90 *
91 * @since 3.0
92 */
93 protected $single_cell_fields = array();
94
95 /**
96 * @var array
97 *
98 * @since 3.0
99 */
100 protected $atts = array();
101
102 /**
103 * FrmEntryFormat constructor
104 *
105 * @since 2.04
106 *
107 * @param array $atts
108 */
109 public function __construct( $atts ) {
110 $this->init_entry( $atts );
111
112 if ( $this->entry === null || $this->entry === false ) {
113 return;
114 }
115
116 $this->init_is_plain_text( $atts );
117 $this->init_format( $atts );
118 $this->init_array_key( $atts );
119 $this->init_include_blank( $atts );
120 $this->init_direction( $atts );
121 $this->init_include_user_info( $atts );
122 $this->init_include_extras( $atts );
123 $this->init_single_cell_fields();
124 $this->init_entry_values( $atts );
125
126 if ( $this->format === 'table' ) {
127 $this->init_table_generator( $atts );
128 $this->init_is_clickable( $atts );
129 }
130
131 $this->init_atts( $atts );
132 }
133
134 /**
135 * Set the entry property
136 *
137 * @since 2.04
138 *
139 * @param array $atts
140 *
141 * @return void
142 */
143 protected function init_entry( $atts ) {
144 if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) ) {
145 $this->entry = isset( $atts['entry']->metas ) ? $atts['entry'] : FrmEntry::getOne( $atts['entry']->id, true );
146 } elseif ( ! empty( $atts['id'] ) ) {
147 $this->entry = FrmEntry::getOne( $atts['id'], true );
148 }
149 }
150
151 /**
152 * Set the entry values property
153 *
154 * @since 2.04
155 *
156 * @param array $atts
157 *
158 * @return void
159 */
160 protected function init_entry_values( $atts ) {
161 $entry_atts = $this->prepare_entry_attributes( $atts );
162 $this->entry_values = new FrmEntryValues( $this->entry->id, $entry_atts );
163 }
164
165 /**
166 * Prepare attributes array for FrmEntryValues constructor
167 *
168 * @since 2.05
169 *
170 * @param array $atts
171 *
172 * @return array
173 */
174 protected function prepare_entry_attributes( $atts ) {
175 $entry_atts = array();
176 $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields', 'entry' );
177
178 foreach ( $conditionally_add as $index ) {
179 if ( isset( $atts[ $index ] ) ) {
180 $entry_atts[ $index ] = $atts[ $index ];
181 }
182 }
183
184 return $entry_atts;
185 }
186
187 /**
188 * Set the format property
189 *
190 * @since 2.04
191 *
192 * @param array $atts
193 *
194 * @return void
195 */
196 protected function init_format( $atts ) {
197 if ( $atts['format'] === 'array' ) {
198 $this->format = 'array';
199 } elseif ( $atts['format'] === 'json' ) {
200 $this->format = 'json';
201 } elseif ( $atts['format'] === 'text' ) {
202 $this->format = $this->is_plain_text === true ? 'plain_text_block' : 'table';
203 }
204
205 /**
206 * Allows modifying the format property of FrmEntryFormatter object.
207 *
208 * @since 5.0.16
209 *
210 * @param string $format The format.
211 * @param array $args Includes `atts`, `entry`.
212 */
213 $this->format = apply_filters(
214 'frm_entry_formatter_format',
215 $this->format,
216 array(
217 'atts' => $atts,
218 'entry' => $this->entry,
219 )
220 );
221 }
222
223 /**
224 * Set the array_key property that sets whether the keys in the
225 * returned array are field keys or ids
226 *
227 * @since 2.05
228 *
229 * @param array $atts
230 *
231 * @return void
232 */
233 protected function init_array_key( $atts ) {
234 if ( isset( $atts['array_key'] ) && $atts['array_key'] === 'id' ) {
235 $this->array_key = 'id';
236 }
237 }
238
239 /**
240 * Set the is_plain_text property
241 *
242 * @since 2.04
243 *
244 * @param array $atts
245 *
246 * @return void
247 */
248 protected function init_is_plain_text( $atts ) {
249 if ( ! empty( $atts['plain_text'] ) ) {
250 $this->is_plain_text = true;
251 } elseif ( $atts['format'] !== 'text' ) {
252 $this->is_plain_text = true;
253 }
254 }
255
256 /**
257 * Set the include_blank property
258 *
259 * @since 2.04
260 *
261 * @param array $atts
262 *
263 * @return void
264 */
265 protected function init_include_blank( $atts ) {
266 if ( ! empty( $atts['include_blank'] ) ) {
267 $this->include_blank = true;
268 }
269 }
270
271 /**
272 * Set the direction property
273 *
274 * @since 2.04
275 *
276 * @param array $atts
277 *
278 * @return void
279 */
280 protected function init_direction( $atts ) {
281 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
282 $this->direction = 'rtl';
283 }
284 }
285
286 /**
287 * Set the include_user_info property
288 *
289 * @since 2.04
290 *
291 * @param array $atts
292 *
293 * @return void
294 */
295 protected function init_include_user_info( $atts ) {
296 if ( ! empty( $atts['user_info'] ) ) {
297 $this->include_user_info = true;
298 }
299 }
300
301 /**
302 * Which fields to skip by default
303 *
304 * @since 3.0
305 *
306 * @return array
307 */
308 protected function skip_fields() {
309 return array( 'captcha', 'html', FrmSubmitHelper::FIELD_TYPE );
310 }
311
312 /**
313 * Set the include_extras property
314 *
315 * @since 3.0
316 *
317 * @param array $atts
318 *
319 * @return void
320 */
321 protected function init_include_extras( $atts ) {
322 if ( ! empty( $atts['include_extras'] ) ) {
323 $this->include_extras = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['include_extras'] ) ) );
324 }
325 }
326
327 /**
328 * Initialize the single_cell_fields property
329 *
330 * @since 3.0
331 *
332 * @return void
333 */
334 protected function init_single_cell_fields() {
335 $this->single_cell_fields = array( 'html' );
336 }
337
338 /**
339 * Set the table_generator property
340 *
341 * @since 2.04
342 *
343 * @param array $atts
344 *
345 * @return void
346 */
347 protected function init_table_generator( $atts ) {
348 $this->table_generator = new FrmTableHTMLGenerator( 'entry', $atts );
349 }
350
351 /**
352 * Set the is_clickable property
353 *
354 * @since 2.04
355 *
356 * @param array $atts
357 *
358 * @return void
359 */
360 protected function init_is_clickable( $atts ) {
361 if ( ! empty( $atts['clickable'] ) ) {
362 $this->is_clickable = true;
363 }
364 }
365
366 /**
367 * Save the passed atts for other calls. Exclude some attributes to prevent
368 * interaction with processing field values like time format.
369 *
370 * @since 3.0
371 *
372 * @param array $atts
373 *
374 * @return void
375 */
376 protected function init_atts( $atts ) {
377 $atts['source'] = 'entry_formatter';
378 $atts['wpautop'] = false;
379 $atts['return_array'] = true;
380
381 $unset = array( 'id', 'form_id', 'format' );
382
383 foreach ( $unset as $param ) {
384 if ( isset( $atts[ $param ] ) ) {
385 unset( $atts[ $param ] );
386 }
387 }
388
389 $this->atts = $atts;
390 $this->atts['entry'] = $this->entry;
391 }
392
393 /**
394 * Get the field key or ID, depending on array_key property
395 *
396 * @since 2.05
397 *
398 * @param FrmFieldValue $field_value
399 *
400 * @return int|string
401 */
402 protected function get_key_or_id( $field_value ) {
403 return $this->array_key === 'key' ? $field_value->get_field_key() : $field_value->get_field_id();
404 }
405
406 /**
407 * Package and return the formatted entry values
408 *
409 * @since 2.04
410 *
411 * @return array|string
412 */
413 public function get_formatted_entry_values() {
414 if ( $this->entry === null || $this->entry === false ) {
415 return '';
416 }
417
418 if ( $this->format === 'json' ) {
419 $content = json_encode( $this->prepare_array() );
420 } elseif ( $this->format === 'array' ) {
421 $content = $this->prepare_array();
422 } elseif ( $this->format === 'table' ) {
423 $content = $this->prepare_html_table();
424 } elseif ( $this->format === 'plain_text_block' ) {
425 $content = $this->prepare_plain_text_block();
426 } else {
427 $content = '';
428 }
429
430 /**
431 * Allows modifying the formatted entry values content.
432 *
433 * @since 5.0.16
434 *
435 * @param string $content The formatted entry values content.
436 * @param array $args Includes `entry`, `atts`, `format`, `entry_values`.
437 */
438 return apply_filters(
439 'frm_formatted_entry_values_content',
440 $content,
441 array(
442 'entry' => $this->entry,
443 'atts' => $this->atts,
444 'format' => $this->format,
445 'entry_values' => $this->entry_values,
446 )
447 );
448 }
449
450 /**
451 * Return the formatted HTML table with entry values
452 *
453 * @since 2.04
454 *
455 * @return string
456 */
457 protected function prepare_html_table() {
458 $content = $this->table_generator->generate_table_header();
459
460 $this->add_field_values_to_content( $content );
461 $this->add_user_info_to_html_table( $content );
462
463 $content .= $this->table_generator->generate_table_footer();
464
465 return $this->is_clickable ? make_clickable( $content ) : $content;
466 }
467
468 /**
469 * Add field values to table or plain text content
470 *
471 * @since 2.05
472 *
473 * @param string $content
474 *
475 * @return void
476 */
477 protected function add_field_values_to_content( &$content ) {
478 foreach ( $this->entry_values->get_field_values() as $field_value ) {
479 /**
480 * @var FrmFieldValue $field_value
481 */
482 $field_value->prepare_displayed_value( $this->atts );
483 $this->add_field_value_to_content( $field_value, $content );
484 }
485 }
486
487 /**
488 * Return the formatted plain text content
489 *
490 * @since 2.04
491 *
492 * @return string
493 */
494 protected function prepare_plain_text_block() {
495 $content = '';
496
497 $this->add_field_values_to_content( $content );
498 $this->add_user_info_to_plain_text_content( $content );
499
500 return $content;
501 }
502
503 /**
504 * Prepare the array output
505 *
506 * @since 2.04
507 *
508 * @return array
509 */
510 protected function prepare_array() {
511 $array_output = array();
512
513 $this->push_field_values_to_array( $this->entry_values->get_field_values(), $array_output );
514
515 return $array_output;
516 }
517
518 /**
519 * Push field values to array content
520 *
521 * @since 2.04
522 *
523 * @param array $field_values
524 * @param array $output
525 *
526 * @return void
527 */
528 protected function push_field_values_to_array( $field_values, &$output ) {
529 foreach ( $field_values as $field_value ) {
530 /**
531 * @var FrmFieldValue $field_value
532 */
533 $field_value->prepare_displayed_value( $this->atts );
534 $this->push_single_field_to_array( $field_value, $output );
535 }
536 }
537
538 /**
539 * Push a single field to the array content
540 *
541 * @since 2.04
542 *
543 * @param FrmFieldValue $field_value
544 * @param array $output
545 *
546 * @return void
547 */
548 protected function push_single_field_to_array( $field_value, &$output ) {
549 if ( ! $this->include_field_in_content( $field_value ) ) {
550 return;
551 }
552
553 $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() );
554 $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value;
555 $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' );
556
557 if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) {
558 $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value();
559 }
560 }
561
562 /**
563 * Add a row of values to the plain text content
564 *
565 * @since 2.04
566 *
567 * @param string $label
568 * @param mixed $display_value
569 * @param string $content
570 *
571 * @return void
572 */
573 protected function add_plain_text_row( $label, $display_value, &$content ) {
574 $display_value = $this->prepare_display_value_for_plain_text_content( $display_value );
575
576 if ( 'rtl' === $this->direction ) {
577 $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n";
578 } else {
579 $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n";
580 }
581 }
582
583 /**
584 * Add a field value to the HTML table or plain text content
585 *
586 * @since 2.04
587 *
588 * @param FrmFieldValue $field_value
589 * @param string $content
590 *
591 * @return void
592 */
593 protected function add_field_value_to_content( $field_value, &$content ) {
594 if ( $this->is_extra_field( $field_value ) ) {
595 $this->add_row_for_extra_field( $field_value, $content );
596 } else {
597 $this->add_row_for_standard_field( $field_value, $content );
598 }
599 }
600
601 /**
602 * Add an extra field to plain text or html table content
603 *
604 * @since 3.0
605 *
606 * @param FrmFieldValue $field_value
607 * @param string $content
608 *
609 * @return void
610 */
611 protected function add_row_for_extra_field( $field_value, &$content ) {
612 if ( ! $this->include_field_in_content( $field_value ) ) {
613 return;
614 }
615
616 if ( $this->format === 'plain_text_block' ) {
617 $this->add_plain_text_row_for_included_extra( $field_value, $content );
618 } elseif ( $this->format === 'table' ) {
619 $this->add_html_row_for_included_extra( $field_value, $content );
620 }
621 }
622
623 /**
624 * Add a standard row to plain text or html table content
625 *
626 * @since 3.0
627 *
628 * @param FrmFieldValue $field_value
629 * @param string $content
630 *
631 * @return void
632 */
633 protected function add_row_for_standard_field( $field_value, &$content ) {
634 if ( ! $this->include_field_in_content( $field_value ) ) {
635 return;
636 }
637
638 if ( $this->format === 'plain_text_block' ) {
639 $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
640 } elseif ( $this->format === 'table' ) {
641 $value_args = $this->package_value_args( $field_value );
642 $this->add_html_row( $value_args, $content );
643 }
644 }
645
646 /**
647 * Add a row to table for included extra
648 *
649 * @since 3.0
650 *
651 * @param FrmFieldValue $field_value
652 * @param string $content
653 *
654 * @return void
655 */
656 protected function add_html_row_for_included_extra( $field_value, &$content ) {
657 $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value );
658
659 if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) {
660 $this->add_single_cell_html_row( $display_value, $content );
661 } else {
662 $value_args = $this->package_value_args( $field_value );
663 $this->add_html_row( $value_args, $content );
664 }
665 }
666
667 /**
668 * Add a plain text row for included extra
669 *
670 * @since 3.0
671 *
672 * @param FrmFieldValue $field_value
673 * @param string $content
674 *
675 * @return void
676 */
677 protected function add_plain_text_row_for_included_extra( $field_value, &$content ) {
678 $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value );
679
680 if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) {
681 $this->add_single_value_plain_text_row( $display_value, $content );
682 } else {
683 $this->add_plain_text_row( $field_value->get_field_label(), $display_value, $content );
684 }
685 }
686
687 /**
688 * Add a single cell row to an HTML table
689 *
690 * @since 3.0
691 *
692 * @param string $display_value
693 * @param string $content
694 *
695 * @return void
696 */
697 protected function add_single_cell_html_row( $display_value, &$content ) {
698 // TODO: maybe move to FrmFieldValue
699 $display_value = $this->prepare_display_value_for_html_table( $display_value );
700
701 $content .= $this->table_generator->generate_single_cell_table_row( $display_value );
702 }
703
704 /**
705 * Add a single value plain text row
706 *
707 * @since 3.0
708 *
709 * @param string $display_value
710 * @param string $content
711 *
712 * @return void
713 */
714 protected function add_single_value_plain_text_row( $display_value, &$content ) {
715 $content .= $this->prepare_display_value_for_plain_text_content( $display_value );
716 }
717
718 /**
719 * Prepare the display value for extra fields an HTML table
720 *
721 * @since 3.0
722 *
723 * @param FrmFieldValue $field_value
724 * @param mixed $display_value
725 *
726 * @return void
727 */
728 protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) {
729 $display_value = $field_value->get_displayed_value();
730 }
731
732 /**
733 * Prepare a plain text value for extra fields
734 *
735 * @since 3.0
736 *
737 * @param FrmFieldValue $field_value
738 * @param mixed $display_value
739 *
740 * @return void
741 */
742 protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) {
743 $display_value = $field_value->get_displayed_value() . "\r\n";
744 }
745
746 /**
747 * Add a standard row to plain text or html table content
748 *
749 * @since 2.04
750 *
751 * @param FrmFieldValue $field_value
752 * @param string $content
753 *
754 * @return void
755 */
756 protected function add_standard_row( $field_value, &$content ) {
757 if ( $this->format === 'plain_text_block' ) {
758 $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
759 } elseif ( $this->format === 'table' ) {
760 $value_args = $this->package_value_args( $field_value );
761 $this->add_html_row( $value_args, $content );
762 }
763 }
764
765 /**
766 * Package the value arguments for an HTML row
767 *
768 * @since 2.04
769 *
770 * @param FrmFieldValue $field_value
771 *
772 * @return array
773 */
774 protected function package_value_args( $field_value ) {
775 return array(
776 'label' => $field_value->get_field_label(),
777 'value' => $field_value->get_displayed_value(),
778 'field_type' => $field_value->get_field_type(),
779 );
780 }
781
782 /**
783 * Add user info to an HTML table
784 *
785 * @since 2.04
786 *
787 * @param string $content
788 *
789 * @return void
790 */
791 protected function add_user_info_to_html_table( &$content ) {
792 if ( ! $this->include_user_info ) {
793 return;
794 }
795
796 foreach ( $this->entry_values->get_user_info() as $user_info ) {
797 $value_args = array(
798 'label' => $user_info['label'],
799 'value' => $user_info['value'],
800 'field_type' => 'none',
801 );
802
803 $this->add_html_row( $value_args, $content );
804 }
805 }
806
807 /**
808 * Add user info to plain text content
809 *
810 * @since 2.04
811 *
812 * @param string $content
813 *
814 * @return void
815 */
816 protected function add_user_info_to_plain_text_content( &$content ) {
817 if ( ! $this->include_user_info ) {
818 return;
819 }
820
821 foreach ( $this->entry_values->get_user_info() as $user_info ) {
822 $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content );
823 }
824 }
825
826 /**
827 * Check if a field should be included in the content
828 *
829 * @since 2.04
830 *
831 * @param FrmFieldValue $field_value
832 *
833 * @return bool
834 */
835 protected function include_field_in_content( $field_value ) {
836 $include = true;
837
838 if ( $this->is_extra_field( $field_value ) ) {
839 $include = $this->is_extra_field_included( $field_value );
840 } elseif ( FrmAppHelper::is_empty_value( $field_value->get_displayed_value() ) && ! $this->include_blank ) {
841 $include = false;
842 }
843
844 return apply_filters( 'frm_include_field_in_content', $include, $field_value );
845 }
846
847 /**
848 * Check if a field is normally a skipped type
849 *
850 * @since 2.04
851 *
852 * @param FrmFieldValue $field_value
853 *
854 * @return bool
855 */
856 protected function is_extra_field( $field_value ) {
857 return in_array( $field_value->get_field_type(), $this->skip_fields(), true );
858 }
859
860 /**
861 * Check if an extra field is included
862 *
863 * @since 2.04
864 *
865 * @param FrmFieldValue $field_value
866 *
867 * @return bool
868 */
869 protected function is_extra_field_included( $field_value ) {
870 return in_array( $field_value->get_field_type(), $this->include_extras, true );
871 }
872
873 /**
874 * Add a row in an HTML table
875 *
876 * @since 2.04
877 *
878 * @param array $value_args
879 * $value_args = [
880 * 'label' => (string) The label. Required
881 * 'value' => (mixed) The value to add. Required
882 * 'field_type' => (string) The field type. Blank string if not a field.
883 * ]
884 * @param string $content
885 *
886 * @return void
887 */
888 protected function add_html_row( $value_args, &$content ) {
889 $display_value = $this->prepare_display_value_for_html_table( $value_args['value'], $value_args['field_type'] );
890
891 $content .= $this->table_generator->generate_two_cell_table_row(
892 $value_args['label'],
893 $display_value,
894 array( 'field_type' => $value_args['field_type'] )
895 );
896 }
897
898 /**
899 * Prepare the displayed value for an array
900 *
901 * @since 2.04
902 *
903 * @param mixed $value
904 *
905 * @return mixed|string
906 */
907 protected function prepare_display_value_for_array( $value ) {
908 return $this->strip_html( $value );
909 }
910
911 /**
912 * Prepare a field's display value for an HTML table
913 *
914 * @since 2.04
915 *
916 * @param mixed $display_value
917 * @param string $field_type
918 *
919 * @return mixed|string
920 */
921 protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) {
922 $display_value = $this->flatten_array( $display_value );
923
924 if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) {
925 return str_replace( array( "\r\n", "\n" ), '<br/>', $display_value );
926 }
927
928 return $display_value;
929 }
930
931 /**
932 * Prepare a field's display value for plain text content
933 *
934 * @since 2.04
935 *
936 * @param mixed $display_value
937 *
938 * @return int|string
939 */
940 protected function prepare_display_value_for_plain_text_content( $display_value ) {
941 $display_value = $this->flatten_array( $display_value );
942 return $this->strip_html( $display_value );
943 }
944
945 /**
946 * Flatten an array
947 *
948 * @since 2.04
949 *
950 * @param array|int|string $value
951 *
952 * @return int|string
953 */
954 protected function flatten_array( $value ) {
955 if ( is_array( $value ) ) {
956 $separator = $this->atts['array_separator'] ?? ', ';
957 $value = implode( $separator, $value );
958 }
959
960 return $value;
961 }
962
963 /**
964 * Strip HTML if from email value if plain text is selected
965 *
966 * @since 2.0.21
967 *
968 * @param mixed $value
969 *
970 * @return mixed
971 */
972 protected function strip_html( $value ) {
973 if ( ! $this->is_plain_text ) {
974 return $value;
975 }
976
977 if ( is_array( $value ) ) {
978 foreach ( $value as $key => $single_value ) {
979 $value[ $key ] = $this->strip_html( $single_value );
980 }
981 } elseif ( $this->is_plain_text && ! is_array( $value ) ) {
982 if ( str_contains( $value, '<img' ) ) {
983 $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value );
984 $value = trim( $value );
985 }
986
987 $value = strip_tags( $value );
988 }
989
990 return $value;
991 }
992 }
993