PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2.2
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 +334 -848 6.31 → 6.2.2 View file →
@@ -5,18 +5,12 @@
5 5
6 6 class FrmXMLHelper {
7 7
8 8 /**
9 - * @var bool true if importing an XML from API, false if importing an XML file manually.
9 + * @var bool $installing_template 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 - /**
14 - * @param array|string $opt
15 - * @param string $padding
16 - *
17 - * @return void
18 - */
19 13 public static function get_xml_values( $opt, $padding ) {
20 14 if ( is_array( $opt ) ) {
21 15 foreach ( $opt as $ok => $ov ) {
22 16 echo "\n" . esc_html( $padding );
@@ -22,9 +16,8 @@
22 16 echo "\n" . esc_html( $padding );
23 17 $tag = ( is_numeric( $ok ) ? 'key:' : '' ) . $ok;
24 18 echo '<' . esc_html( $tag ) . '>';
25 19 self::get_xml_values( $ov, $padding . ' ' );
26 -
27 20 if ( is_array( $ov ) ) {
28 21 echo "\n" . esc_html( $padding );
29 22 }
30 23 echo '</' . esc_html( $tag ) . '>';
@@ -33,13 +26,8 @@
33 26 echo self::cdata( $opt ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
34 27 }
35 28 }
36 29
37 - /**
38 - * @param string $file
39 - *
40 - * @return array|WP_Error The items imported
41 - */
42 30 public static function import_xml( $file ) {
43 31 if ( ! defined( 'WP_IMPORTING' ) ) {
44 32 define( 'WP_IMPORTING', true );
45 33 }
@@ -44,26 +32,15 @@
44 32 define( 'WP_IMPORTING', true );
45 33 }
46 34
47 35 if ( ! class_exists( 'DOMDocument' ) ) {
48 - $error_message = sprintf(
49 - /* translators: 1: Documentation link */
50 - __( 'In order to install XML, your server must have DOMDocument installed. Follow our documentation on %1$s to ensure DOMDocument is properly set up and XML support is enabled.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
51 - '<a href="https://formidableforms.com/knowledgebase/import-forms-entries-and-views/#kb-your-server-does-not-have-xml-enabled" target="_blank">Importing Forms, Entries, and Views</a>' // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
52 - );
53 -
54 - return new WP_Error( 'SimpleXML_parse_error', $error_message, libxml_get_errors() );
36 + return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
55 37 }
56 38
57 - $xml_string = file_get_contents( $file );
58 - self::maybe_fix_xml( $xml_string );
59 -
60 39 $dom = new DOMDocument();
61 -
62 40 // LIBXML_COMPACT activates small nodes allocation optimization.
63 41 // Use LIBXML_PARSEHUGE to avoid "parser error : internal error: Huge input lookup" for large (300MB) files.
64 - $success = $dom->loadXML( $xml_string, LIBXML_COMPACT | LIBXML_PARSEHUGE );
65 -
42 + $success = $dom->loadXML( file_get_contents( $file ), LIBXML_COMPACT | LIBXML_PARSEHUGE );
66 43 if ( ! $success ) {
67 44 return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
68 45 }
69 46
@@ -73,9 +50,9 @@
73 50
74 51 $xml = simplexml_import_dom( $dom );
75 52 unset( $dom );
76 53
77 - // Halt if loading produces an error
54 + // halt if loading produces an error
78 55 if ( ! $xml ) {
79 56 return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
80 57 }
81 58
@@ -82,39 +59,8 @@
82 59 return self::import_xml_now( $xml );
83 60 }
84 61
85 62 /**
86 - * @since 6.2.3
87 - *
88 - * @param string $xml_string
89 - *
90 - * @return void
91 - */
92 - private static function maybe_fix_xml( &$xml_string ) {
93 - if ( ! str_starts_with( $xml_string, '<?xml' ) ) {
94 - // Some XML files have may have unexpected characters at the start.
95 - $xml_string = substr( $xml_string, strpos( $xml_string, '<?xml' ) );
96 - }
97 -
98 - // The Equity theme adds a <meta name="generator" content="Equity 1.7.13" /> tag using the "the_generator" filter.
99 - // Strip that out as it breaks the XML import.
100 - $channel_start_position = strpos( $xml_string, '<channel>' );
101 - $content_before_channel_tag = substr( $xml_string, 0, $channel_start_position );
102 -
103 - if ( str_starts_with( $content_before_channel_tag, '<meta name="generator" ' ) ) {
104 - return;
105 - }
106 -
107 - $content_before_channel_tag = preg_replace(
108 - '/<meta\s+[^>]*name="generator"[^>]*\/>/i',
109 - '',
110 - $content_before_channel_tag,
111 - 1
112 - );
113 - $xml_string = $content_before_channel_tag . substr( $xml_string, $channel_start_position );
114 - }
115 -
116 - /**
117 63 * Add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
118 64 *
119 65 * @since 3.06
120 66 *
@@ -119,9 +65,8 @@
119 65 * @since 3.06
120 66 *
121 67 * @param object $xml
122 68 * @param bool $installing_template
123 - *
124 69 * @return array The number of items imported
125 70 */
126 71 public static function import_xml_now( $xml, $installing_template = false ) {
127 72 if ( ! defined( 'WP_IMPORTING' ) ) {
@@ -132,20 +77,18 @@
132 77 $imported = self::pre_import_data();
133 78
134 79 foreach ( array( 'term', 'form', 'view' ) as $item_type ) {
135 80 // Grab cats, tags, and terms, or forms or posts.
136 - if ( ! isset( $xml->{$item_type} ) ) {
137 - continue;
81 + if ( isset( $xml->{$item_type} ) ) {
82 + $function_name = 'import_xml_' . $item_type . 's';
83 + $imported = self::$function_name( $xml->{$item_type}, $imported );
84 + unset( $function_name, $xml->{$item_type} );
138 85 }
139 -
140 - $function_name = 'import_xml_' . $item_type . 's';
141 - $imported = self::$function_name( $xml->{$item_type}, $imported );
142 - unset( $function_name, $xml->{$item_type} );
143 86 }
144 87
145 88 $imported = apply_filters( 'frm_importing_xml', $imported, $xml );
146 89
147 - if ( empty( $imported['form_status'] ) ) {
90 + if ( ! isset( $imported['form_status'] ) || empty( $imported['form_status'] ) ) {
148 91 // Check for an error message in the XML.
149 92 if ( isset( $xml->Code ) && isset( $xml->Message ) ) { // phpcs:ignore WordPress.NamingConventions
150 93 $imported['error'] = (string) $xml->Message; // phpcs:ignore WordPress.NamingConventions
151 94 }
@@ -155,9 +98,8 @@
155 98 }
156 99
157 100 /**
158 101 * @since 3.06
159 - *
160 102 * @return array
161 103 */
162 104 private static function pre_import_data() {
163 105 $defaults = array(
@@ -177,14 +119,8 @@
177 119 'terms' => array(),
178 120 );
179 121 }
180 122
181 - /**
182 - * @param SimpleXMLElement $terms
183 - * @param array $imported
184 - *
185 - * @return array
186 - */
187 123 public static function import_xml_terms( $terms, $imported ) {
188 124 foreach ( $terms as $t ) {
189 125 if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) {
190 126 continue;
@@ -197,19 +133,19 @@
197 133 (string) $t->term_taxonomy,
198 134 array(
199 135 'slug' => (string) $t->term_slug,
200 136 'description' => (string) $t->term_description,
201 - 'parent' => $parent ? $parent : 0,
137 + 'parent' => empty( $parent ) ? 0 : $parent,
202 138 )
203 139 );
204 140
205 141 if ( $term && is_array( $term ) ) {
206 - ++$imported['imported']['terms'];
142 + $imported['imported']['terms'] ++;
207 143 $imported['terms'][ (int) $t->term_id ] = $term['term_id'];
208 144 }
209 145
210 146 unset( $term, $t );
211 - }//end foreach
147 + }
212 148
213 149 return $imported;
214 150 }
215 151
@@ -214,30 +150,23 @@
214 150 }
215 151
216 152 /**
217 153 * @since 2.0.8
218 - *
219 - * @param object $t
220 - *
221 - * @return int|string
222 154 */
223 155 private static function get_term_parent_id( $t ) {
224 156 $parent = (string) $t->term_parent;
225 -
226 - if ( $parent ) {
157 + if ( ! empty( $parent ) ) {
227 158 $parent = term_exists( (string) $t->term_parent, (string) $t->term_taxonomy );
228 - $parent = $parent ? $parent['term_id'] : 0;
159 + if ( $parent ) {
160 + $parent = $parent['term_id'];
161 + } else {
162 + $parent = 0;
163 + }
229 164 }
230 165
231 166 return $parent;
232 167 }
233 168
234 - /**
235 - * @param SimpleXMLElement $forms
236 - * @param array $imported
237 - *
238 - * @return array
239 - */
240 169 public static function import_xml_forms( $forms, $imported ) {
241 170 $child_forms = array();
242 171
243 172 // Import child forms first
@@ -247,13 +176,13 @@
247 176 $form = self::fill_form( $item );
248 177
249 178 self::update_custom_style_setting_on_import( $form );
250 179
251 - $this_form = self::maybe_get_form( $form );
180 + $this_form = self::maybe_get_form( $form );
181 +
252 182 $old_id = false;
253 183 $form_fields = false;
254 -
255 - if ( $this_form ) {
184 + if ( ! empty( $this_form ) ) {
256 185 $form_id = $this_form->id;
257 186 $old_id = $this_form->id;
258 187 self::update_form( $this_form, $form, $imported );
259 188
@@ -259,13 +188,12 @@
259 188
260 189 $form_fields = self::get_form_fields( $form_id );
261 190 } else {
262 191 $form_id = FrmForm::create( $form );
263 -
264 192 if ( $form_id ) {
265 193 if ( empty( $form['parent_form_id'] ) ) {
266 194 // Don't include the repeater form in the imported count.
267 - ++$imported['imported']['forms'];
195 + $imported['imported']['forms'] ++;
268 196 }
269 197
270 198 // Keep track of whether this specific form was updated or not.
271 199 $imported['form_status'][ $form_id ] = 'imported';
@@ -290,35 +218,15 @@
290 218
291 219 do_action( 'frm_after_import_form', $form_id, $form );
292 220
293 221 unset( $form, $item );
294 - }//end foreach
222 + }
295 223
296 224 self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
297 225
298 - /**
299 - * Fires after all forms in the XML have been imported.
300 - *
301 - * Child forms are imported before their parent form, so per-form fix-ups
302 - * cannot resolve conditional logic that references fields in a form
303 - * imported later. Use this action for cross-form fix-ups that require
304 - * the fully populated `$frm_duplicate_ids` map.
305 - *
306 - * @since 6.31
307 - *
308 - * @param array $imported Summary of imported items, including
309 - * 'forms' => array( old_form_id => new_form_id ).
310 - */
311 - do_action( 'frm_after_import_forms', $imported );
312 -
313 226 return $imported;
314 227 }
315 228
316 - /**
317 - * @param object $item
318 - *
319 - * @return array
320 - */
321 229 private static function fill_form( $item ) {
322 230 $form = array(
323 231 'id' => (int) $item->id,
324 232 'form_key' => (string) $item->form_key,
@@ -346,49 +254,29 @@
346 254
347 255 return $form;
348 256 }
349 257
350 - /**
351 - * @param array $form
352 - *
353 - * @return false|object
354 - */
355 258 private static function maybe_get_form( $form ) {
356 - // If template, allow to edit if form keys match, otherwise, creation date must also match
259 + // if template, allow to edit if form keys match, otherwise, creation date must also match
357 260 $edit_query = array(
358 261 'form_key' => $form['form_key'],
359 262 'is_template' => $form['is_template'],
360 263 );
361 -
362 264 if ( ! $form['is_template'] ) {
363 265 $edit_query['created_at'] = $form['created_at'];
364 266 }
365 267
366 268 $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form );
367 - $form = FrmForm::getAll( $edit_query, '', 1 );
368 269
369 - if ( is_object( $form ) && $form->status === 'trash' ) {
370 - FrmForm::destroy( $form->id );
371 - return false;
372 - }
373 -
374 - return $form;
270 + return FrmForm::getAll( $edit_query, '', 1 );
375 271 }
376 272
377 - /**
378 - * @param object $this_form
379 - * @param array $form
380 - * @param array $imported
381 - *
382 - * @return void
383 - */
384 273 private static function update_form( $this_form, $form, &$imported ) {
385 274 $form_id = $this_form->id;
386 275 FrmForm::update( $form_id, $form );
387 -
388 276 if ( empty( $form['parent_form_id'] ) ) {
389 277 // Don't include the repeater form in the updated count.
390 - ++$imported['updated']['forms'];
278 + $imported['updated']['forms'] ++;
391 279 }
392 280
393 281 // Keep track of whether this specific form was updated or not
394 282 $imported['form_status'][ $form_id ] = 'updated';
@@ -393,43 +281,32 @@
393 281 // Keep track of whether this specific form was updated or not
394 282 $imported['form_status'][ $form_id ] = 'updated';
395 283 }
396 284
397 - /**
398 - * @param int|string $form_id
399 - *
400 - * @return array
401 - */
402 285 private static function get_form_fields( $form_id ) {
403 286 $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
404 287 $old_fields = array();
405 -
406 288 foreach ( $form_fields as $f ) {
407 289 $old_fields[ $f->id ] = $f;
408 290 $old_fields[ $f->field_key ] = $f->id;
409 291 unset( $f );
410 292 }
293 + $form_fields = $old_fields;
411 294
412 - return $old_fields;
295 + return $form_fields;
413 296 }
414 297
415 298 /**
416 299 * Delete any fields attached to this form that were not included in the template
417 - *
418 - * @param array $form_fields
419 - *
420 - * @return void
421 300 */
422 301 private static function delete_removed_fields( $form_fields ) {
423 - if ( ! $form_fields ) {
424 - return;
425 - }
426 -
427 - foreach ( $form_fields as $field ) {
428 - if ( is_object( $field ) ) {
429 - FrmField::destroy( $field->id );
302 + if ( ! empty( $form_fields ) ) {
303 + foreach ( $form_fields as $field ) {
304 + if ( is_object( $field ) ) {
305 + FrmField::destroy( $field->id );
306 + }
307 + unset( $field );
430 308 }
431 - unset( $field );
432 309 }
433 310 }
434 311
435 312 /**
@@ -460,10 +337,10 @@
460 337 * Keep track of all imported child forms
461 338 *
462 339 * @since 2.0.16
463 340 *
464 - * @param int $form_id
465 - * @param int $parent_form_id
341 + * @param int $form_id
342 + * @param int $parent_form_id
466 343 * @param array $child_forms
467 344 */
468 345 private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
469 346 if ( $parent_form_id ) {
@@ -481,16 +358,14 @@
481 358 * @param array $child_forms
482 359 */
483 360 private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) {
484 361 foreach ( $child_forms as $child_form_id => $old_parent_form_id ) {
485 - if ( ! isset( $imported_forms[ $old_parent_form_id ] ) || (int) $imported_forms[ $old_parent_form_id ] === (int) $old_parent_form_id ) {
486 - continue;
362 + if ( isset( $imported_forms[ $old_parent_form_id ] ) && (int) $imported_forms[ $old_parent_form_id ] !== (int) $old_parent_form_id ) {
363 + // Update all children with this old parent_form_id
364 + $new_parent_form_id = (int) $imported_forms[ $old_parent_form_id ];
365 + FrmForm::update( $child_form_id, array( 'parent_form_id' => $new_parent_form_id ) );
366 + do_action( 'frm_update_child_form_parent_id', $child_form_id, $new_parent_form_id );
487 367 }
488 -
489 - // Update all children with this old parent_form_id
490 - $new_parent_form_id = (int) $imported_forms[ $old_parent_form_id ];
491 - FrmForm::update( $child_form_id, array( 'parent_form_id' => $new_parent_form_id ) );
492 - do_action( 'frm_update_child_form_parent_id', $child_form_id, $new_parent_form_id );
493 368 }
494 369 }
495 370
496 371 /**
@@ -498,14 +373,8 @@
498 373 *
499 374 * @since 2.0.13
500 375 *
501 376 * TODO: Cut down on params
502 - *
503 - * @param SimpleXMLElement $xml_fields
504 - * @param int|string $form_id
505 - * @param object $this_form
506 - * @param array $form_fields
507 - * @param array $imported
508 377 */
509 378 private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) {
510 379 $in_section = 0;
511 380 $keys_by_original_field_id = array();
@@ -519,45 +388,40 @@
519 388 self::maybe_update_form_select( $f, $imported );
520 389 self::maybe_update_get_values_form_setting( $imported, $f );
521 390 self::migrate_placeholders( $f );
522 391
523 - if ( $this_form ) {
524 - // Check for field to edit by field id
392 + if ( ! empty( $this_form ) ) {
393 + // check for field to edit by field id
525 394 if ( isset( $form_fields[ $f['id'] ] ) ) {
526 395 FrmField::update( $f['id'], $f );
527 - ++$imported['updated']['fields'];
396 + $imported['updated']['fields'] ++;
528 397
529 398 unset( $form_fields[ $f['id'] ] );
530 399
531 - // Unset old field key.
400 + //unset old field key
532 401 if ( isset( $form_fields[ $f['field_key'] ] ) ) {
533 402 unset( $form_fields[ $f['field_key'] ] );
534 403 }
535 404 } elseif ( isset( $form_fields[ $f['field_key'] ] ) ) {
536 405 $keys_by_original_field_id[ $f['id'] ] = $f['field_key'];
537 - $old_field_id = $f['id'];
538 406
539 - // Check for field to edit by field key
407 + // check for field to edit by field key
540 408 unset( $f['id'] );
541 409
542 410 FrmField::update( $form_fields[ $f['field_key'] ], $f );
543 - ++$imported['updated']['fields'];
411 + $imported['updated']['fields'] ++;
544 412
545 - self::do_after_field_imported_action( $f, $form_fields, $old_field_id );
546 -
547 - // Unset old field id.
548 - unset( $form_fields[ $form_fields[ $f['field_key'] ] ] );
549 -
550 - // Unset old field key.
551 - unset( $form_fields[ $f['field_key'] ] );
413 + unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
414 + unset( $form_fields[ $f['field_key'] ] ); //unset old field key
552 415 } else {
553 - // If no matching field id or key in this form, create the field.
416 + // if no matching field id or key in this form, create the field
554 417 self::create_imported_field( $f, $imported );
555 - }//end if
418 + }
556 419 } else {
420 +
557 421 self::create_imported_field( $f, $imported );
558 - }//end if
559 - }//end foreach
422 + }
423 + }
560 424
561 425 if ( $keys_by_original_field_id ) {
562 426 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
563 427 }
@@ -562,53 +426,8 @@
562 426 self::maybe_update_field_ids( $form_id, $keys_by_original_field_id );
563 427 }
564 428 }
565 429
566 - /**
567 - * @since 6.8.4
568 - *
569 - * @param array $field_array
570 - *
571 - * @return array
572 - */
573 - private static function update_field_options_with_defaults( $field_array ) {
574 - $defaults = self::default_field_options( $field_array['type'] );
575 - $field_array['field_options'] = array_merge( $defaults, $field_array['field_options'] );
576 -
577 - return $field_array;
578 - }
579 -
580 - /**
581 - * @since 6.8.4
582 - *
583 - * @param array $field_array
584 - * @param array $form_fields
585 - * @param int $old_field_id
586 - *
587 - * @return void
588 - */
589 - private static function do_after_field_imported_action( $field_array, $form_fields, $old_field_id ) {
590 - // Assign field array the update field's ID.
591 - $field_array['id'] = $form_fields[ $field_array['field_key'] ];
592 -
593 - /**
594 - * Fires when an existing field is imported.
595 - *
596 - * @since 6.8.4
597 - *
598 - * @param array $field_array
599 - * @param int $field_id
600 - * @param int $old_field_id
601 - */
602 - do_action( 'frm_after_existing_field_is_imported', $field_array, $form_fields[ $field_array['field_key'] ], $old_field_id );
603 - }
604 -
605 - /**
606 - * @param object $field
607 - * @param int|string $form_id
608 - *
609 - * @return array
610 - */
611 430 private static function fill_field( $field, $form_id ) {
612 431 return array(
613 432 'id' => (int) $field->id,
614 433 'field_key' => (string) $field->field_key,
@@ -625,12 +444,8 @@
625 444 }
626 445
627 446 /**
628 447 * @since 4.06
629 - *
630 - * @param array $f
631 - *
632 - * @return void
633 448 */
634 449 private static function set_default_value( &$f ) {
635 450 $has_default = array(
636 451 'text',
@@ -644,17 +459,15 @@
644 459 'password',
645 460 'tag',
646 461 );
647 462
648 - if ( ! is_array( $f['default_value'] ) || ! in_array( $f['type'], $has_default, true ) ) {
649 - return;
463 + if ( is_array( $f['default_value'] ) && in_array( $f['type'], $has_default, true ) ) {
464 + if ( count( $f['default_value'] ) === 1 ) {
465 + $f['default_value'] = '[' . reset( $f['default_value'] ) . ']';
466 + } else {
467 + $f['default_value'] = reset( $f['default_value'] );
468 + }
650 469 }
651 -
652 - if ( count( $f['default_value'] ) === 1 ) {
653 - $f['default_value'] = '[' . reset( $f['default_value'] ) . ']';
654 - } else {
655 - $f['default_value'] = reset( $f['default_value'] );
656 - }
657 470 }
658 471
659 472 /**
660 473 * Make sure the required indicator is set.
@@ -659,12 +472,8 @@
659 472 /**
660 473 * Make sure the required indicator is set.
661 474 *
662 475 * @since 4.05
663 - *
664 - * @param array $f
665 - *
666 - * @return void
667 476 */
668 477 private static function maybe_add_required( &$f ) {
669 478 if ( $f['required'] && ! isset( $f['field_options']['required_indicator'] ) ) {
670 479 $f['field_options']['required_indicator'] = '*';
@@ -674,17 +483,14 @@
674 483 /**
675 484 * Update the current in_section value at the beginning of the field loop
676 485 *
677 486 * @since 2.0.25
678 - *
679 - * @param int $in_section
487 + * @param int $in_section
680 488 * @param array $f
681 - *
682 - * @return void
683 489 */
684 490 private static function maybe_update_in_section_variable( &$in_section, &$f ) {
685 491 // If we're at the end of a section, switch $in_section is 0
686 - if ( in_array( $f['type'], array( 'end_divider', 'break', 'form' ), true ) ) {
492 + if ( in_array( $f['type'], array( 'end_divider', 'break', 'form' ) ) ) {
687 493 $in_section = 0;
688 494 }
689 495
690 496 // Update the current field's in_section value
@@ -692,9 +498,9 @@
692 498 $f['field_options']['in_section'] = $in_section;
693 499 }
694 500
695 501 // If we're starting a new section, switch $in_section to ID of divider
696 - if ( $f['type'] === 'divider' ) {
502 + if ( $f['type'] == 'divider' ) {
697 503 $in_section = $f['id'];
698 504 }
699 505 }
700 506
@@ -710,21 +516,16 @@
710 516 if ( ! isset( $imported['forms'] ) ) {
711 517 return;
712 518 }
713 519
714 - if ( $f['type'] !== 'form' && ( $f['type'] !== 'divider' || ! FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
715 - return;
520 + if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
521 + if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
522 + $form_select = (int) $f['field_options']['form_select'];
523 + if ( isset( $imported['forms'][ $form_select ] ) ) {
524 + $f['field_options']['form_select'] = $imported['forms'][ $form_select ];
525 + }
526 + }
716 527 }
717 -
718 - if ( ! FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
719 - return;
720 - }
721 -
722 - $form_select = (int) $f['field_options']['form_select'];
723 -
724 - if ( isset( $imported['forms'][ $form_select ] ) ) {
725 - $f['field_options']['form_select'] = $imported['forms'][ $form_select ];
726 - }
727 528 }
728 529
729 530 /**
730 531 * Update the get_values_form setting if the form was imported
@@ -732,10 +533,8 @@
732 533 * @since 2.01.0
733 534 *
734 535 * @param array $imported
735 536 * @param array $f
736 - *
737 - * @return void
738 537 */
739 538 private static function maybe_update_get_values_form_setting( $imported, &$f ) {
740 539 if ( ! isset( $imported['forms'] ) ) {
741 540 return;
@@ -740,35 +539,36 @@
740 539 if ( ! isset( $imported['forms'] ) ) {
741 540 return;
742 541 }
743 542
744 - if ( ! FrmField::is_option_true_in_array( $f['field_options'], 'get_values_form' ) ) {
745 - return;
543 + if ( FrmField::is_option_true_in_array( $f['field_options'], 'get_values_form' ) ) {
544 + $old_form = $f['field_options']['get_values_form'];
545 + if ( isset( $imported['forms'][ $old_form ] ) ) {
546 + $f['field_options']['get_values_form'] = $imported['forms'][ $old_form ];
547 + }
746 548 }
549 + }
747 550
748 - $old_form = $f['field_options']['get_values_form'];
749 -
750 - if ( isset( $imported['forms'][ $old_form ] ) ) {
751 - $f['field_options']['get_values_form'] = $imported['forms'][ $old_form ];
752 - }
551 + /**
552 + * If field settings have been migrated, update the values during import.
553 + *
554 + * @since 4.0
555 + */
556 + private static function run_field_migrations( &$f ) {
557 + self::migrate_placeholders( $f );
558 + $f = apply_filters( 'frm_import_xml_field', $f );
753 559 }
754 560
755 561 /**
756 562 * @since 4.0
757 - *
758 - * @param array $f
759 - *
760 - * @return void
761 563 */
762 564 private static function migrate_placeholders( &$f ) {
763 565 $update_values = self::migrate_field_placeholder( $f, 'clear_on_focus' );
764 -
765 566 foreach ( $update_values as $k => $v ) {
766 567 $f[ $k ] = $v;
767 568 }
768 569
769 570 $update_values = self::migrate_field_placeholder( $f, 'default_blank' );
770 -
771 571 foreach ( $update_values as $k => $v ) {
772 572 $f[ $k ] = $v;
773 573 }
774 574 }
@@ -777,18 +577,13 @@
777 577 * Move clear_on_focus or default_blank to placeholder.
778 578 * Also called during database migration in FrmMigrate.
779 579 *
780 580 * @since 4.0
781 - *
782 - * @param array|object $field
783 - * @param string $type
784 - *
785 581 * @return array
786 582 */
787 583 public static function migrate_field_placeholder( $field, $type ) {
788 - $field = (array) $field;
584 + $field = (array) $field;
789 585 $field_options = $field['field_options'];
790 -
791 586 if ( empty( $field_options[ $type ] ) || empty( $field['default_value'] ) ) {
792 587 return array();
793 588 }
794 589
@@ -801,34 +596,27 @@
801 596 );
802 597
803 598 // If a dropdown placeholder was used, remove the option so it won't be included twice.
804 599 $options = $field['options'];
600 + if ( $type === 'default_blank' && is_array( $options ) ) {
601 + $default_value = $field['default_value'];
602 + if ( is_array( $default_value ) ) {
603 + $default_value = reset( $default_value );
604 + }
805 605
806 - if ( $type !== 'default_blank' || ! is_array( $options ) ) {
807 - return $changes;
808 - }
606 + foreach ( $options as $opt_key => $opt ) {
607 + if ( is_array( $opt ) ) {
608 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
609 + }
809 610
810 - $default_value = $field['default_value'];
811 -
812 - if ( is_array( $default_value ) ) {
813 - $default_value = reset( $default_value );
814 - }
815 -
816 - foreach ( $options as $opt_key => $opt ) {
817 - if ( is_array( $opt ) ) {
818 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
611 + if ( $opt == $default_value ) {
612 + unset( $options[ $opt_key ] );
613 + break;
614 + }
819 615 }
820 -
821 - // phpcs:ignore Universal.Operators.StrictComparisons
822 - if ( $opt == $default_value ) {
823 - unset( $options[ $opt_key ] );
824 - break;
825 - }
616 + $changes['options'] = $options;
826 617 }
827 618
828 - $changes['options'] = $options;
829 - // end if
830 -
831 619 return $changes;
832 620 }
833 621
834 622 /**
@@ -837,13 +625,12 @@
837 625 * @since 2.0.25
838 626 *
839 627 * @param array $f
840 628 * @param array $imported
841 - *
842 - * @return void
843 629 */
844 630 private static function create_imported_field( $f, &$imported ) {
845 - $f = self::update_field_options_with_defaults( $f );
631 + $defaults = self::default_field_options( $f['type'] );
632 + $f['field_options'] = array_merge( $defaults, $f['field_options'] );
846 633
847 634 if ( is_callable( 'FrmProFileImport::import_attachment' ) ) {
848 635 $f = self::maybe_import_images_for_options( $f );
849 636 }
@@ -848,15 +635,12 @@
848 635 $f = self::maybe_import_images_for_options( $f );
849 636 }
850 637
851 638 $new_id = FrmField::create( $f );
852 -
853 - if ( ! $new_id ) {
854 - return;
639 + if ( $new_id != false ) {
640 + $imported['imported']['fields'] ++;
641 + do_action( 'frm_after_field_is_imported', $f, $new_id );
855 642 }
856 -
857 - ++$imported['imported']['fields'];
858 - do_action( 'frm_after_field_is_imported', $f, $new_id );
859 643 }
860 644
861 645 /**
862 646 * Import images for radio buttons and checkboxes from image src if available.
@@ -863,9 +647,8 @@
863 647 *
864 648 * @since 5.5.1
865 649 *
866 650 * @param array $field
867 - *
868 651 * @return array
869 652 */
870 653 private static function maybe_import_images_for_options( $field ) {
871 654 if ( empty( $field['options'] ) || ! is_array( $field['options'] ) ) {
@@ -876,15 +659,13 @@
876 659 if ( ! is_array( $option ) || empty( $option['src'] ) ) {
877 660 continue;
878 661 }
879 662
880 - $field_object = (object) $field;
881 - // Fake the file type as FrmProImport::import_attachment checks for file type.
882 - $field_object->type = 'file';
663 + $field_object = (object) $field;
664 + $field_object->type = 'file'; // Fake the file type as FrmProImport::import_attachment checks for file type.
883 665
884 666 $image_id = FrmProFileImport::import_attachment( $option['src'], $field_object );
885 - // Remove the src from options as it isn't required after import.
886 - unset( $field['options'][ $key ]['src'] );
667 + unset( $field['options'][ $key ]['src'] ); // Remove the src from options as it isn't required after import.
887 668
888 669 if ( is_numeric( $image_id ) ) {
889 670 $field['options'][ $key ]['image'] = $image_id;
890 671 }
@@ -896,13 +677,10 @@
896 677 /**
897 678 * Fix field ids for fields that already exist prior to import.
898 679 *
899 680 * @since 4.07
900 - *
901 - * @param int $form_id
681 + * @param int $form_id
902 682 * @param array $keys_by_original_field_id
903 - *
904 - * @return void
905 683 */
906 684 protected static function maybe_update_field_ids( $form_id, $keys_by_original_field_id ) {
907 685 global $frm_duplicate_ids;
908 686
@@ -922,17 +700,15 @@
922 700 $field = (array) $field;
923 701 $frm_duplicate_ids = $keys_by_original_field_id;
924 702 $after = FrmFieldsHelper::switch_field_ids( $field );
925 703
926 - if ( $before['field_options'] === $after['field_options'] ) {
927 - continue;
928 - }
704 + if ( $before['field_options'] !== $after['field_options'] ) {
705 + $frm_duplicate_ids = $field_id_by_key;
706 + $after = FrmFieldsHelper::switch_field_ids( $after );
929 707
930 - $frm_duplicate_ids = $field_id_by_key;
931 - $after = FrmFieldsHelper::switch_field_ids( $after );
932 -
933 - if ( $before['field_options'] !== $after['field_options'] ) {
934 - FrmField::update( $field['id'], array( 'field_options' => $after['field_options'] ) );
708 + if ( $before['field_options'] !== $after['field_options'] ) {
709 + FrmField::update( $field['id'], array( 'field_options' => $after['field_options'] ) );
710 + }
935 711 }
936 712 }
937 713
938 714 $frm_duplicate_ids = $former_duplicate_ids;
@@ -944,10 +720,8 @@
944 720 *
945 721 * @since 2.0.19
946 722 *
947 723 * @param array $form
948 - *
949 - * @return void
950 724 */
951 725 private static function update_custom_style_setting_on_import( &$form ) {
952 726 if ( ! isset( $form['options']['custom_style'] ) ) {
953 727 return;
@@ -955,32 +729,29 @@
955 729
956 730 if ( is_numeric( $form['options']['custom_style'] ) && 1 === intval( $form['options']['custom_style'] ) ) {
957 731 // Set to default
958 732 $form['options']['custom_style'] = 1;
733 + } else {
734 + // Replace the style name with the style ID on import
735 + global $wpdb;
736 + $table = $wpdb->prefix . 'posts';
737 + $where = array(
738 + 'post_name' => $form['options']['custom_style'],
739 + 'post_type' => 'frm_styles',
740 + );
741 + $select = 'ID';
742 + $style_id = FrmDb::get_var( $table, $where, $select );
959 743
960 - return;
961 - }
744 + if ( $style_id ) {
745 + $form['options']['custom_style'] = $style_id;
746 + } else {
747 + // save the old style to maybe update after styles import
748 + $form['options']['old_style'] = $form['options']['custom_style'];
962 749
963 - // Replace the style name with the style ID on import
964 - global $wpdb;
965 - $table = $wpdb->prefix . 'posts';
966 - $where = array(
967 - 'post_name' => $form['options']['custom_style'],
968 - 'post_type' => 'frm_styles',
969 - );
970 - $select = 'ID';
971 - $style_id = FrmDb::get_var( $table, $where, $select );
972 -
973 - if ( $style_id ) {
974 - $form['options']['custom_style'] = $style_id;
975 - return;
750 + // Set to default
751 + $form['options']['custom_style'] = 1;
752 + }
976 753 }
977 -
978 - // Save the old style to maybe update after styles import
979 - $form['options']['old_style'] = $form['options']['custom_style'];
980 -
981 - // Set to default
982 - $form['options']['custom_style'] = 1;
983 754 }
984 755
985 756 /**
986 757 * After styles are imported, check for any forms that were linked
@@ -986,40 +757,25 @@
986 757 * After styles are imported, check for any forms that were linked
987 758 * and link them back up.
988 759 *
989 760 * @since 2.2.7
990 - *
991 - * @param int|string $form_id
992 - *
993 - * @return void
994 761 */
995 762 private static function update_custom_style_setting_after_import( $form_id ) {
996 763 $form = FrmForm::getOne( $form_id );
997 764
998 - if ( ! $form || ! isset( $form->options['old_style'] ) ) {
999 - return;
765 + if ( $form && isset( $form->options['old_style'] ) ) {
766 + $form = (array) $form;
767 + $saved_style = $form['options']['custom_style'];
768 + $form['options']['custom_style'] = $form['options']['old_style'];
769 + self::update_custom_style_setting_on_import( $form );
770 + $has_changed = ( $form['options']['custom_style'] != $saved_style && $form['options']['custom_style'] != $form['options']['old_style'] );
771 + if ( $has_changed ) {
772 + FrmForm::update( $form['id'], $form );
773 + }
1000 774 }
1001 -
1002 - $form = (array) $form;
1003 - $saved_style = $form['options']['custom_style'];
1004 - $form['options']['custom_style'] = $form['options']['old_style'];
1005 - self::update_custom_style_setting_on_import( $form );
1006 - $has_changed = $form['options']['custom_style'] != $saved_style && $form['options']['custom_style'] != $form['options']['old_style']; // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong
1007 -
1008 - if ( $has_changed ) {
1009 - FrmForm::update( $form['id'], $form );
1010 - }
1011 775 }
1012 776
1013 - /**
1014 - * Handle import for all posts. This includes views, styles, pages, and form actions.
1015 - *
1016 - * @param SimpleXMLElement $views
1017 - * @param array $imported
1018 - *
1019 - * @return array
1020 - */
1021 - public static function import_xml_views( $views, $imported ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
777 + public static function import_xml_views( $views, $imported ) {
1022 778 $imported['posts'] = array();
1023 779 $form_action_type = FrmFormActionsController::$action_post_type;
1024 780
1025 781 $post_types = array(
@@ -1056,13 +812,8 @@
1056 812 );
1057 813
1058 814 $post['post_content'] = self::switch_form_ids( $post['post_content'], $imported['forms'] );
1059 815
1060 - // Fix issue with line breaks appearing in descriptions as "rn".
1061 - if ( $post['post_type'] === $form_action_type ) {
1062 - $post['post_content'] = str_replace( '\\\\r\\\\n', '\\r\\n', $post['post_content'] );
1063 - }
1064 -
1065 816 $old_id = $post['post_id'];
1066 817 self::populate_post( $post, $item, $imported );
1067 818
1068 819 unset( $item );
@@ -1067,13 +818,11 @@
1067 818
1068 819 unset( $item );
1069 820
1070 821 $post_id = false;
1071 -
1072 822 if ( $post['post_type'] === $form_action_type ) {
1073 823 $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
1074 -
1075 - if ( $action_control && is_object( $action_control ) && isset( $imported['form_status'] ) ) {
824 + if ( $action_control && is_object( $action_control ) ) {
1076 825 $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
1077 826 }
1078 827 unset( $action_control );
1079 828 } elseif ( $post['post_type'] === 'frm_styles' ) {
@@ -1079,10 +828,8 @@
1079 828 } elseif ( $post['post_type'] === 'frm_styles' ) {
1080 829 // Properly encode post content before inserting the post
1081 830 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
1082 831 $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
1083 - // Store template data additionally to a postmeta that can be used to revert the style to default template style.
1084 - $post['postmeta']['frm_style_default'] = $post['post_content'];
1085 832
1086 833 // Create/update post now
1087 834 $post_id = wp_insert_post( $post );
1088 835 } else {
@@ -1092,15 +839,15 @@
1092 839 $post['post_parent'] = $imported['posts'][ $post['post_parent'] ];
1093 840 }
1094 841 // Create/update post now
1095 842 $post_id = wp_insert_post( $post );
1096 - }//end if
843 + }
1097 844
1098 845 if ( ! is_numeric( $post_id ) ) {
1099 846 continue;
1100 847 }
1101 848
1102 - if ( str_contains( $post['post_content'], '[display-frm-data' ) || str_contains( $post['post_content'], '[formidable' ) ) {
849 + if ( false !== strpos( $post['post_content'], '[display-frm-data' ) || false !== strpos( $post['post_content'], '[formidable' ) ) {
1103 850 $posts_with_shortcodes[ $post_id ] = $post;
1104 851 }
1105 852
1106 853 self::update_postmeta( $post, $post_id );
@@ -1106,29 +853,28 @@
1106 853 self::update_postmeta( $post, $post_id );
1107 854 self::update_layout( $post, $post_id );
1108 855
1109 856 $this_type = 'posts';
1110 -
1111 857 if ( isset( $post_types[ $post['post_type'] ] ) ) {
1112 858 $this_type = $post_types[ $post['post_type'] ];
1113 859 }
1114 860
1115 - if ( isset( $post['ID'] ) && (int) $post_id === (int) $post['ID'] ) {
1116 - ++$imported['updated'][ $this_type ];
861 + if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
862 + $imported['updated'][ $this_type ] ++;
1117 863 } else {
1118 - ++$imported['imported'][ $this_type ];
864 + $imported['imported'][ $this_type ] ++;
1119 865 }
1120 866
1121 - $imported['posts'][ $old_id ] = $post_id;
867 + $imported['posts'][ (int) $old_id ] = $post_id;
1122 868
1123 869 if ( $post['post_type'] === 'frm_display' ) {
1124 - $view_ids[ $old_id ] = $post_id;
870 + $view_ids[ (int) $old_id ] = $post_id;
1125 871 }
1126 872
1127 873 do_action( 'frm_after_import_view', $post_id, $post );
1128 874
1129 875 unset( $post );
1130 - }//end foreach
876 + }
1131 877
1132 878 if ( $posts_with_shortcodes && $view_ids ) {
1133 879 self::maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids );
1134 880 }
@@ -1134,9 +880,9 @@
1134 880 }
1135 881 unset( $posts_with_shortcodes, $view_ids );
1136 882
1137 883 if ( ! empty( $imported['forms'] ) ) {
1138 - // Clear imported forms style cache to make sure the new styles are applied to the forms
884 + // clear imported forms style cache to make sure the new styles are applied to the forms
1139 885 self::clear_forms_style_caches( $imported['forms'] );
1140 886 }
1141 887
1142 888 self::maybe_update_stylesheet( $imported );
@@ -1149,14 +895,12 @@
1149 895 /**
1150 896 * Clears styles from cache for imported forms
1151 897 *
1152 898 * @param array $imported_forms
1153 - *
1154 - * @return void
1155 899 */
1156 900 private static function clear_forms_style_caches( $imported_forms ) {
1157 901 $where = array(
1158 - 'id' => $imported_forms,
902 + 'id' => $imported_forms,
1159 903 'options LIKE' => '"old_style"',
1160 904 );
1161 905 $forms = FrmDb::get_results( 'frm_forms', $where );
1162 906
@@ -1161,19 +905,18 @@
1161 905 $forms = FrmDb::get_results( 'frm_forms', $where );
1162 906
1163 907 foreach ( $forms as $form ) {
1164 908 FrmAppHelper::unserialize_or_decode( $form->options );
1165 -
1166 909 if ( ! $form->options ) {
1167 910 continue;
1168 911 }
1169 -
1170 912 $where = array(
1171 913 'post_name' => $form->options['old_style'],
1172 914 'post_type' => FrmStylesController::$post_type,
1173 915 );
1174 916
1175 - $select = 'ID';
917 + $select = 'ID';
918 +
1176 919 $cache_key = FrmDb::generate_cache_key( $where, array( 'limit' => 1 ), $select, 'var' );
1177 920 FrmDb::delete_cache_and_transient( $cache_key, 'post' );
1178 921 }
1179 922 }
@@ -1182,13 +925,12 @@
1182 925 * Replace old form ids with new ones in a string.
1183 926 *
1184 927 * @param string $string
1185 928 * @param array<int> $form_ids new form ids indexed by old form id.
1186 - *
1187 929 * @return string
1188 930 */
1189 931 private static function switch_form_ids( $string, $form_ids ) {
1190 - if ( ! str_contains( $string, '[formidable' ) ) {
932 + if ( false === strpos( $string, '[formidable' ) ) {
1191 933 // Skip string replacing if there are no form shortcodes in string.
1192 934 return $string;
1193 935 }
1194 936
@@ -1215,15 +957,13 @@
1215 957
1216 958 /**
1217 959 * @param array<array> $posts_with_shortcodes indexed by current post id.
1218 960 * @param array<int> $view_ids new view ids indexed by old view id.
1219 - *
1220 961 * @return void
1221 962 */
1222 963 private static function maybe_switch_view_ids_after_importing_posts( $posts_with_shortcodes, $view_ids ) {
1223 964 foreach ( $posts_with_shortcodes as $imported_post_id => $post ) {
1224 965 $post_content = self::switch_view_ids( $post['post_content'], $view_ids );
1225 -
1226 966 if ( $post_content === $post['post_content'] ) {
1227 967 continue;
1228 968 }
1229 969
@@ -1240,13 +980,12 @@
1240 980 * Replace old view ids with new ones in a string.
1241 981 *
1242 982 * @param string $string
1243 983 * @param array<int> $view_ids new view ids indexed by old view id.
1244 - *
1245 984 * @return string
1246 985 */
1247 986 private static function switch_view_ids( $string, $view_ids ) {
1248 - if ( ! str_contains( $string, '[display-frm-data' ) ) {
987 + if ( false === strpos( $string, '[display-frm-data' ) ) {
1249 988 // Skip string replacing if there are no view shortcodes in string.
1250 989 return $string;
1251 990 }
1252 991
@@ -1273,40 +1012,30 @@
1273 1012 }
1274 1013
1275 1014 /**
1276 1015 * @param string $content
1277 - *
1278 1016 * @return string
1279 1017 */
1280 1018 private static function maybe_prepare_json_view_content( $content ) {
1281 1019 $maybe_decoded = FrmAppHelper::maybe_json_decode( $content );
1282 -
1283 1020 if ( is_array( $maybe_decoded ) && isset( $maybe_decoded[0] ) && isset( $maybe_decoded[0]['box'] ) ) {
1284 1021 return FrmAppHelper::prepare_and_encode( $maybe_decoded );
1285 1022 }
1286 -
1287 1023 return $content;
1288 1024 }
1289 1025
1290 - /**
1291 - * @param array $post
1292 - * @param object $item
1293 - * @param array $imported
1294 - *
1295 - * @return void
1296 - */
1297 1026 private static function populate_post( &$post, $item, $imported ) {
1298 1027 if ( isset( $item->attachment_url ) ) {
1299 1028 $post['attachment_url'] = (string) $item->attachment_url;
1300 1029 }
1301 1030
1302 - if ( $post['post_type'] === FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
1303 - // Update to new form id
1031 + if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
1032 + // update to new form id
1304 1033 $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
1305 1034 }
1306 1035
1307 1036 // Don't allow default styles to take over a site's default style
1308 - if ( 'frm_styles' === $post['post_type'] ) {
1037 + if ( 'frm_styles' == $post['post_type'] ) {
1309 1038 $post['menu_order'] = 0;
1310 1039 }
1311 1040
1312 1041 foreach ( $item->postmeta as $meta ) {
@@ -1328,9 +1057,9 @@
1328 1057 * @param array $post
1329 1058 * @param stdClass $meta
1330 1059 * @param array $imported
1331 1060 */
1332 - private static function populate_postmeta( &$post, $meta, $imported ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh, Generic.Metrics.CyclomaticComplexity.MaxExceeded, SlevomatCodingStandard.Files.LineLength.LineTooLong
1061 + private static function populate_postmeta( &$post, $meta, $imported ) {
1333 1062 global $frm_duplicate_ids;
1334 1063
1335 1064 $m = array(
1336 1065 'key' => (string) $meta->meta_key,
@@ -1336,19 +1065,20 @@
1336 1065 'key' => (string) $meta->meta_key,
1337 1066 'value' => (string) $meta->meta_value,
1338 1067 );
1339 1068
1340 - // Switch old form and field ids to new ones.
1069 + //switch old form and field ids to new ones
1341 1070 if ( 'frm_form_id' === $m['key'] && isset( $imported['forms'][ (int) $m['value'] ] ) ) {
1342 1071 $m['value'] = $imported['forms'][ (int) $m['value'] ];
1343 1072 } else {
1344 1073 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
1345 1074
1346 - if ( $frm_duplicate_ids ) {
1075 + if ( ! empty( $frm_duplicate_ids ) ) {
1347 1076 if ( 'frm_dyncontent' === $m['key'] ) {
1348 1077 $m['value'] = self::maybe_prepare_json_view_content( $m['value'] );
1349 1078 $m['value'] = FrmFieldsHelper::switch_field_ids( $m['value'] );
1350 1079 } elseif ( 'frm_options' === $m['key'] ) {
1080 +
1351 1081 foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
1352 1082 if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) {
1353 1083 $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
1354 1084 }
@@ -1353,38 +1083,10 @@
1353 1083 $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
1354 1084 }
1355 1085 }
1356 1086
1357 - if ( ! empty( $m['value']['map_address_fields'] ) ) {
1358 - foreach ( $m['value']['map_address_fields'] as $address_field_key => $address_field_id ) {
1359 - if ( isset( $frm_duplicate_ids[ $address_field_id ] ) ) {
1360 - $m['value']['map_address_fields'][ $address_field_key ] = $frm_duplicate_ids[ $address_field_id ];
1361 - }
1362 - }
1363 - }
1364 -
1365 - if ( ! empty( $m['value']['calendar_options'] ) ) {
1366 - foreach ( $m['value']['calendar_options'] as $calendar_option_group_key => $calendar_option ) {
1367 - if ( isset( $frm_duplicate_ids[ $calendar_option['value'] ] ) ) {
1368 - $m['value']['calendar_options'][ $calendar_option_group_key ]['value'] = $frm_duplicate_ids[ $calendar_option['value'] ];
1369 - }
1370 - }
1371 - }
1372 -
1373 - if ( ! empty( $m['value']['timeline_options'] ) ) {
1374 - foreach ( $m['value']['timeline_options'] as $timeline_option_group_key => $timeline_group_option ) {
1375 - foreach ( $timeline_group_option as $timeline_option_key => $timeline_option ) {
1376 - // @mago-expect lint:excessive-nesting
1377 - if ( isset( $frm_duplicate_ids[ $timeline_option ] ) ) {
1378 - $m['value']['timeline_options'][ $timeline_option_group_key ][ $timeline_option_key ] = $frm_duplicate_ids[ $timeline_option ];
1379 - }
1380 - }
1381 - }
1382 - }
1383 -
1384 1087 $check_dup_array = array();
1385 -
1386 - if ( ! empty( $m['value']['order_by'] ) ) {
1088 + if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
1387 1089 if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
1388 1090 $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
1389 1091 } elseif ( is_array( $m['value']['order_by'] ) ) {
1390 1092 $check_dup_array[] = 'order_by';
@@ -1390,9 +1092,9 @@
1390 1092 $check_dup_array[] = 'order_by';
1391 1093 }
1392 1094 }
1393 1095
1394 - if ( ! empty( $m['value']['where'] ) ) {
1096 + if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
1395 1097 $check_dup_array[] = 'where';
1396 1098 }
1397 1099
1398 1100 foreach ( $check_dup_array as $check_k ) {
@@ -1402,11 +1104,11 @@
1402 1104 }
1403 1105 unset( $mk, $mv );
1404 1106 }
1405 1107 }
1406 - }//end if
1407 - }//end if
1408 - }//end if
1108 + }
1109 + }
1110 + }
1409 1111
1410 1112 if ( ! is_array( $m['value'] ) ) {
1411 1113 $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
1412 1114 }
@@ -1413,14 +1115,8 @@
1413 1115
1414 1116 $post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
1415 1117 }
1416 1118
1417 - /**
1418 - * @param array $post
1419 - * @param object $layout
1420 - *
1421 - * @return void
1422 - */
1423 1119 private static function populate_layout( &$post, $layout ) {
1424 1120 $post['layout'][ (string) $layout->type ] = (string) $layout->data;
1425 1121 }
1426 1122
@@ -1426,25 +1122,22 @@
1426 1122
1427 1123 /**
1428 1124 * Add terms to post
1429 1125 *
1430 - * @param array $post By reference.
1431 - * @param object $item The XML object data.
1126 + * @param array $post by reference
1127 + * @param object $item The XML object data
1432 1128 */
1433 1129 private static function populate_taxonomies( &$post, $item ) {
1434 1130 foreach ( $item->category as $c ) {
1435 1131 $att = $c->attributes();
1436 -
1437 1132 if ( ! isset( $att['nicename'] ) ) {
1438 1133 continue;
1439 1134 }
1440 1135
1441 1136 $taxonomy = (string) $att['domain'];
1442 -
1443 1137 if ( is_taxonomy_hierarchical( $taxonomy ) ) {
1444 1138 $name = (string) $att['nicename'];
1445 1139 $h_term = get_term_by( 'slug', $name, $taxonomy );
1446 -
1447 1140 if ( $h_term ) {
1448 1141 $name = $h_term->term_id;
1449 1142 }
1450 1143 unset( $h_term );
@@ -1457,17 +1150,13 @@
1457 1150 }
1458 1151
1459 1152 $post['tax_input'][ $taxonomy ][] = $name;
1460 1153 unset( $name );
1461 - }//end foreach
1154 + }
1462 1155 }
1463 1156
1464 1157 /**
1465 - * Edit post if the key and created time match.
1466 - *
1467 - * @param array $post By reference.
1468 - *
1469 - * @return void
1158 + * Edit post if the key and created time match
1470 1159 */
1471 1160 private static function maybe_editing_post( &$post ) {
1472 1161 $match_by = array(
1473 1162 'post_type' => $post['post_type'],
@@ -1475,9 +1164,9 @@
1475 1164 'post_status' => $post['post_status'],
1476 1165 'posts_per_page' => 1,
1477 1166 );
1478 1167
1479 - if ( in_array( $post['post_status'], array( 'trash', 'draft' ), true ) ) {
1168 + if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
1480 1169 $match_by['include'] = $post['post_id'];
1481 1170 unset( $match_by['name'] );
1482 1171 }
1483 1172
@@ -1482,11 +1171,10 @@
1482 1171 }
1483 1172
1484 1173 $editing = get_posts( $match_by );
1485 1174
1486 - // phpcs:ignore Universal.Operators.StrictComparisons
1487 - if ( $editing && current( $editing )->post_date == $post['post_date'] ) {
1488 - // Set the id of the post to edit
1175 + if ( ! empty( $editing ) && current( $editing )->post_date == $post['post_date'] ) {
1176 + // set the id of the post to edit
1489 1177 $post['ID'] = current( $editing )->ID;
1490 1178 }
1491 1179 }
1492 1180
@@ -1492,9 +1180,8 @@
1492 1180
1493 1181 /**
1494 1182 * @param array $post
1495 1183 * @param int $post_id
1496 - *
1497 1184 * @return void
1498 1185 */
1499 1186 private static function update_postmeta( &$post, $post_id ) {
1500 1187 foreach ( $post['postmeta'] as $k => $v ) {
@@ -1519,13 +1206,13 @@
1519 1206
1520 1207 case 'frm_param':
1521 1208 add_rewrite_endpoint( $v, EP_PERMALINK | EP_PAGES );
1522 1209 break;
1523 - }//end switch
1210 + }
1524 1211
1525 1212 update_post_meta( $post_id, $k, $v );
1526 1213 unset( $k, $v );
1527 - }//end foreach
1214 + }
1528 1215 }
1529 1216
1530 1217 /**
1531 1218 * @param array $post
@@ -1531,83 +1218,44 @@
1531 1218 * @param array $post
1532 1219 * @param int $post_id
1533 1220 */
1534 1221 private static function update_layout( &$post, $post_id ) {
1535 - if ( ! is_callable( 'FrmViewsLayout::maybe_create_layouts_for_view' ) ) {
1536 - return;
1222 + if ( is_callable( 'FrmViewsLayout::maybe_create_layouts_for_view' ) ) {
1223 + $listing_layout = ! empty( $post['layout']['listing'] ) ? json_decode( $post['layout']['listing'], true ) : array();
1224 + $detail_layout = ! empty( $post['layout']['detail'] ) ? json_decode( $post['layout']['detail'], true ) : array();
1225 + if ( $listing_layout || $detail_layout ) {
1226 + FrmViewsLayout::maybe_create_layouts_for_view( $post_id, $listing_layout, $detail_layout );
1227 + }
1537 1228 }
1538 -
1539 - $listing_layout = ! empty( $post['layout']['listing'] ) ? json_decode( $post['layout']['listing'], true ) : array();
1540 - $detail_layout = ! empty( $post['layout']['detail'] ) ? json_decode( $post['layout']['detail'], true ) : array();
1541 -
1542 - if ( $listing_layout || $detail_layout ) {
1543 - FrmViewsLayout::maybe_create_layouts_for_view( $post_id, $listing_layout, $detail_layout );
1544 - }
1545 1229 }
1546 1230
1547 - /**
1548 - * @param array $imported
1549 - *
1550 - * @return void
1551 - */
1552 1231 private static function maybe_update_stylesheet( $imported ) {
1553 - $new_styles = ! empty( $imported['imported']['styles'] );
1554 - $updated_styles = ! empty( $imported['updated']['styles'] );
1555 -
1556 - if ( ! $new_styles && ! $updated_styles ) {
1557 - return;
1232 + $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] );
1233 + $updated_styles = isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] );
1234 + if ( $new_styles || $updated_styles ) {
1235 + if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
1236 + $frm_style = new FrmStyle();
1237 + $frm_style->update( 'default' );
1238 + }
1239 + foreach ( $imported['forms'] as $form_id ) {
1240 + self::update_custom_style_setting_after_import( $form_id );
1241 + }
1558 1242 }
1559 -
1560 - if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
1561 - $frm_style = new FrmStyle();
1562 - $frm_style->update( 'default' );
1563 - }
1564 -
1565 - foreach ( $imported['forms'] as $form_id ) {
1566 - self::update_custom_style_setting_after_import( $form_id );
1567 - }
1568 1243 }
1569 1244
1570 1245 /**
1571 - * @param mixed $result
1572 1246 * @param string $message
1573 - * @param array $errors
1574 - *
1575 - * @return void
1576 1247 */
1577 1248 public static function parse_message( $result, &$message, &$errors ) {
1578 1249 if ( is_wp_error( $result ) ) {
1579 1250 $errors[] = $result->get_error_message();
1580 -
1581 - // Remove the SimpleXML_parse_error from the WP_Error object to avoid
1582 - // displaying duplicate error messages from $result->get_error_message()
1583 - $error_details = array();
1584 -
1585 - foreach ( $result->get_error_codes() as $error_code ) {
1586 - // Clone WP_Error data because WP_Error removes all error messages and data
1587 - // Associated with the specified error code when an item is removed.
1588 - // Source: https://developer.wordpress.org/reference/classes/wp_error/remove/#source
1589 - $error_details = $result->get_error_data( $error_code );
1590 -
1591 - if ( $error_code === 'SimpleXML_parse_error' ) {
1592 - $result->remove( $error_code );
1593 - break;
1594 - }
1595 - }
1596 -
1597 - if ( $error_details ) {
1598 - $errors[] = '<br />' . esc_html_x( 'Error details:', 'import xml message', 'formidable' ) . '<br />' . esc_html( print_r( $error_details, 1 ) );
1599 - }
1600 -
1251 + } elseif ( ! $result ) {
1601 1252 return;
1602 - }//end if
1603 -
1604 - if ( ! $result ) {
1605 - return;
1606 1253 }
1607 1254
1608 1255 if ( ! is_array( $result ) ) {
1609 1256 $message = is_string( $result ) ? $result : htmlentities( print_r( $result, 1 ) );
1257 +
1610 1258 return;
1611 1259 }
1612 1260
1613 1261 $t_strings = array(
@@ -1615,48 +1263,42 @@
1615 1263 'updated' => __( 'Updated', 'formidable' ),
1616 1264 );
1617 1265
1618 1266 $message = '<ul>';
1619 -
1620 1267 foreach ( $result as $type => $results ) {
1621 1268 if ( ! isset( $t_strings[ $type ] ) ) {
1622 - // Only print imported and updated
1269 + // only print imported and updated
1623 1270 continue;
1624 1271 }
1625 1272
1626 1273 $s_message = array();
1627 -
1628 1274 foreach ( $results as $k => $m ) {
1629 1275 self::item_count_message( $m, $k, $s_message );
1630 1276 unset( $k, $m );
1631 1277 }
1632 1278
1633 - if ( ! $s_message ) {
1634 - continue;
1279 + if ( ! empty( $s_message ) ) {
1280 + $message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> ';
1281 + $message .= implode( ', ', $s_message );
1282 + $message .= '</li>';
1635 1283 }
1284 + }
1636 1285
1637 - $message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> ';
1638 - $message .= implode( ', ', $s_message );
1639 - $message .= '</li>';
1640 - }//end foreach
1641 -
1642 - if ( $message === '<ul>' ) {
1286 + if ( $message == '<ul>' ) {
1643 1287 $message = '';
1644 1288 $errors[] = __( 'Nothing was imported or updated', 'formidable' );
1289 + } else {
1290 + self::add_form_link_to_message( $result, $message );
1645 1291
1646 - return;
1292 + /**
1293 + * @since 5.3
1294 + *
1295 + * @param string $message
1296 + * @param array $result
1297 + */
1298 + $message = apply_filters( 'frm_xml_parsed_message', $message, $result );
1299 + $message .= '</ul>';
1647 1300 }
1648 -
1649 - self::add_form_link_to_message( $result, $message );
1650 -
1651 - /**
1652 - * @since 5.3
1653 - *
1654 - * @param string $message
1655 - * @param array $result
1656 - */
1657 - $message = apply_filters( 'frm_xml_parsed_message', $message, $result );
1658 - $message .= '</ul>';
1659 1301 }
1660 1302
1661 1303 /**
1662 1304 * @param int $m
@@ -1661,10 +1303,8 @@
1661 1303 /**
1662 1304 * @param int $m
1663 1305 * @param string $type
1664 1306 * @param array<string> $s_message
1665 - *
1666 - * @return void
1667 1307 */
1668 1308 public static function item_count_message( $m, $type, &$s_message ) {
1669 1309 if ( ! $m ) {
1670 1310 return;
@@ -1690,22 +1330,21 @@
1690 1330 );
1691 1331
1692 1332 if ( isset( $strings[ $type ] ) ) {
1693 1333 $s_message[] = $strings[ $type ];
1694 - return;
1334 + } else {
1335 + $string = ' ' . $m . ' ' . ucfirst( $type );
1336 +
1337 + /**
1338 + * @since 5.3
1339 + *
1340 + * @param string $string Message string for imported item.
1341 + * @param int $m Number of item that was imported.
1342 + * }
1343 + */
1344 + $string = apply_filters( 'frm_xml_' . $type . '_count_message', $string, $m );
1345 + $s_message[] = $string;
1695 1346 }
1696 -
1697 - $string = ' ' . $m . ' ' . ucfirst( $type );
1698 -
1699 - /**
1700 - * @since 5.3
1701 - *
1702 - * @param string $string Message string for imported item.
1703 - * @param int $m Number of item that was imported.
1704 - * }
1705 - */
1706 - $string = apply_filters( 'frm_xml_' . $type . '_count_message', $string, $m );
1707 - $s_message[] = $string;
1708 1347 }
1709 1348
1710 1349 /**
1711 1350 * If a single form was imported, include a link in the success message.
@@ -1710,28 +1349,24 @@
1710 1349 /**
1711 1350 * If a single form was imported, include a link in the success message.
1712 1351 *
1713 1352 * @since 4.0
1714 - *
1715 1353 * @param array $result The response from the XML import.
1716 1354 * @param string $message The response shown on the page after import.
1717 1355 */
1718 1356 private static function add_form_link_to_message( $result, &$message ) {
1719 1357 $total_forms = $result['imported']['forms'] + $result['updated']['forms'];
1720 -
1721 1358 if ( $total_forms > 1 ) {
1722 1359 return;
1723 1360 }
1724 1361
1725 1362 $primary_form = reset( $result['forms'] );
1363 + if ( ! empty( $primary_form ) ) {
1364 + $primary_form = FrmForm::getOne( $primary_form );
1365 + $form_id = empty( $primary_form->parent_form_id ) ? $primary_form->id : $primary_form->parent_form_id;
1726 1366
1727 - if ( ! $primary_form ) {
1728 - return;
1367 + $message .= '<li><a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html__( 'Go to imported form', 'formidable' ) . '</a></li>';
1729 1368 }
1730 -
1731 - $primary_form = FrmForm::getOne( $primary_form );
1732 - $form_id = ! empty( $primary_form->parent_form_id ) ? $primary_form->parent_form_id : $primary_form->id;
1733 - $message .= '<li><a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html__( 'Go to imported form', 'formidable' ) . '</a></li>';
1734 1369 }
1735 1370
1736 1371 /**
1737 1372 * Prepare the form options for export
@@ -1744,17 +1379,22 @@
1744 1379 */
1745 1380 public static function prepare_form_options_for_export( $options ) {
1746 1381 FrmAppHelper::unserialize_or_decode( $options );
1747 1382 // Change custom_style to the post_name instead of ID (1 may be a string)
1748 - $not_default = isset( $options['custom_style'] ) && 1 != $options['custom_style']; // phpcs:ignore Universal.Operators.StrictComparisons
1749 -
1383 + $not_default = isset( $options['custom_style'] ) && 1 != $options['custom_style'];
1750 1384 if ( $not_default ) {
1751 1385 global $wpdb;
1752 - $table = $wpdb->prefix . 'posts';
1753 - $where = array( 'ID' => $options['custom_style'] );
1754 - $select = 'post_name';
1755 - $style_name = FrmDb::get_var( $table, $where, $select );
1756 - $options['custom_style'] = $style_name ? $style_name : 1;
1386 + $table = $wpdb->prefix . 'posts';
1387 + $where = array( 'ID' => $options['custom_style'] );
1388 + $select = 'post_name';
1389 +
1390 + $style_name = FrmDb::get_var( $table, $where, $select );
1391 +
1392 + if ( $style_name ) {
1393 + $options['custom_style'] = $style_name;
1394 + } else {
1395 + $options['custom_style'] = 1;
1396 + }
1757 1397 }
1758 1398 self::remove_default_form_options( $options );
1759 1399 $options = serialize( $options );
1760 1400
@@ -1765,16 +1405,11 @@
1765 1405 * If the saved value is the same as the default, remove it from the export
1766 1406 * This keeps file size down and prevents overriding global settings after import
1767 1407 *
1768 1408 * @since 3.06
1769 - *
1770 - * @param array $options By reference.
1771 - *
1772 - * @return void
1773 1409 */
1774 1410 private static function remove_default_form_options( &$options ) {
1775 1411 $defaults = FrmFormsHelper::get_default_opts();
1776 -
1777 1412 if ( is_callable( 'FrmProFormsHelper::get_default_opts' ) ) {
1778 1413 $defaults += FrmProFormsHelper::get_default_opts();
1779 1414 }
1780 1415 self::remove_defaults( $defaults, $options );
@@ -1783,12 +1418,8 @@
1783 1418 /**
1784 1419 * Remove extra settings from field to keep file size down
1785 1420 *
1786 1421 * @since 3.06
1787 - *
1788 - * @param object $field
1789 - *
1790 - * @return void
1791 1422 */
1792 1423 public static function prepare_field_for_export( &$field ) {
1793 1424 self::remove_default_field_options( $field );
1794 1425 self::add_image_src_to_image_options( $field );
@@ -1797,16 +1428,11 @@
1797 1428 /**
1798 1429 * Remove defaults from field options too
1799 1430 *
1800 1431 * @since 3.06
1801 - *
1802 - * @param object $field
1803 - *
1804 - * @return void
1805 1432 */
1806 1433 private static function remove_default_field_options( &$field ) {
1807 1434 $defaults = self::default_field_options( $field->type );
1808 -
1809 1435 if ( empty( $defaults['blank'] ) ) {
1810 1436 $global_settings = new FrmSettings();
1811 1437 $global_defaults = $global_settings->default_options();
1812 1438 $defaults['blank'] = $global_defaults['blank_msg'];
@@ -1834,13 +1460,12 @@
1834 1460 *
1835 1461 * @since 5.5.1
1836 1462 *
1837 1463 * @param stdClass $field
1838 - *
1839 1464 * @return void
1840 1465 */
1841 1466 private static function add_image_src_to_image_options( $field ) {
1842 - if ( empty( $field->options ) || ! str_contains( $field->options, 'image' ) ) {
1467 + if ( empty( $field->options ) || false === strpos( $field->options, 'image' ) ) {
1843 1468 return;
1844 1469 }
1845 1470
1846 1471 $updated = false;
@@ -1851,14 +1476,12 @@
1851 1476 return;
1852 1477 }
1853 1478
1854 1479 foreach ( $options as $key => $option ) {
1855 - if ( ! is_array( $option ) || empty( $option['image'] ) ) {
1856 - continue;
1480 + if ( is_array( $option ) && ! empty( $option['image'] ) ) {
1481 + $options[ $key ]['src'] = wp_get_attachment_url( $option['image'] );
1482 + $updated = true;
1857 1483 }
1858 -
1859 - $options[ $key ]['src'] = wp_get_attachment_url( $option['image'] );
1860 - $updated = true;
1861 1484 }
1862 1485
1863 1486 if ( $updated ) {
1864 1487 $field->options = maybe_serialize( $options );
@@ -1866,20 +1489,14 @@
1866 1489 }
1867 1490
1868 1491 /**
1869 1492 * @since 3.06.03
1870 - *
1871 - * @param string $type
1872 - *
1873 - * @return array
1874 1493 */
1875 1494 private static function default_field_options( $type ) {
1876 1495 $defaults = FrmFieldsHelper::get_default_field_options( $type );
1877 -
1878 1496 if ( empty( $defaults['custom_html'] ) ) {
1879 1497 $defaults['custom_html'] = FrmFieldsHelper::get_default_html( $type );
1880 1498 }
1881 -
1882 1499 return $defaults;
1883 1500 }
1884 1501
1885 1502 /**
@@ -1886,13 +1503,8 @@
1886 1503 * Compare the default array to the saved values and
1887 1504 * remove if they are the same
1888 1505 *
1889 1506 * @since 3.06
1890 - *
1891 - * @param array $defaults
1892 - * @param array $saved
1893 - *
1894 - * @return void
1895 1507 */
1896 1508 private static function remove_defaults( $defaults, &$saved ) {
1897 1509 foreach ( $saved as $key => $value ) {
1898 1510 if ( isset( $defaults[ $key ] ) && $defaults[ $key ] === $value ) {
@@ -1904,14 +1516,8 @@
1904 1516 /**
1905 1517 * The line endings may prevent html from being equal when it should
1906 1518 *
1907 1519 * @since 3.06
1908 - *
1909 - * @param string $html_name
1910 - * @param array $defaults
1911 - * @param array $options
1912 - *
1913 - * @return void
1914 1520 */
1915 1521 private static function remove_default_html( $html_name, $defaults, &$options ) {
1916 1522 if ( ! isset( $options[ $html_name ] ) || ! isset( $defaults[ $html_name ] ) ) {
1917 1523 return;
@@ -1918,35 +1524,27 @@
1918 1524 }
1919 1525
1920 1526 $old_html = str_replace( "\r\n", "\n", $options[ $html_name ] );
1921 1527 $default_html = $defaults[ $html_name ];
1922 -
1923 - // phpcs:ignore Universal.Operators.StrictComparisons
1924 1528 if ( $old_html == $default_html ) {
1925 1529 unset( $options[ $html_name ] );
1530 +
1926 1531 return;
1927 1532 }
1928 1533
1929 1534 // Account for some of the older field default HTML.
1930 1535 $default_html = str_replace( ' id="frm_desc_field_[key]"', '', $default_html );
1931 -
1932 - if ( $old_html === $default_html ) {
1536 + if ( $old_html == $default_html ) {
1933 1537 unset( $options[ $html_name ] );
1934 1538 }
1935 1539 }
1936 1540
1937 - /**
1938 - * @param string $str
1939 - *
1940 - * @return string
1941 - */
1942 1541 public static function cdata( $str ) {
1943 1542 FrmAppHelper::unserialize_or_decode( $str );
1944 -
1945 1543 if ( is_array( $str ) ) {
1946 1544 $str = json_encode( $str );
1947 - } elseif ( FrmAppHelper::is_valid_utf8( $str ) === false ) {
1948 - $str = FrmAppHelper::maybe_utf8_encode( $str );
1545 + } elseif ( seems_utf8( $str ) === false ) {
1546 + $str = utf8_encode( $str );
1949 1547 }
1950 1548
1951 1549 if ( is_numeric( $str ) ) {
1952 1550 return $str;
@@ -1954,9 +1552,11 @@
1954 1552
1955 1553 self::remove_invalid_characters_from_xml( $str );
1956 1554
1957 1555 // $str = ent2ncr(esc_html( $str));
1958 - return '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
1556 + $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
1557 +
1558 + return $str;
1959 1559 }
1960 1560
1961 1561 /**
1962 1562 * Remove <US> character (unit separator) from exported strings
@@ -1963,10 +1563,8 @@
1963 1563 *
1964 1564 * @since 2.0.22
1965 1565 *
1966 1566 * @param string $str
1967 - *
1968 - * @return void
1969 1567 */
1970 1568 private static function remove_invalid_characters_from_xml( &$str ) {
1971 1569 // Remove <US> character
1972 1570 $str = str_replace( '\x1F', '', $str );
@@ -1971,18 +1569,8 @@
1971 1569 // Remove <US> character
1972 1570 $str = str_replace( '\x1F', '', $str );
1973 1571 }
1974 1572
1975 - /**
1976 - * Migrate form settings to actions
1977 - *
1978 - * @param array $form_options
1979 - * @param int $form_id
1980 - * @param array $imported
1981 - * @param bool $switch
1982 - *
1983 - * @return void
1984 - */
1985 1573 public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
1986 1574 // Get post type
1987 1575 $post_type = FrmFormActionsController::$action_post_type;
1988 1576
@@ -2000,16 +1588,12 @@
2000 1588
2001 1589 /**
2002 1590 * Migrate post settings to form action
2003 1591 *
2004 - * @param array $form_options
2005 - * @param int $form_id
2006 1592 * @param string $post_type
2007 - * @param array $imported
2008 - * @param bool $switch
2009 1593 */
2010 1594 private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
2011 - if ( empty( $form_options['create_post'] ) ) {
1595 + if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
2012 1596 return;
2013 1597 }
2014 1598
2015 1599 $new_action = array(
@@ -2061,9 +1645,8 @@
2061 1645 $array_fields = array( 'post_category', 'post_custom_fields' );
2062 1646
2063 1647 $new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields );
2064 1648 }
2065 -
2066 1649 $new_action['post_content'] = json_encode( $new_action['post_content'] );
2067 1650
2068 1651 $exists = get_posts(
2069 1652 array(
@@ -2073,15 +1656,13 @@
2073 1656 'numberposts' => 1,
2074 1657 )
2075 1658 );
2076 1659
2077 - if ( $exists ) {
2078 - return;
1660 + if ( ! $exists ) {
1661 + // this isn't an email, but we need to use a class that will always be included
1662 + FrmDb::save_json_post( $new_action );
1663 + $imported['imported']['actions'] ++;
2079 1664 }
2080 -
2081 - // This isn't an email, but we need to use a class that will always be included
2082 - FrmDb::save_json_post( $new_action );
2083 - ++$imported['imported']['actions'];
2084 1665 }
2085 1666
2086 1667 /**
2087 1668 * Switch old field IDs for new field IDs in emails and post
@@ -2087,11 +1668,11 @@
2087 1668 * Switch old field IDs for new field IDs in emails and post
2088 1669 *
2089 1670 * @since 2.0
2090 1671 *
2091 - * @param array $post_content Check for old field IDs.
2092 - * @param array $basic_fields Fields with string or int saved.
2093 - * @param array $array_fields Fields with arrays saved.
1672 + * @param array $post_content - check for old field IDs
1673 + * @param array $basic_fields - fields with string or int saved
1674 + * @param array $array_fields - fields with arrays saved
2094 1675 *
2095 1676 * @return string $post_content - new field IDs
2096 1677 */
2097 1678 private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
@@ -2098,9 +1679,9 @@
2098 1679 global $frm_duplicate_ids;
2099 1680
2100 1681 // If there aren't IDs that were switched, end now
2101 1682 if ( ! $frm_duplicate_ids ) {
2102 - return null;
1683 + return;
2103 1684 }
2104 1685
2105 1686 // Get old IDs
2106 1687 $old = array_keys( $frm_duplicate_ids );
@@ -2109,13 +1690,11 @@
2109 1690 $new = array_values( $frm_duplicate_ids );
2110 1691
2111 1692 // Do a str_replace with each item to set the new IDs
2112 1693 foreach ( $post_content as $key => $setting ) {
2113 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
2114 1694 if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
2115 1695 // Replace old IDs with new IDs
2116 1696 $post_content[ $key ] = str_replace( $old, $new, $setting );
2117 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
2118 1697 } elseif ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
2119 1698 foreach ( $setting as $k => $val ) {
2120 1699 // Replace old IDs with new IDs
2121 1700 $post_content[ $key ][ $k ] = str_replace( $old, $new, $val );
@@ -2126,19 +1705,8 @@
2126 1705
2127 1706 return $post_content;
2128 1707 }
2129 1708
2130 - /**
2131 - * Migrate email settings to action
2132 - *
2133 - * @param array $form_options
2134 - * @param int $form_id
2135 - * @param string $post_type
2136 - * @param array $imported
2137 - * @param bool $switch
2138 - *
2139 - * @return void
2140 - */
2141 1709 private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
2142 1710 // No old notifications or autoresponders to carry over
2143 1711 if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) {
2144 1712 return;
@@ -2152,9 +1720,9 @@
2152 1720
2153 1721 // Migrate autoresponders
2154 1722 self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
2155 1723
2156 - if ( ! $notifications ) {
1724 + if ( empty( $notifications ) ) {
2157 1725 return;
2158 1726 }
2159 1727
2160 1728 foreach ( $notifications as $new_notification ) {
@@ -2165,8 +1733,9 @@
2165 1733 $new_notification['post_status'] = 'publish';
2166 1734
2167 1735 // Switch field IDs and keys, if needed
2168 1736 if ( $switch ) {
1737 +
2169 1738 // Switch field IDs in email conditional logic
2170 1739 self::switch_email_condition_field_ids( $new_notification['post_content'] );
2171 1740
2172 1741 // Switch all other field IDs in email
@@ -2171,9 +1740,8 @@
2171 1740
2172 1741 // Switch all other field IDs in email
2173 1742 $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
2174 1743 }
2175 -
2176 1744 $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
2177 1745
2178 1746 $exists = get_posts(
2179 1747 array(
@@ -2183,14 +1751,14 @@
2183 1751 'numberposts' => 1,
2184 1752 )
2185 1753 );
2186 1754
2187 - if ( ! $exists ) {
1755 + if ( empty( $exists ) ) {
2188 1756 FrmDb::save_json_post( $new_notification );
2189 - ++$imported['imported']['actions'];
1757 + $imported['imported']['actions'] ++;
2190 1758 }
2191 1759 unset( $new_notification );
2192 - }//end foreach
1760 + }
2193 1761
2194 1762 self::remove_deprecated_notification_settings( $form_id, $form_options );
2195 1763 }
2196 1764
@@ -2199,44 +1767,32 @@
2199 1767 *
2200 1768 * @since 2.05
2201 1769 *
2202 1770 * @param int|string $form_id
2203 - * @param array $form_options
2204 - *
2205 - * @return void
1771 + * @param array $form_options
2206 1772 */
2207 1773 private static function remove_deprecated_notification_settings( $form_id, $form_options ) {
2208 1774 $delete_settings = array( 'notification', 'autoresponder', 'email_to' );
2209 -
2210 1775 foreach ( $delete_settings as $index ) {
2211 1776 if ( isset( $form_options[ $index ] ) ) {
2212 1777 unset( $form_options[ $index ] );
2213 1778 }
2214 1779 }
2215 -
2216 1780 FrmForm::update( $form_id, array( 'options' => $form_options ) );
2217 1781 }
2218 1782
2219 - /**
2220 - * Migrate notifications to action
2221 - *
2222 - * @param array $form_options
2223 - * @param int $form_id
2224 - * @param array $notifications
2225 - *
2226 - * @return void
2227 - */
2228 1783 private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
2229 - if ( ! isset( $form_options['notification'] ) && ! empty( $form_options['email_to'] ) ) {
2230 - // Add old settings into notification array
1784 + if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
1785 + // add old settings into notification array
2231 1786 $form_options['notification'] = array( 0 => $form_options );
2232 1787 } elseif ( isset( $form_options['notification']['email_to'] ) ) {
2233 - // Make sure it's in the correct format
1788 + // make sure it's in the correct format
2234 1789 $form_options['notification'] = array( 0 => $form_options['notification'] );
2235 1790 }
2236 1791
2237 1792 if ( isset( $form_options['notification'] ) && is_array( $form_options['notification'] ) ) {
2238 1793 foreach ( $form_options['notification'] as $email_key => $notification ) {
1794 +
2239 1795 $atts = array(
2240 1796 'email_to' => '',
2241 1797 'reply_to' => '',
2242 1798 'reply_to_name' => '',
@@ -2247,9 +1803,9 @@
2247 1803
2248 1804 // Format the email data
2249 1805 self::format_email_data( $atts, $notification );
2250 1806
2251 - if ( ! empty( $notification['twilio'] ) ) {
1807 + if ( isset( $notification['twilio'] ) && $notification['twilio'] ) {
2252 1808 do_action( 'frm_create_twilio_action', $atts, $notification );
2253 1809 }
2254 1810
2255 1811 // Setup the new notification
@@ -2256,20 +1812,12 @@
2256 1812 $new_notification = array();
2257 1813 self::setup_new_notification( $new_notification, $notification, $atts );
2258 1814
2259 1815 $notifications[] = $new_notification;
2260 - }//end foreach
2261 - }//end if
1816 + }
1817 + }
2262 1818 }
2263 1819
2264 - /**
2265 - * Format email data
2266 - *
2267 - * @param array $atts
2268 - * @param array $notification
2269 - *
2270 - * @return void
2271 - */
2272 1820 private static function format_email_data( &$atts, $notification ) {
2273 1821 // Format email_to
2274 1822 self::format_email_to_data( $atts, $notification );
2275 1823
@@ -2277,16 +1825,14 @@
2277 1825 $reply_fields = array(
2278 1826 'reply_to' => '',
2279 1827 'reply_to_name' => '',
2280 1828 );
2281 -
2282 1829 foreach ( $reply_fields as $f => $val ) {
2283 1830 if ( isset( $notification[ $f ] ) ) {
2284 1831 $atts[ $f ] = $notification[ $f ];
2285 -
2286 - if ( 'custom' === $notification[ $f ] ) {
1832 + if ( 'custom' == $notification[ $f ] ) {
2287 1833 $atts[ $f ] = $notification[ 'cust_' . $f ];
2288 - } elseif ( is_numeric( $atts[ $f ] ) && $atts[ $f ] ) {
1834 + } elseif ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
2289 1835 $atts[ $f ] = '[' . $atts[ $f ] . ']';
2290 1836 }
2291 1837 }
2292 1838 unset( $f, $val );
@@ -2293,27 +1839,21 @@
2293 1839 }
2294 1840
2295 1841 // Format event
2296 1842 $atts['event'] = array( 'create' );
2297 -
2298 - // phpcs:ignore Universal.Operators.StrictComparisons
2299 1843 if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
2300 1844 $atts['event'][] = 'update';
2301 - } elseif ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) { // phpcs:ignore Universal.Operators.StrictComparisons
1845 + } elseif ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) {
2302 1846 $atts['event'] = array( 'update' );
2303 1847 }
2304 1848 }
2305 1849
2306 - /**
2307 - * Format email_to data
2308 - *
2309 - * @param array $atts
2310 - * @param array $notification
2311 - *
2312 - * @return void
2313 - */
2314 1850 private static function format_email_to_data( &$atts, $notification ) {
2315 - $atts['email_to'] = isset( $notification['email_to'] ) ? preg_split( '/ (,|;) /', $notification['email_to'] ) : array();
1851 + if ( isset( $notification['email_to'] ) ) {
1852 + $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
1853 + } else {
1854 + $atts['email_to'] = array();
1855 + }
2316 1856
2317 1857 if ( isset( $notification['also_email_to'] ) ) {
2318 1858 $email_fields = (array) $notification['also_email_to'];
2319 1859 $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] );
@@ -2320,36 +1860,24 @@
2320 1860 unset( $email_fields );
2321 1861 }
2322 1862
2323 1863 foreach ( $atts['email_to'] as $key => $email_field ) {
1864 +
2324 1865 if ( is_numeric( $email_field ) ) {
2325 1866 $atts['email_to'][ $key ] = '[' . $email_field . ']';
2326 1867 }
2327 1868
2328 - if ( ! str_contains( $email_field, '|' ) ) {
2329 - continue;
1869 + if ( strpos( $email_field, '|' ) ) {
1870 + $email_opt = explode( '|', $email_field );
1871 + if ( isset( $email_opt[0] ) ) {
1872 + $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
1873 + }
1874 + unset( $email_opt );
2330 1875 }
2331 -
2332 - $email_opt = explode( '|', $email_field );
2333 -
2334 - if ( isset( $email_opt[0] ) ) {
2335 - $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
2336 - }
2337 - unset( $email_opt );
2338 1876 }
2339 -
2340 1877 $atts['email_to'] = implode( ', ', $atts['email_to'] );
2341 1878 }
2342 1879
2343 - /**
2344 - * Setup new notification
2345 - *
2346 - * @param array $new_notification
2347 - * @param array $notification
2348 - * @param array $atts
2349 - *
2350 - * @return void
2351 - */
2352 1880 private static function setup_new_notification( &$new_notification, $notification, $atts ) {
2353 1881 // Set up new notification
2354 1882 $new_notification = array(
2355 1883 'post_content' => array(
@@ -2360,13 +1888,12 @@
2360 1888 );
2361 1889
2362 1890 // Add more fields to the new notification
2363 1891 $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
2364 -
2365 1892 foreach ( $add_fields as $add_field ) {
2366 1893 if ( isset( $notification[ $add_field ] ) ) {
2367 1894 $new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
2368 - } elseif ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ), true ) ) {
1895 + } elseif ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
2369 1896 $new_notification['post_content'][ $add_field ] = 0;
2370 1897 } else {
2371 1898 $new_notification['post_content'][ $add_field ] = '';
2372 1899 }
@@ -2377,9 +1904,9 @@
2377 1904 $new_notification['post_content']['reply_to'] = $atts['reply_to'];
2378 1905
2379 1906 // Set from
2380 1907 if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) {
2381 - $new_notification['post_content']['from'] = ( ! empty( $atts['reply_to_name'] ) ? $atts['reply_to_name'] : '[sitename]' ) . ' <' . ( ! empty( $atts['reply_to'] ) ? $atts['reply_to'] : '[admin_email]' ) . '>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1908 + $new_notification['post_content']['from'] = ( empty( $atts['reply_to_name'] ) ? '[sitename]' : $atts['reply_to_name'] ) . ' <' . ( empty( $atts['reply_to'] ) ? '[admin_email]' : $atts['reply_to'] ) . '>';
2382 1909 }
2383 1910 }
2384 1911
2385 1912 /**
@@ -2384,90 +1911,72 @@
2384 1911
2385 1912 /**
2386 1913 * Switch field IDs in pre-2.0 email conditional logic
2387 1914 *
2388 - * @param array $post_content Pass by reference.
2389 - *
2390 - * @return void
1915 + * @param $post_content array, pass by reference
2391 1916 */
2392 1917 private static function switch_email_condition_field_ids( &$post_content ) {
2393 1918 // Switch field IDs in conditional logic
2394 - if ( ! isset( $post_content['conditions'] ) || ! is_array( $post_content['conditions'] ) ) {
2395 - return;
2396 - }
2397 -
2398 - foreach ( $post_content['conditions'] as $email_key => $val ) {
2399 - if ( is_numeric( $email_key ) ) {
2400 - $post_content['conditions'][ $email_key ] = self::switch_action_field_ids( $val, array( 'hide_field' ) );
1919 + if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
1920 + foreach ( $post_content['conditions'] as $email_key => $val ) {
1921 + if ( is_numeric( $email_key ) ) {
1922 + $post_content['conditions'][ $email_key ] = self::switch_action_field_ids( $val, array( 'hide_field' ) );
1923 + }
1924 + unset( $email_key, $val );
2401 1925 }
2402 - unset( $email_key, $val );
2403 1926 }
2404 1927 }
2405 1928
2406 - /**
2407 - * Migrate autoresponder to action
2408 - *
2409 - * @param array $form_options
2410 - * @param int $form_id
2411 - * @param array $notifications
2412 - *
2413 - * @return void
2414 - */
2415 1929 private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
2416 - if ( empty( $form_options['auto_responder'] ) || empty( $form_options['ar_email_message'] ) ) {
2417 - return;
2418 - }
1930 + if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
1931 + // migrate autoresponder
2419 1932
2420 - // Migrate autoresponder
1933 + $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0;
1934 + if ( strpos( $email_field, '|' ) ) {
1935 + // data from entries field
1936 + $email_field = explode( '|', $email_field );
1937 + if ( isset( $email_field[1] ) ) {
1938 + $email_field = $email_field[1];
1939 + }
1940 + }
1941 + if ( is_numeric( $email_field ) && ! empty( $email_field ) ) {
1942 + $email_field = '[' . $email_field . ']';
1943 + }
2421 1944
2422 - $email_field = $form_options['ar_email_to'] ?? 0;
1945 + $notification = $form_options;
1946 + $new_notification2 = array(
1947 + 'post_content' => array(
1948 + 'email_message' => $notification['ar_email_message'],
1949 + 'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
1950 + 'email_to' => $email_field,
1951 + 'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
1952 + 'inc_user_info' => 0,
1953 + ),
1954 + 'post_name' => $form_id . '_email_' . count( $notifications ),
1955 + );
2423 1956
2424 - if ( str_contains( $email_field, '|' ) ) {
2425 - // Data from entries field
2426 - $email_field = explode( '|', $email_field );
1957 + $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : '';
1958 + $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : '';
2427 1959
2428 - if ( isset( $email_field[1] ) ) {
2429 - $email_field = $email_field[1];
1960 + if ( ! empty( $reply_to ) ) {
1961 + $new_notification2['post_content']['reply_to'] = $reply_to;
2430 1962 }
2431 - }
2432 1963
2433 - if ( is_numeric( $email_field ) && $email_field ) {
2434 - $email_field = '[' . $email_field . ']';
2435 - }
1964 + if ( ! empty( $reply_to ) || ! empty( $reply_to_name ) ) {
1965 + $new_notification2['post_content']['from'] = ( empty( $reply_to_name ) ? '[sitename]' : $reply_to_name ) . ' <' . ( empty( $reply_to ) ? '[admin_email]' : $reply_to ) . '>';
1966 + }
2436 1967
2437 - $notification = $form_options;
2438 - $new_notification2 = array(
2439 - 'post_content' => array(
2440 - 'email_message' => $notification['ar_email_message'],
2441 - 'email_subject' => $notification['ar_email_subject'] ?? '',
2442 - 'email_to' => $email_field,
2443 - 'plain_text' => $notification['ar_plain_text'] ?? 0,
2444 - 'inc_user_info' => 0,
2445 - ),
2446 - 'post_name' => $form_id . '_email_' . count( $notifications ),
2447 - );
2448 -
2449 - $reply_to = $notification['ar_reply_to'] ?? '';
2450 - $reply_to_name = $notification['ar_reply_to_name'] ?? '';
2451 -
2452 - if ( $reply_to ) {
2453 - $new_notification2['post_content']['reply_to'] = $reply_to;
1968 + $notifications[] = $new_notification2;
1969 + unset( $new_notification2 );
2454 1970 }
2455 -
2456 - if ( $reply_to || $reply_to_name ) {
2457 - $new_notification2['post_content']['from'] = ( $reply_to_name ? $reply_to_name : '[sitename]' ) . ' <' . ( $reply_to ? $reply_to : '[admin_email]' ) . '>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2458 - }
2459 -
2460 - $notifications[] = $new_notification2;
2461 - unset( $new_notification2 );
2462 1971 }
2463 1972
2464 1973 /**
2465 1974 * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2466 1975 *
2467 - * @param bool $loader
1976 + * @param boolean $disable
2468 1977 *
2469 - * @return bool
1978 + * @return boolean
2470 1979 */
2471 1980 public static function maybe_libxml_disable_entity_loader( $loader ) {
2472 1981 if ( version_compare( phpversion(), '8.0', '<' ) && function_exists( 'libxml_disable_entity_loader' ) ) {
2473 1982 $loader = libxml_disable_entity_loader( $loader ); // phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
@@ -2475,32 +1984,9 @@
2475 1984
2476 1985 return $loader;
2477 1986 }
2478 1987
2479 - /**
2480 - * PHP 8 backward compatibility for the libxml_disable_entity_loader function
2481 - *
2482 - * @return bool
2483 - */
2484 1988 public static function check_if_libxml_disable_entity_loader_exists() {
2485 1989 return version_compare( phpversion(), '8.0', '<' ) && ! function_exists( 'libxml_disable_entity_loader' );
2486 1990 }
1991 +}
2487 1992
2488 - /**
2489 - * Get the file types allowed for importing.
2490 - * This is used in the "accept" attribute for the file upload input on the XML import page.
2491 - *
2492 - * @since 6.8.3
2493 - *
2494 - * @return array
2495 - */
2496 - public static function get_supported_upload_file_types() {
2497 - $file_types = array( '.xml' );
2498 -
2499 - if ( FrmAppHelper::pro_is_installed() ) {
2500 - // CSV Importing is only available in Pro.
2501 - $file_types[] = '.csv';
2502 - }
2503 -
2504 - return $file_types;
2505 - }
2506 -}