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