PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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
← All changes | classes/models/FrmEntryFormatter.php +93 -152 6.326.8 View file →
@@ -8,24 +8,21 @@
8 8 */
9 9 class FrmEntryFormatter {
10 10
11 11 /**
12 + * @var stdClass
12 13 * @since 2.04
13 - *
14 - * @var false|stdClass|null
15 14 */
16 - protected $entry;
15 + protected $entry = null;
17 16
18 17 /**
19 - * @var FrmEntryValues|null
20 - *
18 + * @var FrmEntryValues
21 19 * @since 2.04
22 20 */
23 - protected $entry_values;
21 + protected $entry_values = null;
24 22
25 23 /**
26 24 * @var bool
27 - *
28 25 * @since 2.04
29 26 */
30 27 protected $is_plain_text = false;
31 28
@@ -30,9 +27,8 @@
30 27 protected $is_plain_text = false;
31 28
32 29 /**
33 30 * @var bool
34 - *
35 31 * @since 2.04
36 32 */
37 33 protected $include_user_info = false;
38 34
@@ -37,9 +33,8 @@
37 33 protected $include_user_info = false;
38 34
39 35 /**
40 36 * @var bool
41 - *
42 37 * @since 2.04
43 38 */
44 39 protected $include_blank = false;
45 40
@@ -44,9 +39,8 @@
44 39 protected $include_blank = false;
45 40
46 41 /**
47 42 * @var string
48 - *
49 43 * @since 2.04
50 44 */
51 45 protected $format = 'text';
52 46
@@ -51,9 +45,8 @@
51 45 protected $format = 'text';
52 46
53 47 /**
54 48 * @var string
55 - *
56 49 * @since 2.05
57 50 */
58 51 protected $array_key = 'key';
59 52
@@ -58,23 +51,20 @@
58 51 protected $array_key = 'key';
59 52
60 53 /**
61 54 * @var string
62 - *
63 55 * @since 2.04
64 56 */
65 57 protected $direction = 'ltr';
66 58
67 59 /**
68 - * @var FrmTableHTMLGenerator|null
69 - *
60 + * @var FrmTableHTMLGenerator
70 61 * @since 2.04
71 62 */
72 - protected $table_generator;
63 + protected $table_generator = null;
73 64
74 65 /**
75 66 * @var bool
76 - *
77 67 * @since 2.04
78 68 */
79 69 protected $is_clickable = false;
80 70
@@ -79,9 +69,8 @@
79 69 protected $is_clickable = false;
80 70
81 71 /**
82 72 * @var array
83 - *
84 73 * @since 2.04
85 74 */
86 75 protected $include_extras = array();
87 76
@@ -86,9 +75,8 @@
86 75 protected $include_extras = array();
87 76
88 77 /**
89 78 * @var array
90 - *
91 79 * @since 3.0
92 80 */
93 81 protected $single_cell_fields = array();
94 82
@@ -93,9 +81,8 @@
93 81 protected $single_cell_fields = array();
94 82
95 83 /**
96 84 * @var array
97 - *
98 85 * @since 3.0
99 86 */
100 87 protected $atts = array();
101 88
@@ -136,14 +123,17 @@
136 123 *
137 124 * @since 2.04
138 125 *
139 126 * @param array $atts
140 - *
141 - * @return void
142 127 */
143 128 protected function init_entry( $atts ) {
144 129 if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) ) {
145 - $this->entry = isset( $atts['entry']->metas ) ? $atts['entry'] : FrmEntry::getOne( $atts['entry']->id, true );
130 +
131 + if ( isset( $atts['entry']->metas ) ) {
132 + $this->entry = $atts['entry'];
133 + } else {
134 + $this->entry = FrmEntry::getOne( $atts['entry']->id, true );
135 + }
146 136 } elseif ( ! empty( $atts['id'] ) ) {
147 137 $this->entry = FrmEntry::getOne( $atts['id'], true );
148 138 }
149 139 }
@@ -153,10 +143,8 @@
153 143 *
154 144 * @since 2.04
155 145 *
156 146 * @param array $atts
157 - *
158 - * @return void
159 147 */
160 148 protected function init_entry_values( $atts ) {
161 149 $entry_atts = $this->prepare_entry_attributes( $atts );
162 150 $this->entry_values = new FrmEntryValues( $this->entry->id, $entry_atts );
@@ -171,11 +159,11 @@
171 159 *
172 160 * @return array
173 161 */
174 162 protected function prepare_entry_attributes( $atts ) {
175 - $entry_atts = array();
163 + $entry_atts = array();
164 +
176 165 $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields', 'entry' );
177 -
178 166 foreach ( $conditionally_add as $index ) {
179 167 if ( isset( $atts[ $index ] ) ) {
180 168 $entry_atts[ $index ] = $atts[ $index ];
181 169 }
@@ -189,18 +177,25 @@
189 177 *
190 178 * @since 2.04
191 179 *
192 180 * @param array $atts
193 - *
194 - * @return void
195 181 */
196 182 protected function init_format( $atts ) {
197 183 if ( $atts['format'] === 'array' ) {
184 +
198 185 $this->format = 'array';
186 +
199 187 } elseif ( $atts['format'] === 'json' ) {
188 +
200 189 $this->format = 'json';
190 +
201 191 } elseif ( $atts['format'] === 'text' ) {
202 - $this->format = $this->is_plain_text === true ? 'plain_text_block' : 'table';
192 +
193 + if ( $this->is_plain_text === true ) {
194 + $this->format = 'plain_text_block';
195 + } else {
196 + $this->format = 'table';
197 + }
203 198 }
204 199
205 200 /**
206 201 * Allows modifying the format property of FrmEntryFormatter object.
@@ -226,13 +221,11 @@
226 221 *
227 222 * @since 2.05
228 223 *
229 224 * @param array $atts
230 - *
231 - * @return void
232 225 */
233 226 protected function init_array_key( $atts ) {
234 - if ( isset( $atts['array_key'] ) && $atts['array_key'] === 'id' ) {
227 + if ( isset( $atts['array_key'] ) && $atts['array_key'] == 'id' ) {
235 228 $this->array_key = 'id';
236 229 }
237 230 }
238 231
@@ -241,13 +234,11 @@
241 234 *
242 235 * @since 2.04
243 236 *
244 237 * @param array $atts
245 - *
246 - * @return void
247 238 */
248 239 protected function init_is_plain_text( $atts ) {
249 - if ( ! empty( $atts['plain_text'] ) ) {
240 + if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) {
250 241 $this->is_plain_text = true;
251 242 } elseif ( $atts['format'] !== 'text' ) {
252 243 $this->is_plain_text = true;
253 244 }
@@ -258,13 +249,11 @@
258 249 *
259 250 * @since 2.04
260 251 *
261 252 * @param array $atts
262 - *
263 - * @return void
264 253 */
265 254 protected function init_include_blank( $atts ) {
266 - if ( ! empty( $atts['include_blank'] ) ) {
255 + if ( isset( $atts['include_blank'] ) && $atts['include_blank'] ) {
267 256 $this->include_blank = true;
268 257 }
269 258 }
270 259
@@ -273,10 +262,8 @@
273 262 *
274 263 * @since 2.04
275 264 *
276 265 * @param array $atts
277 - *
278 - * @return void
279 266 */
280 267 protected function init_direction( $atts ) {
281 268 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
282 269 $this->direction = 'rtl';
@@ -288,13 +275,11 @@
288 275 *
289 276 * @since 2.04
290 277 *
291 278 * @param array $atts
292 - *
293 - * @return void
294 279 */
295 280 protected function init_include_user_info( $atts ) {
296 - if ( ! empty( $atts['user_info'] ) ) {
281 + if ( isset( $atts['user_info'] ) && $atts['user_info'] ) {
297 282 $this->include_user_info = true;
298 283 }
299 284 }
300 285
@@ -301,13 +286,11 @@
301 286 /**
302 287 * Which fields to skip by default
303 288 *
304 289 * @since 3.0
305 - *
306 - * @return array
307 290 */
308 291 protected function skip_fields() {
309 - return array( 'captcha', 'html', FrmSubmitHelper::FIELD_TYPE );
292 + return array( 'captcha', 'html' );
310 293 }
311 294
312 295 /**
313 296 * Set the include_extras property
@@ -314,13 +297,11 @@
314 297 *
315 298 * @since 3.0
316 299 *
317 300 * @param array $atts
318 - *
319 - * @return void
320 301 */
321 302 protected function init_include_extras( $atts ) {
322 - if ( ! empty( $atts['include_extras'] ) ) {
303 + if ( isset( $atts['include_extras'] ) && $atts['include_extras'] ) {
323 304 $this->include_extras = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['include_extras'] ) ) );
324 305 }
325 306 }
326 307
@@ -327,10 +308,8 @@
327 308 /**
328 309 * Initialize the single_cell_fields property
329 310 *
330 311 * @since 3.0
331 - *
332 - * @return void
333 312 */
334 313 protected function init_single_cell_fields() {
335 314 $this->single_cell_fields = array( 'html' );
336 315 }
@@ -340,10 +319,8 @@
340 319 *
341 320 * @since 2.04
342 321 *
343 322 * @param array $atts
344 - *
345 - * @return void
346 323 */
347 324 protected function init_table_generator( $atts ) {
348 325 $this->table_generator = new FrmTableHTMLGenerator( 'entry', $atts );
349 326 }
@@ -353,13 +330,11 @@
353 330 *
354 331 * @since 2.04
355 332 *
356 333 * @param array $atts
357 - *
358 - * @return void
359 334 */
360 335 protected function init_is_clickable( $atts ) {
361 - if ( ! empty( $atts['clickable'] ) ) {
336 + if ( isset( $atts['clickable'] ) && $atts['clickable'] ) {
362 337 $this->is_clickable = true;
363 338 }
364 339 }
365 340
@@ -367,12 +342,8 @@
367 342 * Save the passed atts for other calls. Exclude some attributes to prevent
368 343 * interaction with processing field values like time format.
369 344 *
370 345 * @since 3.0
371 - *
372 - * @param array $atts
373 - *
374 - * @return void
375 346 */
376 347 protected function init_atts( $atts ) {
377 348 $atts['source'] = 'entry_formatter';
378 349 $atts['wpautop'] = false;
@@ -378,9 +349,8 @@
378 349 $atts['wpautop'] = false;
379 350 $atts['return_array'] = true;
380 351
381 352 $unset = array( 'id', 'form_id', 'format' );
382 -
383 353 foreach ( $unset as $param ) {
384 354 if ( isset( $atts[ $param ] ) ) {
385 355 unset( $atts[ $param ] );
386 356 }
@@ -396,12 +366,12 @@
396 366 * @since 2.05
397 367 *
398 368 * @param FrmFieldValue $field_value
399 369 *
400 - * @return int|string
370 + * @return string|int
401 371 */
402 372 protected function get_key_or_id( $field_value ) {
403 - return $this->array_key === 'key' ? $field_value->get_field_key() : $field_value->get_field_id();
373 + return $this->array_key == 'key' ? $field_value->get_field_key() : $field_value->get_field_id();
404 374 }
405 375
406 376 /**
407 377 * Package and return the formatted entry values
@@ -416,14 +386,18 @@
416 386 }
417 387
418 388 if ( $this->format === 'json' ) {
419 389 $content = json_encode( $this->prepare_array() );
390 +
420 391 } elseif ( $this->format === 'array' ) {
421 392 $content = $this->prepare_array();
393 +
422 394 } elseif ( $this->format === 'table' ) {
423 395 $content = $this->prepare_html_table();
396 +
424 397 } elseif ( $this->format === 'plain_text_block' ) {
425 398 $content = $this->prepare_plain_text_block();
399 +
426 400 } else {
427 401 $content = '';
428 402 }
429 403
@@ -461,9 +435,13 @@
461 435 $this->add_user_info_to_html_table( $content );
462 436
463 437 $content .= $this->table_generator->generate_table_footer();
464 438
465 - return $this->is_clickable ? make_clickable( $content ) : $content;
439 + if ( $this->is_clickable ) {
440 + $content = make_clickable( $content );
441 + }
442 +
443 + return $content;
466 444 }
467 445
468 446 /**
469 447 * Add field values to table or plain text content
@@ -470,13 +448,12 @@
470 448 *
471 449 * @since 2.05
472 450 *
473 451 * @param string $content
474 - *
475 - * @return void
476 452 */
477 453 protected function add_field_values_to_content( &$content ) {
478 - foreach ( $this->entry_values->get_field_values() as $field_value ) {
454 + foreach ( $this->entry_values->get_field_values() as $field_id => $field_value ) {
455 +
479 456 /**
480 457 * @var FrmFieldValue $field_value
481 458 */
482 459 $field_value->prepare_displayed_value( $this->atts );
@@ -521,10 +498,8 @@
521 498 * @since 2.04
522 499 *
523 500 * @param array $field_values
524 501 * @param array $output
525 - *
526 - * @return void
527 502 */
528 503 protected function push_field_values_to_array( $field_values, &$output ) {
529 504 foreach ( $field_values as $field_value ) {
530 505 /**
@@ -541,22 +516,20 @@
541 516 * @since 2.04
542 517 *
543 518 * @param FrmFieldValue $field_value
544 519 * @param array $output
545 - *
546 - * @return void
547 520 */
548 521 protected function push_single_field_to_array( $field_value, &$output ) {
549 - if ( ! $this->include_field_in_content( $field_value ) ) {
550 - return;
551 - }
522 + if ( $this->include_field_in_content( $field_value ) ) {
552 523
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' );
524 + $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() );
556 525
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();
526 + $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value;
527 +
528 + $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' );
529 + if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) {
530 + $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value();
531 + }
559 532 }
560 533 }
561 534
562 535 /**
@@ -566,15 +539,13 @@
566 539 *
567 540 * @param string $label
568 541 * @param mixed $display_value
569 542 * @param string $content
570 - *
571 - * @return void
572 543 */
573 544 protected function add_plain_text_row( $label, $display_value, &$content ) {
574 545 $display_value = $this->prepare_display_value_for_plain_text_content( $display_value );
575 546
576 - if ( 'rtl' === $this->direction ) {
547 + if ( 'rtl' == $this->direction ) {
577 548 $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n";
578 549 } else {
579 550 $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n";
580 551 }
@@ -586,14 +557,13 @@
586 557 * @since 2.04
587 558 *
588 559 * @param FrmFieldValue $field_value
589 560 * @param string $content
590 - *
591 - * @return void
592 561 */
593 562 protected function add_field_value_to_content( $field_value, &$content ) {
594 563 if ( $this->is_extra_field( $field_value ) ) {
595 564 $this->add_row_for_extra_field( $field_value, $content );
565 +
596 566 } else {
597 567 $this->add_row_for_standard_field( $field_value, $content );
598 568 }
599 569 }
@@ -604,10 +574,8 @@
604 574 * @since 3.0
605 575 *
606 576 * @param FrmFieldValue $field_value
607 577 * @param string $content
608 - *
609 - * @return void
610 578 */
611 579 protected function add_row_for_extra_field( $field_value, &$content ) {
612 580 if ( ! $this->include_field_in_content( $field_value ) ) {
613 581 return;
@@ -626,10 +594,8 @@
626 594 * @since 3.0
627 595 *
628 596 * @param FrmFieldValue $field_value
629 597 * @param string $content
630 - *
631 - * @return void
632 598 */
633 599 protected function add_row_for_standard_field( $field_value, &$content ) {
634 600 if ( ! $this->include_field_in_content( $field_value ) ) {
635 601 return;
@@ -649,15 +615,13 @@
649 615 * @since 3.0
650 616 *
651 617 * @param FrmFieldValue $field_value
652 618 * @param string $content
653 - *
654 - * @return void
655 619 */
656 620 protected function add_html_row_for_included_extra( $field_value, &$content ) {
657 621 $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value );
658 622
659 - if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) {
623 + if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) {
660 624 $this->add_single_cell_html_row( $display_value, $content );
661 625 } else {
662 626 $value_args = $this->package_value_args( $field_value );
663 627 $this->add_html_row( $value_args, $content );
@@ -670,15 +634,13 @@
670 634 * @since 3.0
671 635 *
672 636 * @param FrmFieldValue $field_value
673 637 * @param string $content
674 - *
675 - * @return void
676 638 */
677 639 protected function add_plain_text_row_for_included_extra( $field_value, &$content ) {
678 640 $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value );
679 641
680 - if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) {
642 + if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) {
681 643 $this->add_single_value_plain_text_row( $display_value, $content );
682 644 } else {
683 645 $this->add_plain_text_row( $field_value->get_field_label(), $display_value, $content );
684 646 }
@@ -690,10 +652,8 @@
690 652 * @since 3.0
691 653 *
692 654 * @param string $display_value
693 655 * @param string $content
694 - *
695 - * @return void
696 656 */
697 657 protected function add_single_cell_html_row( $display_value, &$content ) {
698 658 // TODO: maybe move to FrmFieldValue
699 659 $display_value = $this->prepare_display_value_for_html_table( $display_value );
@@ -707,10 +667,8 @@
707 667 * @since 3.0
708 668 *
709 669 * @param string $display_value
710 670 * @param string $content
711 - *
712 - * @return void
713 671 */
714 672 protected function add_single_value_plain_text_row( $display_value, &$content ) {
715 673 $content .= $this->prepare_display_value_for_plain_text_content( $display_value );
716 674 }
@@ -721,10 +679,8 @@
721 679 * @since 3.0
722 680 *
723 681 * @param FrmFieldValue $field_value
724 682 * @param mixed $display_value
725 - *
726 - * @return void
727 683 */
728 684 protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) {
729 685 $display_value = $field_value->get_displayed_value();
730 686 }
@@ -735,10 +691,8 @@
735 691 * @since 3.0
736 692 *
737 693 * @param FrmFieldValue $field_value
738 694 * @param mixed $display_value
739 - *
740 - * @return void
741 695 */
742 696 protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) {
743 697 $display_value = $field_value->get_displayed_value() . "\r\n";
744 698 }
@@ -749,10 +703,8 @@
749 703 * @since 2.04
750 704 *
751 705 * @param FrmFieldValue $field_value
752 706 * @param string $content
753 - *
754 - * @return void
755 707 */
756 708 protected function add_standard_row( $field_value, &$content ) {
757 709 if ( $this->format === 'plain_text_block' ) {
758 710 $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content );
@@ -784,24 +736,22 @@
784 736 *
785 737 * @since 2.04
786 738 *
787 739 * @param string $content
788 - *
789 - * @return void
790 740 */
791 741 protected function add_user_info_to_html_table( &$content ) {
792 - if ( ! $this->include_user_info ) {
793 - return;
794 - }
742 + if ( $this->include_user_info ) {
795 743
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 - );
744 + foreach ( $this->entry_values->get_user_info() as $user_info ) {
802 745
803 - $this->add_html_row( $value_args, $content );
746 + $value_args = array(
747 + 'label' => $user_info['label'],
748 + 'value' => $user_info['value'],
749 + 'field_type' => 'none',
750 + );
751 +
752 + $this->add_html_row( $value_args, $content );
753 + }
804 754 }
805 755 }
806 756
807 757 /**
@@ -809,18 +759,15 @@
809 759 *
810 760 * @since 2.04
811 761 *
812 762 * @param string $content
813 - *
814 - * @return void
815 763 */
816 764 protected function add_user_info_to_plain_text_content( &$content ) {
817 - if ( ! $this->include_user_info ) {
818 - return;
819 - }
765 + if ( $this->include_user_info ) {
820 766
821 - foreach ( $this->entry_values->get_user_info() as $user_info ) {
822 - $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content );
767 + foreach ( $this->entry_values->get_user_info() as $user_info ) {
768 + $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content );
769 + }
823 770 }
824 771 }
825 772
826 773 /**
@@ -853,9 +800,9 @@
853 800 *
854 801 * @return bool
855 802 */
856 803 protected function is_extra_field( $field_value ) {
857 - return in_array( $field_value->get_field_type(), $this->skip_fields(), true );
804 + return in_array( $field_value->get_field_type(), $this->skip_fields() );
858 805 }
859 806
860 807 /**
861 808 * Check if an extra field is included
@@ -866,9 +813,9 @@
866 813 *
867 814 * @return bool
868 815 */
869 816 protected function is_extra_field_included( $field_value ) {
870 - return in_array( $field_value->get_field_type(), $this->include_extras, true );
817 + return in_array( $field_value->get_field_type(), $this->include_extras );
871 818 }
872 819
873 820 /**
874 821 * Add a row in an HTML table
@@ -881,19 +828,13 @@
881 828 * 'value' => (mixed) The value to add. Required
882 829 * 'field_type' => (string) The field type. Blank string if not a field.
883 830 * ]
884 831 * @param string $content
885 - *
886 - * @return void
887 832 */
888 833 protected function add_html_row( $value_args, &$content ) {
889 834 $display_value = $this->prepare_display_value_for_html_table( $value_args['value'], $value_args['field_type'] );
890 835
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 - );
836 + $content .= $this->table_generator->generate_two_cell_table_row( $value_args['label'], $display_value );
896 837 }
897 838
898 839 /**
899 840 * Prepare the displayed value for an array
@@ -919,11 +860,10 @@
919 860 * @return mixed|string
920 861 */
921 862 protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) {
922 863 $display_value = $this->flatten_array( $display_value );
923 -
924 864 if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) {
925 - return str_replace( array( "\r\n", "\n" ), '<br/>', $display_value );
865 + $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value );
926 866 }
927 867
928 868 return $display_value;
929 869 }
@@ -934,13 +874,15 @@
934 874 * @since 2.04
935 875 *
936 876 * @param mixed $display_value
937 877 *
938 - * @return int|string
878 + * @return string|int
939 879 */
940 880 protected function prepare_display_value_for_plain_text_content( $display_value ) {
941 881 $display_value = $this->flatten_array( $display_value );
942 - return $this->strip_html( $display_value );
882 + $display_value = $this->strip_html( $display_value );
883 +
884 + return $display_value;
943 885 }
944 886
945 887 /**
946 888 * Flatten an array
@@ -946,15 +888,15 @@
946 888 * Flatten an array
947 889 *
948 890 * @since 2.04
949 891 *
950 - * @param array|int|string $value
892 + * @param array|string|int $value
951 893 *
952 - * @return int|string
894 + * @return string|int
953 895 */
954 896 protected function flatten_array( $value ) {
955 897 if ( is_array( $value ) ) {
956 - $separator = $this->atts['array_separator'] ?? ', ';
898 + $separator = isset( $this->atts['array_separator'] ) ? $this->atts['array_separator'] : ', ';
957 899 $value = implode( $separator, $value );
958 900 }
959 901
960 902 return $value;
@@ -969,23 +911,22 @@
969 911 *
970 912 * @return mixed
971 913 */
972 914 protected function strip_html( $value ) {
973 - if ( ! $this->is_plain_text ) {
974 - return $value;
975 - }
976 915
977 - if ( is_array( $value ) ) {
978 - foreach ( $value as $key => $single_value ) {
979 - $value[ $key ] = $this->strip_html( $single_value );
916 + if ( $this->is_plain_text ) {
917 +
918 + if ( is_array( $value ) ) {
919 + foreach ( $value as $key => $single_value ) {
920 + $value[ $key ] = $this->strip_html( $single_value );
921 + }
922 + } elseif ( $this->is_plain_text && ! is_array( $value ) ) {
923 + if ( strpos( $value, '<img' ) !== false ) {
924 + $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value );
925 + $value = trim( $value );
926 + }
927 + $value = strip_tags( $value );
980 928 }
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 929 }
989 930
990 931 return $value;
991 932 }