PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22.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
← All changes | classes/helpers/FrmXMLHelper.php +201 -74 6.36.22.1 View file →
@@ -5,9 +5,9 @@
5 5
6 6 class FrmXMLHelper {
7 7
8 8 /**
9 - * @var bool $installing_template true if importing an XML from API, false if importing an XML file manually.
9 + * @var bool true if importing an XML from API, false if importing an XML file manually.
10 10 */
11 11 private static $installing_template = false;
12 12
13 13 public static function get_xml_values( $opt, $padding ) {
@@ -26,8 +26,12 @@
26 26 echo self::cdata( $opt ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
27 27 }
28 28 }
29 29
30 + /**
31 + * @param string $file
32 + * @return array|WP_Error The items imported
33 + */
30 34 public static function import_xml( $file ) {
31 35 if ( ! defined( 'WP_IMPORTING' ) ) {
32 36 define( 'WP_IMPORTING', true );
33 37 }
@@ -91,9 +95,9 @@
91 95 '',
92 96 $content_before_channel_tag,
93 97 1
94 98 );
95 - $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position );
99 + $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position );
96 100 }
97 101 }
98 102
99 103 /**
@@ -123,9 +127,9 @@
123 127 }
124 128
125 129 $imported = apply_filters( 'frm_importing_xml', $imported, $xml );
126 130
127 - if ( ! isset( $imported['form_status'] ) || empty( $imported['form_status'] ) ) {
131 + if ( empty( $imported['form_status'] ) ) {
128 132 // Check for an error message in the XML.
129 133 if ( isset( $xml->Code ) && isset( $xml->Message ) ) { // phpcs:ignore WordPress.NamingConventions
130 134 $imported['error'] = (string) $xml->Message; // phpcs:ignore WordPress.NamingConventions
131 135 }
@@ -156,8 +160,13 @@
156 160 'terms' => array(),
157 161 );
158 162 }
159 163
164 + /**
165 + * @param SimpleXMLElement $terms
166 + * @param array $imported
167 + * @return array
168 + */
160 169 public static function import_xml_terms( $terms, $imported ) {
161 170 foreach ( $terms as $t ) {
162 171 if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) {
163 172 continue;
@@ -175,14 +184,14 @@
175 184 )
176 185 );
177 186
178 187 if ( $term && is_array( $term ) ) {
179 - $imported['imported']['terms'] ++;
188 + ++$imported['imported']['terms'];
180 189 $imported['terms'][ (int) $t->term_id ] = $term['term_id'];
181 190 }
182 191
183 192 unset( $term, $t );
184 - }
193 + }//end foreach
185 194
186 195 return $imported;
187 196 }
188 197
@@ -187,8 +196,11 @@
187 196 }
188 197
189 198 /**
190 199 * @since 2.0.8
200 + *
201 + * @param object $t
202 + * @return int|string
191 203 */
192 204 private static function get_term_parent_id( $t ) {
193 205 $parent = (string) $t->term_parent;
194 206 if ( ! empty( $parent ) ) {
@@ -202,8 +214,13 @@
202 214
203 215 return $parent;
204 216 }
205 217
218 + /**
219 + * @param SimpleXMLElement $forms
220 + * @param array $imported
221 + * @return array
222 + */
206 223 public static function import_xml_forms( $forms, $imported ) {
207 224 $child_forms = array();
208 225
209 226 // Import child forms first
@@ -228,9 +245,9 @@
228 245 $form_id = FrmForm::create( $form );
229 246 if ( $form_id ) {
230 247 if ( empty( $form['parent_form_id'] ) ) {
231 248 // Don't include the repeater form in the imported count.
232 - $imported['imported']['forms'] ++;
249 + ++$imported['imported']['forms'];
233 250 }
234 251
235 252 // Keep track of whether this specific form was updated or not.
236 253 $imported['form_status'][ $form_id ] = 'imported';
@@ -255,9 +272,9 @@
255 272
256 273 do_action( 'frm_after_import_form', $form_id, $form );
257 274
258 275 unset( $form, $item );
259 - }
276 + }//end foreach
260 277
261 278 self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
262 279
263 280 return $imported;
@@ -303,9 +320,15 @@
303 320 }
304 321
305 322 $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form );
306 323
307 - return FrmForm::getAll( $edit_query, '', 1 );
324 + $form = FrmForm::getAll( $edit_query, '', 1 );
325 + if ( is_object( $form ) && $form->status === 'trash' ) {
326 + FrmForm::destroy( $form->id );
327 + return false;
328 + }
329 +
330 + return $form;
308 331 }
309 332
310 333 private static function update_form( $this_form, $form, &$imported ) {
311 334 $form_id = $this_form->id;
@@ -311,9 +334,9 @@
311 334 $form_id = $this_form->id;
312 335 FrmForm::update( $form_id, $form );
313 336 if ( empty( $form['parent_form_id'] ) ) {
314 337 // Don't include the repeater form in the updated count.
315 - $imported['updated']['forms'] ++;
338 + ++$imported['updated']['forms'];
316 339 }
317 340
318 341 // Keep track of whether this specific form was updated or not
319 342 $imported['form_status'][ $form_id ] = 'updated';
@@ -374,10 +397,10 @@
374 397 * Keep track of all imported child forms
375 398 *
376 399 * @since 2.0.16
377 400 *
378 - * @param int $form_id
379 - * @param int $parent_form_id
401 + * @param int $form_id
402 + * @param int $parent_form_id
380 403 * @param array $child_forms
381 404 */
382 405 private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
383 406 if ( $parent_form_id ) {
@@ -429,13 +452,13 @@
429 452 if ( ! empty( $this_form ) ) {
430 453 // check for field to edit by field id
431 454 if ( isset( $form_fields[ $f['id'] ] ) ) {
432 455 FrmField::update( $f['id'], $f );
433 - $imported['updated']['fields'] ++;
456 + ++$imported['updated']['fields'];
434 457
435 458 unset( $form_fields[ $f['id'] ] );
436 459
437 - //unset old field key
460 + // Unset old field key.
438 461 if ( isset( $form_fields[ $f['field_key'] ] ) ) {
439 462 unset( $form_fields[ $f['field_key'] ] );
440 463 }
441 464 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
@@ -440,25 +463,32 @@
440 463 }
441 464 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
442 465 $keys_by_original_field_id[ $f['id'] ] = $f['field_key'];
443 466
467 + $old_field_id = $f['id'];
468 +
444 469 // check for field to edit by field key
445 470 unset( $f['id'] );
446 471
447 472 FrmField::update( $form_fields[ $f['field_key'] ], $f );
448 - $imported['updated']['fields'] ++;
473 + ++$imported['updated']['fields'];
449 474
450 - unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
451 - unset( $form_fields[ $f['field_key'] ] ); //unset old field key
475 + self::do_after_field_imported_action( $f, $form_fields, $old_field_id );
476 +
477 + // Unset old field id.
478 + unset( $form_fields[ $form_fields[ $f['field_key'] ] ] );
479 +
480 + // Unset old field key.
481 + unset( $form_fields[ $f['field_key'] ] );
452 482 } else {
453 - // if no matching field id or key in this form, create the field
483 + // If no matching field id or key in this form, create the field.
454 484 self::create_imported_field( $f, $imported );
455 - }
485 + }//end if
456 486 } else {
457 487
458 488 self::create_imported_field( $f, $imported );
459 - }
460 - }
489 + }//end if
490 + }//end foreach
461 491
462 492 if ( $keys_by_original_field_id ) {
463 493 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
464 494 }
@@ -463,8 +493,46 @@
463 493 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
464 494 }
465 495 }
466 496
497 + /**
498 + * @since 6.8.4
499 + *
500 + * @param array $field_array
501 + * @return array
502 + */
503 + private static function update_field_options_with_defaults( $field_array ) {
504 + $defaults = self::default_field_options( $field_array['type'] );
505 + $field_array['field_options'] = array_merge( $defaults, $field_array['field_options'] );
506 +
507 + return $field_array;
508 + }
509 +
510 + /**
511 + * @since 6.8.4
512 + *
513 + * @param array $field_array
514 + * @param array $form_fields
515 + * @param int $old_field_id
516 + *
517 + * @return void
518 + */
519 + private static function do_after_field_imported_action( $field_array, $form_fields, $old_field_id ) {
520 + // Assign field array the update field's ID.
521 + $field_array['id'] = $form_fields[ $field_array['field_key'] ];
522 +
523 + /**
524 + * Fires when an existing field is imported.
525 + *
526 + * @since 6.8.4
527 + *
528 + * @param array $field_array
529 + * @param int $field_id
530 + * @param int $old_field_id
531 + */
532 + do_action( 'frm_after_existing_field_is_imported', $field_array, $form_fields[ $field_array['field_key'] ], $old_field_id );
533 + }
534 +
467 535 private static function fill_field( $field, $form_id ) {
468 536 return array(
469 537 'id' => (int) $field->id,
470 538 'field_key' => (string) $field->field_key,
@@ -520,9 +588,9 @@
520 588 /**
521 589 * Update the current in_section value at the beginning of the field loop
522 590 *
523 591 * @since 2.0.25
524 - * @param int $in_section
592 + * @param int $in_section
525 593 * @param array $f
526 594 */
527 595 private static function maybe_update_in_section_variable( &$in_section, &$f ) {
528 596 // If we're at the end of a section, switch $in_section is 0
@@ -535,9 +603,9 @@
535 603 $f['field_options']['in_section'] = $in_section;
536 604 }
537 605
538 606 // If we're starting a new section, switch $in_section to ID of divider
539 - if ( $f['type'] == 'divider' ) {
607 + if ( $f['type'] === 'divider' ) {
540 608 $in_section = $f['id'];
541 609 }
542 610 }
543 611
@@ -553,9 +621,9 @@
553 621 if ( ! isset( $imported['forms'] ) ) {
554 622 return;
555 623 }
556 624
557 - if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
625 + if ( $f['type'] === 'form' || ( $f['type'] === 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
558 626 if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
559 627 $form_select = (int) $f['field_options']['form_select'];
560 628 if ( isset( $imported['forms'][ $form_select ] ) ) {
561 629 $f['field_options']['form_select'] = $imported['forms'][ $form_select ];
@@ -617,9 +685,9 @@
617 685 * @since 4.0
618 686 * @return array
619 687 */
620 688 public static function migrate_field_placeholder( $field, $type ) {
621 - $field = (array) $field;
689 + $field = (array) $field;
622 690 $field_options = $field['field_options'];
623 691 if ( empty( $field_options[ $type ] ) || empty( $field['default_value'] ) ) {
624 692 return array();
625 693 }
@@ -664,10 +732,9 @@
664 732 * @param array $f
665 733 * @param array $imported
666 734 */
667 735 private static function create_imported_field( $f, &$imported ) {
668 - $defaults = self::default_field_options( $f['type'] );
669 - $f['field_options'] = array_merge( $defaults, $f['field_options'] );
736 + $f = self::update_field_options_with_defaults( $f );
670 737
671 738 if ( is_callable( 'FrmProFileImport::import_attachment' ) ) {
672 739 $f = self::maybe_import_images_for_options( $f );
673 740 }
@@ -673,9 +740,9 @@
673 740 }
674 741
675 742 $new_id = FrmField::create( $f );
676 743 if ( $new_id != false ) {
677 - $imported['imported']['fields'] ++;
744 + ++$imported['imported']['fields'];
678 745 do_action( 'frm_after_field_is_imported', $f, $new_id );
679 746 }
680 747 }
681 748
@@ -696,13 +763,15 @@
696 763 if ( ! is_array( $option ) || empty( $option['src'] ) ) {
697 764 continue;
698 765 }
699 766
700 - $field_object = (object) $field;
701 - $field_object->type = 'file'; // Fake the file type as FrmProImport::import_attachment checks for file type.
767 + $field_object = (object) $field;
768 + // Fake the file type as FrmProImport::import_attachment checks for file type.
769 + $field_object->type = 'file';
702 770
703 771 $image_id = FrmProFileImport::import_attachment( $option['src'], $field_object );
704 - unset( $field['options'][ $key ]['src'] ); // Remove the src from options as it isn't required after import.
772 + // Remove the src from options as it isn't required after import.
773 + unset( $field['options'][ $key ]['src'] );
705 774
706 775 if ( is_numeric( $image_id ) ) {
707 776 $field['options'][ $key ]['image'] = $image_id;
708 777 }
@@ -714,9 +783,9 @@
714 783 /**
715 784 * Fix field ids for fields that already exist prior to import.
716 785 *
717 786 * @since 4.07
718 - * @param int $form_id
787 + * @param int $form_id
719 788 * @param array $keys_by_original_field_id
720 789 */
721 790 protected static function maybe_update_field_ids( $form_id, $keys_by_original_field_id ) {
722 791 global $frm_duplicate_ids;
@@ -786,9 +855,9 @@
786 855
787 856 // Set to default
788 857 $form['options']['custom_style'] = 1;
789 858 }
790 - }
859 + }//end if
791 860 }
792 861
793 862 /**
794 863 * After styles are imported, check for any forms that were linked
@@ -810,8 +879,15 @@
810 879 }
811 880 }
812 881 }
813 882
883 + /**
884 + * Handle import for all posts. This includes views, styles, pages, and form actions.
885 + *
886 + * @param SimpleXMLElement $views
887 + * @param array $imported
888 + * @return array
889 + */
814 890 public static function import_xml_views( $views, $imported ) {
815 891 $imported['posts'] = array();
816 892 $form_action_type = FrmFormActionsController::$action_post_type;
817 893
@@ -857,9 +933,9 @@
857 933
858 934 $post_id = false;
859 935 if ( $post['post_type'] === $form_action_type ) {
860 936 $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
861 - if ( $action_control && is_object( $action_control ) ) {
937 + if ( $action_control && is_object( $action_control ) && isset( $imported['form_status'] ) ) {
862 938 $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
863 939 }
864 940 unset( $action_control );
865 941 } elseif ( $post['post_type'] === 'frm_styles' ) {
@@ -865,8 +941,10 @@
865 941 } elseif ( $post['post_type'] === 'frm_styles' ) {
866 942 // Properly encode post content before inserting the post
867 943 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
868 944 $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
945 + // Store template data additionally to a postmeta that can be used to revert the style to default template style.
946 + $post['postmeta']['frm_style_default'] = $post['post_content'];
869 947
870 948 // Create/update post now
871 949 $post_id = wp_insert_post( $post );
872 950 } else {
@@ -876,9 +954,9 @@
876 954 $post['post_parent'] = $imported['posts'][ $post['post_parent'] ];
877 955 }
878 956 // Create/update post now
879 957 $post_id = wp_insert_post( $post );
880 - }
958 + }//end if
881 959
882 960 if ( ! is_numeric( $post_id ) ) {
883 961 continue;
884 962 }
@@ -895,23 +973,23 @@
895 973 $this_type = $post_types[ $post['post_type'] ];
896 974 }
897 975
898 976 if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
899 - $imported['updated'][ $this_type ] ++;
977 + ++$imported['updated'][ $this_type ];
900 978 } else {
901 - $imported['imported'][ $this_type ] ++;
979 + ++$imported['imported'][ $this_type ];
902 980 }
903 981
904 - $imported['posts'][ (int) $old_id ] = $post_id;
982 + $imported['posts'][ $old_id ] = $post_id;
905 983
906 984 if ( $post['post_type'] === 'frm_display' ) {
907 - $view_ids[ (int) $old_id ] = $post_id;
985 + $view_ids[ $old_id ] = $post_id;
908 986 }
909 987
910 988 do_action( 'frm_after_import_view', $post_id, $post );
911 989
912 990 unset( $post );
913 - }
991 + }//end foreach
914 992
915 993 if ( $posts_with_shortcodes && $view_ids ) {
916 994 self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
917 995 }
@@ -935,9 +1013,9 @@
935 1013 * @param array $imported_forms
936 1014 */
937 1015 private static function clear_forms_style_caches( $imported_forms ) {
938 1016 $where = array(
939 - 'id' => $imported_forms,
1017 + 'id' => $imported_forms,
940 1018 'options LIKE' => '"old_style"',
941 1019 );
942 1020 $forms = FrmDb::get_results( 'frm_forms', $where );
943 1021
@@ -1102,9 +1180,9 @@
1102 1180 'key' => (string) $meta->meta_key,
1103 1181 'value' => (string) $meta->meta_value,
1104 1182 );
1105 1183
1106 - //switch old form and field ids to new ones
1184 + // Switch old form and field ids to new ones.
1107 1185 if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
1108 1186 $m['value'] = $imported['forms'][ (int) $m['value'] ];
1109 1187 } else {
1110 1188 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
@@ -1120,10 +1198,36 @@
1120 1198 $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
1121 1199 }
1122 1200 }
1123 1201
1202 + if ( ! empty( $m['value']['map_address_fields'] ) ) {
1203 + foreach ( $m['value']['map_address_fields'] as $address_field_key => $address_field_id ) {
1204 + if ( isset( $frm_duplicate_ids[ $address_field_id ] ) ) {
1205 + $m['value']['map_address_fields'][ $address_field_key ] = $frm_duplicate_ids[ $address_field_id ];
1206 + }
1207 + }
1208 + }
1209 +
1210 + if ( ! empty( $m['value']['calendar_options'] ) ) {
1211 + foreach ( $m['value']['calendar_options'] as $calendar_option_group_key => $calendar_option ) {
1212 + if ( isset( $frm_duplicate_ids[ $calendar_option['value'] ] ) ) {
1213 + $m['value']['calendar_options'][ $calendar_option_group_key ]['value'] = $frm_duplicate_ids[ $calendar_option['value'] ];
1214 + }
1215 + }
1216 + }
1217 +
1218 + if ( ! empty( $m['value']['timeline_options'] ) ) {
1219 + foreach ( $m['value']['timeline_options'] as $timeline_option_group_key => $timeline_group_option ) {
1220 + foreach ( $timeline_group_option as $timeline_option_key => $timeline_option ) {
1221 + if ( isset( $frm_duplicate_ids[ $timeline_option ] ) ) {
1222 + $m['value']['timeline_options'][ $timeline_option_group_key ][ $timeline_option_key ] = $frm_duplicate_ids[ $timeline_option ];
1223 + }
1224 + }
1225 + }
1226 + }
1227 +
1124 1228 $check_dup_array = array();
1125 - if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
1229 + if ( ! empty( $m['value']['order_by'] ) ) {
1126 1230 if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
1127 1231 $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
1128 1232 } elseif ( is_array( $m['value']['order_by'] ) ) {
1129 1233 $check_dup_array[] = 'order_by';
@@ -1129,9 +1233,9 @@
1129 1233 $check_dup_array[] = 'order_by';
1130 1234 }
1131 1235 }
1132 1236
1133 - if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
1237 + if ( ! empty( $m['value']['where'] ) ) {
1134 1238 $check_dup_array[] = 'where';
1135 1239 }
1136 1240
1137 1241 foreach ( $check_dup_array as $check_k ) {
@@ -1141,11 +1245,11 @@
1141 1245 }
1142 1246 unset( $mk, $mv );
1143 1247 }
1144 1248 }
1145 - }
1146 - }
1147 - }
1249 + }//end if
1250 + }//end if
1251 + }//end if
1148 1252
1149 1253 if ( ! is_array( $m['value'] ) ) {
1150 1254 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
1151 1255 }
@@ -1159,10 +1263,10 @@
1159 1263
1160 1264 /**
1161 1265 * Add terms to post
1162 1266 *
1163 - * @param array $post by reference
1164 - * @param object $item The XML object data
1267 + * @param array $post By reference.
1268 + * @param object $item The XML object data.
1165 1269 */
1166 1270 private static function populate_taxonomies( &$post, $item ) {
1167 1271 foreach ( $item->category as $c ) {
1168 1272 $att = $c->attributes();
@@ -1187,13 +1291,13 @@
1187 1291 }
1188 1292
1189 1293 $post['tax_input'][ $taxonomy ][] = $name;
1190 1294 unset( $name );
1191 - }
1295 + }//end foreach
1192 1296 }
1193 1297
1194 1298 /**
1195 - * Edit post if the key and created time match
1299 + * Edit post if the key and created time match.
1196 1300 */
1197 1301 private static function maybe_editing_post( &$post ) {
1198 1302 $match_by = array(
1199 1303 'post_type' => $post['post_type'],
@@ -1201,9 +1305,9 @@
1201 1305 'post_status' => $post['post_status'],
1202 1306 'posts_per_page' => 1,
1203 1307 );
1204 1308
1205 - if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
1309 + if ( in_array( $post['post_status'], array( 'trash', 'draft' ), true ) ) {
1206 1310 $match_by['include'] = $post['post_id'];
1207 1311 unset( $match_by['name'] );
1208 1312 }
1209 1313
@@ -1243,13 +1347,13 @@
1243 1347
1244 1348 case 'frm_param':
1245 1349 add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES );
1246 1350 break;
1247 - }
1351 + }//end switch
1248 1352
1249 1353 update_post_meta( $post_id, $k, $v );
1250 1354 unset( $k, $v );
1251 - }
1355 + }//end foreach
1252 1356 }
1253 1357
1254 1358 /**
1255 1359 * @param array $post
@@ -1265,10 +1369,10 @@
1265 1369 }
1266 1370 }
1267 1371
1268 1372 private static function maybe_update_stylesheet( $imported ) {
1269 - $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
1270 - $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
1373 + $new_styles = ! empty( $imported['imported']['styles'] );
1374 + $updated_styles = ! empty( $imported['updated']['styles'] );
1271 1375 if ( $new_styles || $updated_styles ) {
1272 1376 if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
1273 1377 $frm_style = new FrmStyle();
1274 1378 $frm_style->update( 'default' );
@@ -1279,9 +1383,11 @@
1279 1383 }
1280 1384 }
1281 1385
1282 1386 /**
1387 + * @param mixed $result
1283 1388 * @param string $message
1389 + * @param array $errors
1284 1390 */
1285 1391 public static function parse_message( $result, &$message, &$errors ) {
1286 1392 if ( is_wp_error( $result ) ) {
1287 1393 $errors[] = $result->get_error_message();
@@ -1287,9 +1393,9 @@
1287 1393 $errors[] = $result->get_error_message();
1288 1394
1289 1395 // Remove the SimpleXML_parse_error from the WP_Error object to avoid
1290 1396 // displaying duplicate error messages from $result->get_error_message()
1291 - $error_codes = $result->get_error_codes();
1397 + $error_codes = $result->get_error_codes();
1292 1398 $error_details = array();
1293 1399 foreach ( $error_codes as $error_code ) {
1294 1400 // Clone WP_Error data because WP_Error removes all error messages and data
1295 1401 // associated with the specified error code when an item is removed.
@@ -1305,15 +1411,16 @@
1305 1411 $errors[] = '<br />' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '<br />' . esc_html( print_r( $error_details, 1 ) );
1306 1412 }
1307 1413
1308 1414 return;
1309 - } elseif ( ! $result ) {
1415 + }//end if
1416 +
1417 + if ( ! $result ) {
1310 1418 return;
1311 1419 }
1312 1420
1313 1421 if ( ! is_array( $result ) ) {
1314 1422 $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) );
1315 -
1316 1423 return;
1317 1424 }
1318 1425
1319 1426 $t_strings = array(
@@ -1340,9 +1447,9 @@
1340 1447 $message .= '</li>';
1341 1448 }
1342 1449 }
1343 1450
1344 - if ( $message == '<ul>' ) {
1451 + if ( $message === '<ul>' ) {
1345 1452 $message = '';
1346 1453 $errors[] = __( 'Nothing was imported or updated', 'formidable' );
1347 1454 } else {
1348 1455 self::add_form_link_to_message( $result, $message );
@@ -1646,9 +1753,13 @@
1646 1753
1647 1754 /**
1648 1755 * Migrate post settings to form action
1649 1756 *
1757 + * @param array $form_options
1758 + * @param int $form_id
1650 1759 * @param string $post_type
1760 + * @param array $imported
1761 + * @param bool $switch
1651 1762 */
1652 1763 private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1653 1764 if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
1654 1765 return;
@@ -1717,9 +1828,9 @@
1717 1828
1718 1829 if ( ! $exists ) {
1719 1830 // this isn't an email, but we need to use a class that will always be included
1720 1831 FrmDb::save_json_post( $new_action );
1721 - $imported['imported']['actions'] ++;
1832 + ++$imported['imported']['actions'];
1722 1833 }
1723 1834 }
1724 1835
1725 1836 /**
@@ -1726,11 +1837,11 @@
1726 1837 * Switch old field IDs for new field IDs in emails and post
1727 1838 *
1728 1839 * @since 2.0
1729 1840 *
1730 - * @param array $post_content - check for old field IDs
1731 - * @param array $basic_fields - fields with string or int saved
1732 - * @param array $array_fields - fields with arrays saved
1841 + * @param array $post_content Check for old field IDs.
1842 + * @param array $basic_fields Fields with string or int saved.
1843 + * @param array $array_fields Fields with arrays saved.
1733 1844 *
1734 1845 * @return string $post_content - new field IDs
1735 1846 */
1736 1847 private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
@@ -1811,12 +1922,12 @@
1811 1922 );
1812 1923
1813 1924 if ( empty( $exists ) ) {
1814 1925 FrmDb::save_json_post( $new_notification );
1815 - $imported['imported']['actions'] ++;
1926 + ++$imported['imported']['actions'];
1816 1927 }
1817 1928 unset( $new_notification );
1818 - }
1929 + }//end foreach
1819 1930
1820 1931 self::remove_deprecated_notification_settings( $form_id, $form_options );
1821 1932 }
1822 1933
@@ -1825,9 +1936,9 @@
1825 1936 *
1826 1937 * @since 2.05
1827 1938 *
1828 1939 * @param int|string $form_id
1829 - * @param array $form_options
1940 + * @param array $form_options
1830 1941 */
1831 1942 private static function remove_deprecated_notification_settings( $form_id, $form_options ) {
1832 1943 $delete_settings = array( 'notification', 'autoresponder', 'email_to' );
1833 1944 foreach ( $delete_settings as $index ) {
@@ -1838,9 +1949,9 @@
1838 1949 FrmForm::update( $form_id, array( 'options' => $form_options ) );
1839 1950 }
1840 1951
1841 1952 private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
1842 - if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
1953 + if ( ! isset( $form_options['notification'] ) && ! empty( $form_options['email_to'] ) ) {
1843 1954 // add old settings into notification array
1844 1955 $form_options['notification'] = array( 0 => $form_options );
1845 1956 } elseif ( isset( $form_options['notification']['email_to'] ) ) {
1846 1957 // make sure it's in the correct format
@@ -1870,10 +1981,10 @@
1870 1981 $new_notification = array();
1871 1982 self::setup_new_notification( $new_notification, $notification, $atts );
1872 1983
1873 1984 $notifications[] = $new_notification;
1874 - }
1875 - }
1985 + }//end foreach
1986 + }//end if
1876 1987 }
1877 1988
1878 1989 private static function format_email_data( &$atts, $notification ) {
1879 1990 // Format email_to
@@ -1969,9 +2080,9 @@
1969 2080
1970 2081 /**
1971 2082 * Switch field IDs in pre-2.0 email conditional logic
1972 2083 *
1973 - * @param $post_content array, pass by reference
2084 + * @param array $post_content Pass by reference.
1974 2085 */
1975 2086 private static function switch_email_condition_field_ids( &$post_content ) {
1976 2087 // Switch field IDs in conditional logic
1977 2088 if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
@@ -2024,17 +2135,17 @@
2024 2135 }
2025 2136
2026 2137 $notifications[] = $new_notification2;
2027 2138 unset( $new_notification2 );
2028 - }
2139 + }//end if
2029 2140 }
2030 2141
2031 2142 /**
2032 2143 * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2033 2144 *
2034 - * @param boolean $disable
2145 + * @param bool $loader
2035 2146 *
2036 - * @return boolean
2147 + * @return bool
2037 2148 */
2038 2149 public static function maybe_libxml_disable_entity_loader( $loader ) {
2039 2150 if ( version_compare( phpversion(), '8.0', '<' ) && function_exists( 'libxml_disable_entity_loader' ) ) {
2040 2151 $loader = libxml_disable_entity_loader( $loader ); // phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
@@ -2045,6 +2156,22 @@
2045 2156
2046 2157 public static function check_if_libxml_disable_entity_loader_exists() {
2047 2158 return version_compare( phpversion(), '8.0', '<' ) && ! function_exists( 'libxml_disable_entity_loader' );
2048 2159 }
2160 +
2161 + /**
2162 + * Get the file types allowed for importing.
2163 + * This is used in the "accept" attribute for the file upload input on the XML import page.
2164 + *
2165 + * @since 6.8.3
2166 + *
2167 + * @return array
2168 + */
2169 + public static function get_supported_upload_file_types() {
2170 + $file_types = array( '.xml' );
2171 + if ( FrmAppHelper::pro_is_installed() ) {
2172 + // CSV Importing is only available in Pro.
2173 + $file_types[] = '.csv';
2174 + }
2175 + return $file_types;
2176 + }
2049 2177 }
2050 -