PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.23
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.23
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/controllers/FrmFieldsController.php +53 -121 6.276.23 View file →
@@ -18,10 +18,9 @@
18 18
19 19 // Javascript may be included in some field settings.
20 20 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
21 21 $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array();
22 -
23 - if ( ! $fields ) {
22 + if ( empty( $fields ) ) {
24 23 wp_die();
25 24 }
26 25
27 26 $_GET['page'] = 'formidable';
@@ -34,9 +33,8 @@
34 33
35 34 foreach ( $fields as $field ) {
36 35 $field = htmlspecialchars_decode( nl2br( $field ) );
37 36 $field = json_decode( $field );
38 -
39 37 if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
40 38 // this field may have already been loaded
41 39 continue;
42 40 }
@@ -49,10 +47,11 @@
49 47 $field->default_value = json_decode( json_encode( $field->default_value ), true );
50 48
51 49 ob_start();
52 50 self::load_single_field( $field, $values );
53 - $field_html[ absint( $field->id ) ] = ob_get_clean();
54 - }//end foreach
51 + $field_html[ absint( $field->id ) ] = ob_get_contents();
52 + ob_end_clean();
53 + }
55 54
56 55 echo json_encode( $field_html );
57 56
58 57 wp_die();
@@ -90,9 +89,9 @@
90 89 */
91 90 public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
92 91 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
93 92
94 - if ( $field_options ) {
93 + if ( ! empty( $field_options ) ) {
95 94 $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
96 95 }
97 96
98 97 // When a new field is added to the form, flag it as draft and hide it from the front-end.
@@ -107,15 +106,15 @@
107 106 if ( ! $field_id ) {
108 107 return false;
109 108 }
110 109
111 - $field = self::get_field_array_from_id( $field_id );
110 + $field = self::get_field_array_from_id( $field_id );
111 +
112 112 $values = array();
113 -
114 113 if ( FrmAppHelper::pro_is_installed() ) {
115 114 $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
116 - $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
117 115
116 + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
118 117 if ( $parent_form_id ) {
119 118 $field['parent_form_id'] = $parent_form_id;
120 119 }
121 120 }
@@ -128,10 +127,11 @@
128 127 public static function duplicate() {
129 128 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 129 check_ajax_referer( 'frm_ajax', 'nonce' );
131 130
132 - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
133 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
131 + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
132 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
133 +
134 134 $new_field = FrmField::duplicate_single_field( $field_id, $form_id );
135 135
136 136 if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) {
137 137 self::load_single_field( $new_field['field_id'], $new_field['values'] );
@@ -148,8 +148,9 @@
148 148 * @return array
149 149 */
150 150 public static function get_field_array_from_id( $field_id ) {
151 151 $field = FrmField::getOne( $field_id );
152 +
152 153 return FrmFieldsHelper::setup_edit_vars( $field );
153 154 }
154 155
155 156 /**
@@ -157,10 +158,8 @@
157 158 *
158 159 * @param array|int|object $field_object
159 160 * @param array $values
160 161 * @param int $form_id
161 - *
162 - * @return void
163 162 */
164 163 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
165 164 global $frm_vars;
166 165 $frm_vars['is_admin'] = true;
@@ -171,10 +170,11 @@
171 170 $field = $field_object;
172 171 $field_object = FrmField::getOne( $field['id'] );
173 172 }
174 173
175 - $field_obj = FrmFieldFactory::get_field_factory( $field_object );
176 - $display = self::display_field_options( array(), $field_obj );
174 + $field_obj = FrmFieldFactory::get_field_factory( $field_object );
175 + $display = self::display_field_options( array(), $field_obj );
176 +
177 177 $ajax_loading = ! empty( $values['ajax_load'] );
178 178 $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
179 179
180 180 if ( $ajax_loading && $ajax_this_field ) {
@@ -183,9 +183,9 @@
183 183 return;
184 184 }
185 185
186 186 if ( ! isset( $field ) && is_object( $field_object ) ) {
187 - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id;
187 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
188 188 $field = FrmFieldsHelper::setup_edit_vars( $field_object );
189 189 }
190 190
191 191 /**
@@ -210,9 +210,8 @@
210 210 *
211 211 * @param array $field
212 212 * @param array $display
213 213 * @param FrmFieldType $field_info
214 - *
215 214 * @return string
216 215 */
217 216 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
218 217 $li_classes = $field_info->form_builder_classes( $display['type'] );
@@ -260,9 +259,8 @@
260 259 *
261 260 * @since 6.8.4
262 261 *
263 262 * @param array $bulk_edit_types
264 - *
265 263 * @return array
266 264 */
267 265 $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
268 266
@@ -270,19 +268,18 @@
270 268 return;
271 269 }
272 270
273 271 $field = FrmFieldsHelper::setup_edit_vars( $field );
272 + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
273 + $opts = explode( "\n", rtrim( $opts, "\n" ) );
274 + $opts = array_map( 'trim', $opts );
274 275
275 - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
276 - $opts = explode( "\n", rtrim( $opts, "\n" ) );
277 - $opts = array_map( 'trim', $opts );
278 -
279 276 $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
280 277 $field['separate_value'] = $separate === 'true';
281 278
282 279 if ( $field['separate_value'] ) {
283 280 foreach ( $opts as $opt_key => $opt ) {
284 - if ( str_contains( $opt, '|' ) ) {
281 + if ( strpos( $opt, '|' ) !== false ) {
285 282 $vals = explode( '|', $opt );
286 283 $opts[ $opt_key ] = array(
287 284 'label' => trim( $vals[0] ),
288 285 'value' => trim( $vals[1] ),
@@ -293,12 +290,10 @@
293 290 }
294 291 }
295 292
296 293 // Keep other options after bulk update.
297 - // phpcs:ignore Universal.Operators.StrictComparisons
298 - if ( ! empty( $field['field_options']['other'] ) ) {
294 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
299 295 $other_array = array();
300 -
301 296 foreach ( $field['options'] as $opt_key => $opt ) {
302 297 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
303 298 $other_array[ $opt_key ] = $opt;
304 299 }
@@ -303,10 +298,9 @@
303 298 $other_array[ $opt_key ] = $opt;
304 299 }
305 300 unset( $opt_key, $opt );
306 301 }
307 -
308 - if ( $other_array ) {
302 + if ( ! empty( $other_array ) ) {
309 303 $opts = array_merge( $opts, $other_array );
310 304 }
311 305 }
312 306
@@ -320,9 +314,8 @@
320 314 /**
321 315 * @since 4.0
322 316 *
323 317 * @param array $atts - Includes field array, field_obj, display array, values array.
324 - *
325 318 * @return void
326 319 */
327 320 public static function load_single_field_settings( $atts ) {
328 321 $field = $atts['field'];
@@ -348,9 +341,9 @@
348 341 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
349 342 // Add fallback for an add-on field type that has been deactivated.
350 343 $all_field_types[ $field['type'] ] = array(
351 344 'name' => ucfirst( $field['type'] ),
352 - 'icon' => 'frmfont frm_pencil_icon',
345 + 'icon' => 'frm_icon_font frm_pencil_icon',
353 346 );
354 347 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
355 348 // Fallback for fields added in a more basic way.
356 349 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -356,9 +349,8 @@
356 349 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
357 350 }
358 351
359 352 $type_name = $all_field_types[ $field['type'] ]['name'];
360 -
361 353 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
362 354 $type_name = $all_field_types['divider|repeat']['name'];
363 355 }
364 356
@@ -391,9 +383,8 @@
391 383 * @since 4.0
392 384 *
393 385 * @param array $field
394 386 * @param array $atts
395 - *
396 387 * @return array
397 388 */
398 389 private static function default_value_types( $field, $atts ) {
399 390 $types = array(
@@ -398,33 +389,31 @@
398 389 private static function default_value_types( $field, $atts ) {
399 390 $types = array(
400 391 'default_value' => array(
401 392 'class' => '',
402 - 'icon' => 'frmfont frm_text2_icon',
403 - 'title' => __( 'Default Value', 'formidable' ),
393 + 'icon' => 'frm_icon_font frm_text2_icon',
394 + 'title' => __( 'Default Value (Text)', 'formidable' ),
404 395 'data' => array(
405 396 'frmshow' => '#default-value-for-',
406 397 ),
407 398 ),
408 399 'calc' => array(
409 - 'class' => 'frm_show_upgrade frm_noallow',
410 - 'title' => __( 'Calculate Value', 'formidable' ),
411 - 'icon' => 'frmfont frm_calculator_icon',
412 - 'data' => array(
400 + 'class' => 'frm_show_upgrade frm_noallow',
401 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
402 + 'icon' => 'frm_icon_font frm_calculator_icon',
403 + 'data' => array(
413 404 'medium' => 'calculations',
414 405 'upgrade' => __( 'Calculator forms', 'formidable' ),
415 406 ),
416 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
417 407 ),
418 408 'get_values_field' => array(
419 - 'class' => 'frm_show_upgrade frm_noallow',
420 - 'title' => __( 'Lookup', 'formidable' ),
421 - 'icon' => 'frmfont frm_search_icon',
422 - 'data' => array(
409 + 'class' => 'frm_show_upgrade frm_noallow',
410 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
411 + 'icon' => 'frm_icon_font frm_search_icon',
412 + 'data' => array(
423 413 'medium' => 'lookup',
424 414 'upgrade' => __( 'Lookup fields', 'formidable' ),
425 415 ),
426 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
427 416 ),
428 417 );
429 418
430 419 $types = apply_filters( 'frm_default_value_types', $types, $atts );
@@ -432,13 +421,11 @@
432 421 // Set active class.
433 422 $settings = array_keys( $types );
434 423 $active = 'default_value';
435 424
436 - if ( FrmAppHelper::pro_is_connected() ) {
437 - foreach ( $settings as $type ) {
438 - if ( ! empty( $field[ $type ] ) ) {
439 - $active = $type;
440 - }
425 + foreach ( $settings as $type ) {
426 + if ( ! empty( $field[ $type ] ) ) {
427 + $active = $type;
441 428 }
442 429 }
443 430
444 431 $types[ $active ]['class'] .= ' current';
@@ -448,9 +435,8 @@
448 435 }
449 436
450 437 /**
451 438 * @param string $type
452 - *
453 439 * @return string
454 440 */
455 441 public static function change_type( $type ) {
456 442 $type_switch = array(
@@ -460,9 +446,8 @@
460 446 'rte' => 'textarea',
461 447 'website' => 'url',
462 448 'image' => 'url',
463 449 );
464 -
465 450 if ( isset( $type_switch[ $type ] ) ) {
466 451 $type = $type_switch[ $type ];
467 452 }
468 453
@@ -501,9 +486,8 @@
501 486 * @since 3.0
502 487 *
503 488 * @param array $field Field data.
504 489 * @param bool $is_hidden Whether the format option should be hidden.
505 - *
506 490 * @return void
507 491 */
508 492 public static function show_format_option( $field, $is_hidden = false ) {
509 493 $attributes = array(
@@ -517,14 +501,8 @@
517 501
518 502 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
519 503 }
520 504
521 - /**
522 - * @param array $field
523 - * @param bool $echo
524 - *
525 - * @return string
526 - */
527 505 public static function input_html( $field, $echo = true ) {
528 506 $class = array();
529 507 self::add_input_classes( $field, $class );
530 508
@@ -553,9 +531,8 @@
553 531
554 532 /**
555 533 * @param array $field
556 534 * @param array $class
557 - *
558 535 * @return void
559 536 */
560 537 private static function add_input_classes( $field, array &$class ) {
561 538 if ( ! empty( $field['input_class'] ) ) {
@@ -573,9 +550,8 @@
573 550
574 551 /**
575 552 * @param array $field
576 553 * @param array $add_html
577 - *
578 554 * @return void
579 555 */
580 556 private static function add_html_size( $field, array &$add_html ) {
581 557 $size_fields = array(
@@ -608,9 +584,8 @@
608 584
609 585 /**
610 586 * @param array $field
611 587 * @param array $add_html
612 - *
613 588 * @return void
614 589 */
615 590 private static function add_html_cols( $field, array &$add_html ) {
616 591 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -631,9 +606,10 @@
631 606 if ( ! isset( $calc[ $unit ] ) ) {
632 607 return;
633 608 }
634 609
635 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
610 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
611 +
636 612 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
637 613 }
638 614
639 615 /**
@@ -638,9 +614,8 @@
638 614
639 615 /**
640 616 * @param array $field
641 617 * @param array $add_html
642 - *
643 618 * @return void
644 619 */
645 620 private static function add_html_length( $field, array &$add_html ) {
646 621 // Check for max setting and if this field accepts maxlength.
@@ -666,13 +641,11 @@
666 641 /**
667 642 * @param array $field
668 643 * @param array $add_html
669 644 * @param array $class
670 - *
671 645 * @return void
672 646 */
673 647 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
674 - // phpcs:ignore Universal.Operators.StrictComparisons
675 648 if ( $field['default_value'] != '' ) {
676 649 if ( is_array( $field['default_value'] ) ) {
677 650 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
678 651 } else {
@@ -680,10 +653,8 @@
680 653 }
681 654 }
682 655
683 656 $field['placeholder'] = self::prepare_placeholder( $field );
684 -
685 - // phpcs:ignore Universal.Operators.StrictComparisons
686 657 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
687 658 // don't include a json placeholder
688 659 return;
689 660 }
@@ -696,13 +667,14 @@
696 667 *
697 668 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
698 669 *
699 670 * @param array $field Field array.
700 - *
701 671 * @return string
702 672 */
703 673 private static function prepare_placeholder( $field ) {
704 - return $field['placeholder'] ?? '';
674 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
675 +
676 + return $placeholder;
705 677 }
706 678
707 679 /**
708 680 * If the label position is "inside",
@@ -723,17 +695,13 @@
723 695 * Maybe add a blank placeholder option before any options
724 696 * in a dropdown.
725 697 *
726 698 * @since 4.04
727 - *
728 - * @param array|object $field
729 - *
730 699 * @return bool True if placeholder was added.
731 700 */
732 701 public static function add_placeholder_to_select( $field ) {
733 702 $placeholder = FrmField::get_option( $field, 'placeholder' );
734 -
735 - if ( ! $placeholder ) {
703 + if ( empty( $placeholder ) ) {
736 704 $placeholder = self::get_default_value_from_name( $field );
737 705 }
738 706
739 707 $use_placeholder = $placeholder;
@@ -740,9 +708,8 @@
740 708 $autocomplete = FrmField::get_option( $field, 'autocom' );
741 709
742 710 if ( $autocomplete ) {
743 711 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
744 -
745 712 if ( $use_chosen ) {
746 713 $use_placeholder = '';
747 714 }
748 715 }
@@ -765,9 +732,8 @@
765 732 * Use HTML5 placeholder with js fallback.
766 733 *
767 734 * @param array $field
768 735 * @param array $add_html
769 - *
770 736 * @return void
771 737 */
772 738 private static function add_placeholder_to_input( $field, &$add_html ) {
773 739 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -777,13 +743,11 @@
777 743
778 744 /**
779 745 * @param array $field
780 746 * @param array $add_html
781 - *
782 747 * @return void
783 748 */
784 749 private static function add_frmval_to_input( $field, &$add_html ) {
785 - // phpcs:ignore Universal.Operators.StrictComparisons
786 750 if ( $field['placeholder'] != '' ) {
787 751 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
788 752
789 753 if ( 'select' === $field['type'] ) {
@@ -790,20 +754,13 @@
790 754 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
791 755 }
792 756 }
793 757
794 - // phpcs:ignore Universal.Operators.StrictComparisons
795 758 if ( $field['default_value'] != '' ) {
796 759 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
797 760 }
798 761 }
799 762
800 - /**
801 - * @param array $field
802 - * @param array $add_html
803 - *
804 - * @return void
805 - */
806 763 private static function add_validation_messages( $field, array &$add_html ) {
807 764 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
808 765
809 766 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -827,9 +784,8 @@
827 784 *
828 785 * @since 6.9
829 786 *
830 787 * @param array|object $field
831 - *
832 788 * @return array
833 789 */
834 790 private static function get_validation_data_attribute_visibility_info( $field ) {
835 791 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -859,20 +815,17 @@
859 815 * @since 5.0.03
860 816 *
861 817 * @param array $field
862 818 * @param array $add_html
863 - *
864 819 * @return void
865 820 */
866 821 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
867 822 $form = self::get_form_for_js_validation( $field );
868 -
869 823 if ( false === $form ) {
870 824 return;
871 825 }
872 826
873 827 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
874 -
875 828 if ( false !== $error_body ) {
876 829 $error_body = urlencode( $error_body );
877 830 $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
878 831 }
@@ -881,24 +834,20 @@
881 834 /**
882 835 * @since 5.0.03
883 836 *
884 837 * @param array $field
885 - *
886 838 * @return false|stdClass false if there is no form object found with JS validation active.
887 839 */
888 840 private static function get_form_for_js_validation( $field ) {
889 841 global $frm_vars;
890 -
891 842 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
892 843 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
893 844 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
894 845 }
895 -
896 846 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
897 847 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
898 848 }
899 849 }
900 -
901 850 return false;
902 851 }
903 852
904 853 /**
@@ -904,9 +853,8 @@
904 853 /**
905 854 * @param stdClass $form
906 855 * @param array $field
907 856 * @param array $errors
908 - *
909 857 * @return false|string
910 858 */
911 859 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
912 860 if ( empty( $field['custom_html'] ) ) {
@@ -914,16 +862,15 @@
914 862 }
915 863
916 864 $custom_html = $field['custom_html'];
917 865 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
918 - $start = strpos( $custom_html, '[if error]' );
919 866
867 + $start = strpos( $custom_html, '[if error]' );
920 868 if ( false === $start ) {
921 869 return false;
922 870 }
923 871
924 872 $end = strpos( $custom_html, '[/if error]' );
925 -
926 873 if ( false === $end || $end < $start ) {
927 874 return false;
928 875 }
929 876
@@ -934,9 +881,13 @@
934 881 '<div class="frm_error">[error]</div>',
935 882 '<div class="frm_error" role="alert">[error]</div>',
936 883 );
937 884
938 - return in_array( $error_body, $default_html, true ) ? false : $error_body;
885 + if ( in_array( $error_body, $default_html, true ) ) {
886 + return false;
887 + }
888 +
889 + return $error_body;
939 890 }
940 891
941 892 /**
942 893 * If 'required' is added to a conditionally hidden field, the form won't
@@ -943,12 +894,10 @@
943 894 * submit in many browsers. Check to make sure the javascript to conditionally
944 895 * remove it is present if needed.
945 896 *
946 897 * @since 3.06.01
947 - *
948 898 * @param array $field
949 899 * @param array $add_html
950 - *
951 900 * @return void
952 901 */
953 902 private static function maybe_add_html_required( $field, array &$add_html ) {
954 903 $excluded_field_types =
@@ -967,9 +916,8 @@
967 916
968 917 /**
969 918 * @param array $field
970 919 * @param array $add_html
971 - *
972 920 * @return void
973 921 */
974 922 private static function add_shortcodes_to_html( $field, array &$add_html ) {
975 923 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -980,11 +928,10 @@
980 928 unset( $field['shortcodes']['autocomplete'] );
981 929 }
982 930
983 931 foreach ( $field['shortcodes'] as $k => $v ) {
984 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
932 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
985 933 $subfield_name = $field['subfield_name'];
986 -
987 934 if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
988 935 continue;
989 936 }
990 937 // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
@@ -991,14 +938,13 @@
991 938 $k = 'aria-invalid';
992 939 $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
993 940 unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
994 941 }
995 -
996 942 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
997 943 continue;
998 944 }
999 945
1000 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
946 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1001 947 $add_html[] = $v;
1002 948 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1003 949 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1004 950 } else {
@@ -1014,9 +960,8 @@
1014 960 *
1015 961 * @since 6.11.2
1016 962 *
1017 963 * @param string $key The option key.
1018 - *
1019 964 * @return bool
1020 965 */
1021 966 private static function should_allow_input_attribute( $key ) {
1022 967 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1031,9 +976,8 @@
1031 976 * @since 3.0
1032 977 *
1033 978 * @param array $field
1034 979 * @param array $add_html
1035 - *
1036 980 * @return void
1037 981 */
1038 982 private static function add_pattern_attribute( $field, array &$add_html ) {
1039 983 $format_value = FrmField::get_option( $field, 'format' );
@@ -1047,21 +991,14 @@
1047 991 $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1048 992 }
1049 993 }
1050 994
1051 - /**
1052 - * @param mixed $opt
1053 - * @param mixed $opt_key
1054 - * @param array|object $field
1055 - *
1056 - * @return mixed
1057 - */
1058 995 public static function check_value( $opt, $opt_key, $field ) {
1059 996 if ( is_array( $opt ) ) {
1060 997 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1061 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
998 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1062 999 } else {
1063 - $opt = $opt['label'] ?? reset( $opt );
1000 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1064 1001 }
1065 1002 }
1066 1003
1067 1004 return $opt;
@@ -1066,16 +1003,11 @@
1066 1003
1067 1004 return $opt;
1068 1005 }
1069 1006
1070 - /**
1071 - * @param mixed $opt
1072 - *
1073 - * @return mixed
1074 - */
1075 1007 public static function check_label( $opt ) {
1076 1008 if ( is_array( $opt ) ) {
1077 - $opt = $opt['label'] ?? reset( $opt );
1009 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1078 1010 }
1079 1011
1080 1012 return $opt;
1081 1013 }