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 +194 -73 6.5.26.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;
@@ -317,9 +334,9 @@
317 334 $form_id = $this_form->id;
318 335 FrmForm::update( $form_id, $form );
319 336 if ( empty( $form['parent_form_id'] ) ) {
320 337 // Don't include the repeater form in the updated count.
321 - $imported['updated']['forms'] ++;
338 + ++$imported['updated']['forms'];
322 339 }
323 340
324 341 // Keep track of whether this specific form was updated or not
325 342 $imported['form_status'][ $form_id ] = 'updated';
@@ -380,10 +397,10 @@
380 397 * Keep track of all imported child forms
381 398 *
382 399 * @since 2.0.16
383 400 *
384 - * @param int $form_id
385 - * @param int $parent_form_id
401 + * @param int $form_id
402 + * @param int $parent_form_id
386 403 * @param array $child_forms
387 404 */
388 405 private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
389 406 if ( $parent_form_id ) {
@@ -435,13 +452,13 @@
435 452 if ( ! empty( $this_form ) ) {
436 453 // check for field to edit by field id
437 454 if ( isset( $form_fields[ $f['id'] ] ) ) {
438 455 FrmField::update( $f['id'], $f );
439 - $imported['updated']['fields'] ++;
456 + ++$imported['updated']['fields'];
440 457
441 458 unset( $form_fields[ $f['id'] ] );
442 459
443 - //unset old field key
460 + // Unset old field key.
444 461 if ( isset( $form_fields[ $f['field_key'] ] ) ) {
445 462 unset( $form_fields[ $f['field_key'] ] );
446 463 }
447 464 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
@@ -446,25 +463,32 @@
446 463 }
447 464 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
448 465 $keys_by_original_field_id[ $f['id'] ] = $f['field_key'];
449 466
467 + $old_field_id = $f['id'];
468 +
450 469 // check for field to edit by field key
451 470 unset( $f['id'] );
452 471
453 472 FrmField::update( $form_fields[ $f['field_key'] ], $f );
454 - $imported['updated']['fields'] ++;
473 + ++$imported['updated']['fields'];
455 474
456 - unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
457 - 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'] ] );
458 482 } else {
459 - // 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.
460 484 self::create_imported_field( $f, $imported );
461 - }
485 + }//end if
462 486 } else {
463 487
464 488 self::create_imported_field( $f, $imported );
465 - }
466 - }
489 + }//end if
490 + }//end foreach
467 491
468 492 if ( $keys_by_original_field_id ) {
469 493 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
470 494 }
@@ -469,8 +493,46 @@
469 493 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
470 494 }
471 495 }
472 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 +
473 535 private static function fill_field( $field, $form_id ) {
474 536 return array(
475 537 'id' => (int) $field->id,
476 538 'field_key' => (string) $field->field_key,
@@ -526,9 +588,9 @@
526 588 /**
527 589 * Update the current in_section value at the beginning of the field loop
528 590 *
529 591 * @since 2.0.25
530 - * @param int $in_section
592 + * @param int $in_section
531 593 * @param array $f
532 594 */
533 595 private static function maybe_update_in_section_variable( &$in_section, &$f ) {
534 596 // If we're at the end of a section, switch $in_section is 0
@@ -541,9 +603,9 @@
541 603 $f['field_options']['in_section'] = $in_section;
542 604 }
543 605
544 606 // If we're starting a new section, switch $in_section to ID of divider
545 - if ( $f['type'] == 'divider' ) {
607 + if ( $f['type'] === 'divider' ) {
546 608 $in_section = $f['id'];
547 609 }
548 610 }
549 611
@@ -559,9 +621,9 @@
559 621 if ( ! isset( $imported['forms'] ) ) {
560 622 return;
561 623 }
562 624
563 - 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' ) ) ) {
564 626 if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
565 627 $form_select = (int) $f['field_options']['form_select'];
566 628 if ( isset( $imported['forms'][ $form_select ] ) ) {
567 629 $f['field_options']['form_select'] = $imported['forms'][ $form_select ];
@@ -623,9 +685,9 @@
623 685 * @since 4.0
624 686 * @return array
625 687 */
626 688 public static function migrate_field_placeholder( $field, $type ) {
627 - $field = (array) $field;
689 + $field = (array) $field;
628 690 $field_options = $field['field_options'];
629 691 if ( empty( $field_options[ $type ] ) || empty( $field['default_value'] ) ) {
630 692 return array();
631 693 }
@@ -670,10 +732,9 @@
670 732 * @param array $f
671 733 * @param array $imported
672 734 */
673 735 private static function create_imported_field( $f, &$imported ) {
674 - $defaults = self::default_field_options( $f['type'] );
675 - $f['field_options'] = array_merge( $defaults, $f['field_options'] );
736 + $f = self::update_field_options_with_defaults( $f );
676 737
677 738 if ( is_callable( 'FrmProFileImport::import_attachment' ) ) {
678 739 $f = self::maybe_import_images_for_options( $f );
679 740 }
@@ -679,9 +740,9 @@
679 740 }
680 741
681 742 $new_id = FrmField::create( $f );
682 743 if ( $new_id != false ) {
683 - $imported['imported']['fields'] ++;
744 + ++$imported['imported']['fields'];
684 745 do_action( 'frm_after_field_is_imported', $f, $new_id );
685 746 }
686 747 }
687 748
@@ -702,13 +763,15 @@
702 763 if ( ! is_array( $option ) || empty( $option['src'] ) ) {
703 764 continue;
704 765 }
705 766
706 - $field_object = (object) $field;
707 - $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';
708 770
709 771 $image_id = FrmProFileImport::import_attachment( $option['src'], $field_object );
710 - 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'] );
711 774
712 775 if ( is_numeric( $image_id ) ) {
713 776 $field['options'][ $key ]['image'] = $image_id;
714 777 }
@@ -720,9 +783,9 @@
720 783 /**
721 784 * Fix field ids for fields that already exist prior to import.
722 785 *
723 786 * @since 4.07
724 - * @param int $form_id
787 + * @param int $form_id
725 788 * @param array $keys_by_original_field_id
726 789 */
727 790 protected static function maybe_update_field_ids( $form_id, $keys_by_original_field_id ) {
728 791 global $frm_duplicate_ids;
@@ -792,9 +855,9 @@
792 855
793 856 // Set to default
794 857 $form['options']['custom_style'] = 1;
795 858 }
796 - }
859 + }//end if
797 860 }
798 861
799 862 /**
800 863 * After styles are imported, check for any forms that were linked
@@ -816,8 +879,15 @@
816 879 }
817 880 }
818 881 }
819 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 + */
820 890 public static function import_xml_views( $views, $imported ) {
821 891 $imported['posts'] = array();
822 892 $form_action_type = FrmFormActionsController::$action_post_type;
823 893
@@ -863,9 +933,9 @@
863 933
864 934 $post_id = false;
865 935 if ( $post['post_type'] === $form_action_type ) {
866 936 $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
867 - if ( $action_control && is_object( $action_control ) ) {
937 + if ( $action_control && is_object( $action_control ) && isset( $imported['form_status'] ) ) {
868 938 $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
869 939 }
870 940 unset( $action_control );
871 941 } elseif ( $post['post_type'] === 'frm_styles' ) {
@@ -871,8 +941,10 @@
871 941 } elseif ( $post['post_type'] === 'frm_styles' ) {
872 942 // Properly encode post content before inserting the post
873 943 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
874 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'];
875 947
876 948 // Create/update post now
877 949 $post_id = wp_insert_post( $post );
878 950 } else {
@@ -882,9 +954,9 @@
882 954 $post['post_parent'] = $imported['posts'][ $post['post_parent'] ];
883 955 }
884 956 // Create/update post now
885 957 $post_id = wp_insert_post( $post );
886 - }
958 + }//end if
887 959
888 960 if ( ! is_numeric( $post_id ) ) {
889 961 continue;
890 962 }
@@ -901,23 +973,23 @@
901 973 $this_type = $post_types[ $post['post_type'] ];
902 974 }
903 975
904 976 if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
905 - $imported['updated'][ $this_type ] ++;
977 + ++$imported['updated'][ $this_type ];
906 978 } else {
907 - $imported['imported'][ $this_type ] ++;
979 + ++$imported['imported'][ $this_type ];
908 980 }
909 981
910 - $imported['posts'][ (int) $old_id ] = $post_id;
982 + $imported['posts'][ $old_id ] = $post_id;
911 983
912 984 if ( $post['post_type'] === 'frm_display' ) {
913 - $view_ids[ (int) $old_id ] = $post_id;
985 + $view_ids[ $old_id ] = $post_id;
914 986 }
915 987
916 988 do_action( 'frm_after_import_view', $post_id, $post );
917 989
918 990 unset( $post );
919 - }
991 + }//end foreach
920 992
921 993 if ( $posts_with_shortcodes && $view_ids ) {
922 994 self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
923 995 }
@@ -941,9 +1013,9 @@
941 1013 * @param array $imported_forms
942 1014 */
943 1015 private static function clear_forms_style_caches( $imported_forms ) {
944 1016 $where = array(
945 - 'id' => $imported_forms,
1017 + 'id' => $imported_forms,
946 1018 'options LIKE' => '"old_style"',
947 1019 );
948 1020 $forms = FrmDb::get_results( 'frm_forms', $where );
949 1021
@@ -1108,9 +1180,9 @@
1108 1180 'key' => (string) $meta->meta_key,
1109 1181 'value' => (string) $meta->meta_value,
1110 1182 );
1111 1183
1112 - //switch old form and field ids to new ones
1184 + // Switch old form and field ids to new ones.
1113 1185 if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
1114 1186 $m['value'] = $imported['forms'][ (int) $m['value'] ];
1115 1187 } else {
1116 1188 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
@@ -1126,10 +1198,36 @@
1126 1198 $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
1127 1199 }
1128 1200 }
1129 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 +
1130 1228 $check_dup_array = array();
1131 - if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
1229 + if ( ! empty( $m['value']['order_by'] ) ) {
1132 1230 if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
1133 1231 $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
1134 1232 } elseif ( is_array( $m['value']['order_by'] ) ) {
1135 1233 $check_dup_array[] = 'order_by';
@@ -1135,9 +1233,9 @@
1135 1233 $check_dup_array[] = 'order_by';
1136 1234 }
1137 1235 }
1138 1236
1139 - if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
1237 + if ( ! empty( $m['value']['where'] ) ) {
1140 1238 $check_dup_array[] = 'where';
1141 1239 }
1142 1240
1143 1241 foreach ( $check_dup_array as $check_k ) {
@@ -1147,11 +1245,11 @@
1147 1245 }
1148 1246 unset( $mk, $mv );
1149 1247 }
1150 1248 }
1151 - }
1152 - }
1153 - }
1249 + }//end if
1250 + }//end if
1251 + }//end if
1154 1252
1155 1253 if ( ! is_array( $m['value'] ) ) {
1156 1254 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
1157 1255 }
@@ -1165,10 +1263,10 @@
1165 1263
1166 1264 /**
1167 1265 * Add terms to post
1168 1266 *
1169 - * @param array $post by reference
1170 - * @param object $item The XML object data
1267 + * @param array $post By reference.
1268 + * @param object $item The XML object data.
1171 1269 */
1172 1270 private static function populate_taxonomies( &$post, $item ) {
1173 1271 foreach ( $item->category as $c ) {
1174 1272 $att = $c->attributes();
@@ -1193,13 +1291,13 @@
1193 1291 }
1194 1292
1195 1293 $post['tax_input'][ $taxonomy ][] = $name;
1196 1294 unset( $name );
1197 - }
1295 + }//end foreach
1198 1296 }
1199 1297
1200 1298 /**
1201 - * Edit post if the key and created time match
1299 + * Edit post if the key and created time match.
1202 1300 */
1203 1301 private static function maybe_editing_post( &$post ) {
1204 1302 $match_by = array(
1205 1303 'post_type' => $post['post_type'],
@@ -1207,9 +1305,9 @@
1207 1305 'post_status' => $post['post_status'],
1208 1306 'posts_per_page' => 1,
1209 1307 );
1210 1308
1211 - if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
1309 + if ( in_array( $post['post_status'], array( 'trash', 'draft' ), true ) ) {
1212 1310 $match_by['include'] = $post['post_id'];
1213 1311 unset( $match_by['name'] );
1214 1312 }
1215 1313
@@ -1249,13 +1347,13 @@
1249 1347
1250 1348 case 'frm_param':
1251 1349 add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES );
1252 1350 break;
1253 - }
1351 + }//end switch
1254 1352
1255 1353 update_post_meta( $post_id, $k, $v );
1256 1354 unset( $k, $v );
1257 - }
1355 + }//end foreach
1258 1356 }
1259 1357
1260 1358 /**
1261 1359 * @param array $post
@@ -1271,10 +1369,10 @@
1271 1369 }
1272 1370 }
1273 1371
1274 1372 private static function maybe_update_stylesheet( $imported ) {
1275 - $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
1276 - $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
1373 + $new_styles = ! empty( $imported['imported']['styles'] );
1374 + $updated_styles = ! empty( $imported['updated']['styles'] );
1277 1375 if ( $new_styles || $updated_styles ) {
1278 1376 if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
1279 1377 $frm_style = new FrmStyle();
1280 1378 $frm_style->update( 'default' );
@@ -1285,9 +1383,11 @@
1285 1383 }
1286 1384 }
1287 1385
1288 1386 /**
1387 + * @param mixed $result
1289 1388 * @param string $message
1389 + * @param array $errors
1290 1390 */
1291 1391 public static function parse_message( $result, &$message, &$errors ) {
1292 1392 if ( is_wp_error( $result ) ) {
1293 1393 $errors[] = $result->get_error_message();
@@ -1293,9 +1393,9 @@
1293 1393 $errors[] = $result->get_error_message();
1294 1394
1295 1395 // Remove the SimpleXML_parse_error from the WP_Error object to avoid
1296 1396 // displaying duplicate error messages from $result->get_error_message()
1297 - $error_codes = $result->get_error_codes();
1397 + $error_codes = $result->get_error_codes();
1298 1398 $error_details = array();
1299 1399 foreach ( $error_codes as $error_code ) {
1300 1400 // Clone WP_Error data because WP_Error removes all error messages and data
1301 1401 // associated with the specified error code when an item is removed.
@@ -1311,15 +1411,16 @@
1311 1411 $errors[] = '<br />' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '<br />' . esc_html( print_r( $error_details, 1 ) );
1312 1412 }
1313 1413
1314 1414 return;
1315 - } elseif ( ! $result ) {
1415 + }//end if
1416 +
1417 + if ( ! $result ) {
1316 1418 return;
1317 1419 }
1318 1420
1319 1421 if ( ! is_array( $result ) ) {
1320 1422 $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) );
1321 -
1322 1423 return;
1323 1424 }
1324 1425
1325 1426 $t_strings = array(
@@ -1346,9 +1447,9 @@
1346 1447 $message .= '</li>';
1347 1448 }
1348 1449 }
1349 1450
1350 - if ( $message == '<ul>' ) {
1451 + if ( $message === '<ul>' ) {
1351 1452 $message = '';
1352 1453 $errors[] = __( 'Nothing was imported or updated', 'formidable' );
1353 1454 } else {
1354 1455 self::add_form_link_to_message( $result, $message );
@@ -1652,9 +1753,13 @@
1652 1753
1653 1754 /**
1654 1755 * Migrate post settings to form action
1655 1756 *
1757 + * @param array $form_options
1758 + * @param int $form_id
1656 1759 * @param string $post_type
1760 + * @param array $imported
1761 + * @param bool $switch
1657 1762 */
1658 1763 private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
1659 1764 if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
1660 1765 return;
@@ -1723,9 +1828,9 @@
1723 1828
1724 1829 if ( ! $exists ) {
1725 1830 // this isn't an email, but we need to use a class that will always be included
1726 1831 FrmDb::save_json_post( $new_action );
1727 - $imported['imported']['actions'] ++;
1832 + ++$imported['imported']['actions'];
1728 1833 }
1729 1834 }
1730 1835
1731 1836 /**
@@ -1732,11 +1837,11 @@
1732 1837 * Switch old field IDs for new field IDs in emails and post
1733 1838 *
1734 1839 * @since 2.0
1735 1840 *
1736 - * @param array $post_content - check for old field IDs
1737 - * @param array $basic_fields - fields with string or int saved
1738 - * @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.
1739 1844 *
1740 1845 * @return string $post_content - new field IDs
1741 1846 */
1742 1847 private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
@@ -1817,12 +1922,12 @@
1817 1922 );
1818 1923
1819 1924 if ( empty( $exists ) ) {
1820 1925 FrmDb::save_json_post( $new_notification );
1821 - $imported['imported']['actions'] ++;
1926 + ++$imported['imported']['actions'];
1822 1927 }
1823 1928 unset( $new_notification );
1824 - }
1929 + }//end foreach
1825 1930
1826 1931 self::remove_deprecated_notification_settings( $form_id, $form_options );
1827 1932 }
1828 1933
@@ -1831,9 +1936,9 @@
1831 1936 *
1832 1937 * @since 2.05
1833 1938 *
1834 1939 * @param int|string $form_id
1835 - * @param array $form_options
1940 + * @param array $form_options
1836 1941 */
1837 1942 private static function remove_deprecated_notification_settings( $form_id, $form_options ) {
1838 1943 $delete_settings = array( 'notification', 'autoresponder', 'email_to' );
1839 1944 foreach ( $delete_settings as $index ) {
@@ -1844,9 +1949,9 @@
1844 1949 FrmForm::update( $form_id, array( 'options' => $form_options ) );
1845 1950 }
1846 1951
1847 1952 private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
1848 - 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'] ) ) {
1849 1954 // add old settings into notification array
1850 1955 $form_options['notification'] = array( 0 => $form_options );
1851 1956 } elseif ( isset( $form_options['notification']['email_to'] ) ) {
1852 1957 // make sure it's in the correct format
@@ -1876,10 +1981,10 @@
1876 1981 $new_notification = array();
1877 1982 self::setup_new_notification( $new_notification, $notification, $atts );
1878 1983
1879 1984 $notifications[] = $new_notification;
1880 - }
1881 - }
1985 + }//end foreach
1986 + }//end if
1882 1987 }
1883 1988
1884 1989 private static function format_email_data( &$atts, $notification ) {
1885 1990 // Format email_to
@@ -1975,9 +2080,9 @@
1975 2080
1976 2081 /**
1977 2082 * Switch field IDs in pre-2.0 email conditional logic
1978 2083 *
1979 - * @param $post_content array, pass by reference
2084 + * @param array $post_content Pass by reference.
1980 2085 */
1981 2086 private static function switch_email_condition_field_ids( &$post_content ) {
1982 2087 // Switch field IDs in conditional logic
1983 2088 if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
@@ -2030,17 +2135,17 @@
2030 2135 }
2031 2136
2032 2137 $notifications[] = $new_notification2;
2033 2138 unset( $new_notification2 );
2034 - }
2139 + }//end if
2035 2140 }
2036 2141
2037 2142 /**
2038 2143 * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2039 2144 *
2040 - * @param boolean $disable
2145 + * @param bool $loader
2041 2146 *
2042 - * @return boolean
2147 + * @return bool
2043 2148 */
2044 2149 public static function maybe_libxml_disable_entity_loader( $loader ) {
2045 2150 if ( version_compare( phpversion(), '8.0', '<' ) && function_exists( 'libxml_disable_entity_loader' ) ) {
2046 2151 $loader = libxml_disable_entity_loader( $loader ); // phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
@@ -2051,6 +2156,22 @@
2051 2156
2052 2157 public static function check_if_libxml_disable_entity_loader_exists() {
2053 2158 return version_compare( phpversion(), '8.0', '<' ) && ! function_exists( 'libxml_disable_entity_loader' );
2054 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 + }
2055 2177 }
2056 -