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