PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.3
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/models/FrmFormMigrator.php +31 -184 6.265.3 View file →
@@ -4,51 +4,19 @@
4 4 }
5 5
6 6 abstract class FrmFormMigrator {
7 7
8 - /**
9 - * @var bool
10 - */
11 8 public $source_active;
12 9
13 - /**
14 - * @var string
15 - */
16 10 public $slug;
17 -
18 - /**
19 - * @var string
20 - */
21 11 public $path;
22 -
23 - /**
24 - * @var string
25 - */
26 12 public $name;
27 13
28 - /**
29 - * @var array
30 - */
31 14 public $response = array();
32 -
33 - /**
34 - * @var string
35 - */
36 15 public $tracking = 'frm_forms_imported';
37 16
38 - /**
39 - * @var array
40 - */
41 17 protected $fields_map = array();
42 -
43 - /**
44 - * @var mixed
45 - */
46 - protected $current_source_form;
47 -
48 - /**
49 - * @var array
50 - */
18 + protected $current_source_form = null;
51 19 protected $current_section = array();
52 20
53 21 /**
54 22 * Define required properties.
@@ -58,13 +26,12 @@
58 26 return;
59 27 }
60 28
61 29 if ( ! function_exists( 'is_plugin_active' ) ) {
62 - require_once ABSPATH . '/wp-admin/includes/plugin.php';
30 + require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
63 31 }
64 32
65 33 $this->source_active = is_plugin_active( $this->path );
66 -
67 34 if ( ! $this->source_active ) {
68 35 // if source plugin is not installed, do nothing
69 36 return;
70 37 }
@@ -76,27 +43,20 @@
76 43 'unsupported' => array(),
77 44 );
78 45 }
79 46
80 - /**
81 - * @return void
82 - */
83 47 private function maybe_add_to_import_page() {
84 48 add_action( 'frm_import_settings', array( $this, 'import_page' ) );
85 49 add_action( 'wp_ajax_frm_import_' . $this->slug, array( $this, 'import_forms' ) );
86 50 }
87 51
88 - /**
89 - * @return void
90 - */
91 52 public function import_page() {
92 - $forms = $this->get_forms();
93 53 ?>
94 54 <div class="wrap">
95 55 <h2 class="frm-h2"><?php echo esc_html( $this->name ); ?> Importer</h2>
96 56 <p class="howto">Import forms and settings automatically from <?php echo esc_html( $this->name ); ?>.</p>
97 - <div id="welcome-panel">
98 - <div style="margin-bottom:10px;">
57 + <div class="welcome-panel" id="welcome-panel">
58 + <div class="welcome-panel-content" style="text-align:center;margin-bottom:10px;">
99 59 <p class="about-description">
100 60 Select the forms to import.
101 61 </p>
102 62 <form class="frm_form_importer" method="post"
@@ -103,15 +63,15 @@
103 63 action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>">
104 64 <?php wp_nonce_field( 'nonce', 'frm_ajax' ); ?>
105 65 <input type="hidden" name="slug" value="<?php echo esc_attr( $this->slug ); ?>" />
106 66 <input type="hidden" name="action" value="frm_import_<?php echo esc_attr( $this->slug ); ?>" />
107 - <div style="max-width:400px;text-align:left;">
67 + <div style="margin:10px auto;max-width:400px;text-align:left;">
108 68 <?php
109 - if ( ! $forms ) {
69 + if ( empty( $this->get_forms() ) ) {
110 70 esc_html_e( 'No Forms Found.', 'formidable' );
111 71 }
112 72 ?>
113 - <?php foreach ( $forms as $form_id => $name ) { ?>
73 + <?php foreach ( $this->get_forms() as $form_id => $name ) { ?>
114 74 <p>
115 75 <label>
116 76 <input type="checkbox" name="form_id[]"
117 77 value="<?php echo esc_attr( $form_id ); ?>" checked="checked" />
@@ -125,23 +85,9 @@
125 85 </label>
126 86 </p>
127 87 <?php } ?>
128 88 </div>
129 - <?php
130 - $button_atts = array(
131 - 'type' => 'submit',
132 - 'class' => 'button button-primary frm-button-primary',
133 - );
134 -
135 - if ( ! $forms ) {
136 - $button_atts['disabled'] = 'disabled';
137 - }
138 - ?>
139 - <p class="submit">
140 - <button <?php FrmAppHelper::array_to_html_params( $button_atts, true ); ?>>
141 - <?php esc_html_e( 'Start Import', 'formidable' ); ?>
142 - </button>
143 - </p>
89 + <button type="submit" class="button button-primary button-hero">Start Import</button>
144 90 </form>
145 91 <div id="frm-importer-process" class="frm-importer-process frm_hidden">
146 92
147 93 <p class="process-count">
@@ -150,15 +96,10 @@
150 96 from <?php echo esc_html( $this->name ); ?>.
151 97 </p>
152 98
153 99 <p class="process-completed" class="frm_hidden">
154 - <?php
155 - printf(
156 - // translators: %s is the number of forms that were imported.
157 - esc_html__( 'The import process has finished! We have successfully imported %s forms. You can review the results below.', 'formidable' ),
158 - '<span class="forms-completed"></span>'
159 - );
160 - ?>
100 + The import process has finished! We have successfully imported
101 + <span class="forms-completed"></span> forms. You can review the results below.
161 102 </p>
162 103
163 104 <div class="status"></div>
164 105
@@ -170,10 +111,8 @@
170 111 }
171 112
172 113 /**
173 114 * Import all forms using ajax
174 - *
175 - * @return void
176 115 */
177 116 public function import_forms() {
178 117
179 118 check_ajax_referer( 'frm_ajax', 'nonce' );
@@ -188,10 +127,9 @@
188 127 );
189 128
190 129 if ( is_array( $forms ) ) {
191 130 $imported = array();
192 -
193 - foreach ( $forms as $form_id ) {
131 + foreach ( (array) $forms as $form_id ) {
194 132 $imported[] = $this->import_form( $form_id );
195 133 }
196 134 } else {
197 135 $imported = $this->import_form( $forms );
@@ -201,12 +139,8 @@
201 139 }
202 140
203 141 /**
204 142 * Import a single form
205 - *
206 - * @param int $source_id Source form ID.
207 - *
208 - * @return array
209 143 */
210 144 protected function import_form( $source_id ) {
211 145
212 146 $source_form = $this->get_form( $source_id );
@@ -240,14 +174,8 @@
240 174
241 175 return $response;
242 176 }
243 177
244 - /**
245 - * @param int|string $source_id
246 - * @param string $source_form_name
247 - *
248 - * @return array
249 - */
250 178 protected function prepare_new_form( $source_id, $source_form_name ) {
251 179 return array(
252 180 'import_form_id' => $source_id,
253 181 'fields' => array(),
@@ -257,24 +185,12 @@
257 185 'actions' => array(),
258 186 );
259 187 }
260 188
261 - /**
262 - * @param array|object $form
263 - * @param array $new_form
264 - *
265 - * @return void
266 - */
267 189 protected function prepare_form( $form, &$new_form ) {
268 190 // customize this function
269 191 }
270 192
271 - /**
272 - * @param array $fields
273 - * @param array $form
274 - *
275 - * @return void
276 - */
277 193 protected function prepare_fields( $fields, &$form ) {
278 194 $field_order = 1;
279 195
280 196 foreach ( $fields as $field ) {
@@ -303,9 +219,8 @@
303 219
304 220 $this->prepare_field( $field, $new_field );
305 221
306 222 $in_section = ! empty( $this->current_section ) && ! in_array( $new_type, $this->fields_with_end() ) && $new_type !== 'break';
307 -
308 223 if ( $in_section ) {
309 224 $new_field['field_options']['in_section'] = $this->current_section['id'];
310 225 }
311 226
@@ -316,28 +231,22 @@
316 231 } elseif ( $new_type === 'break' || $new_type === 'end_divider' ) {
317 232 $this->current_section = array();
318 233 }
319 234
320 - // This may occasionally skip one level/order e.g. after adding a
235 + // This may occassionally skip one level/order e.g. after adding a
321 236 // list field, as field_order would already be prepared to be used.
322 - ++$field_order;
237 + $field_order ++;
323 238
324 - if ( ! empty( $new_field['fields'] ) && is_array( $new_field['fields'] ) ) {
239 + if ( isset( $new_field['fields'] ) && is_array( $new_field['fields'] ) && ! empty( $new_field['fields'] ) ) {
325 240 // we have (inner) fields to merge
326 241
327 242 $form['fields'] = array_merge( $form['fields'], $new_field['fields'] );
328 243 // set the new field_order as it would have changed
329 - $field_order = $new_field['current_order'];
244 + $field_order = $new_field['current_order'];
330 245 }
331 - }//end foreach
246 + }
332 247 }
333 248
334 - /**
335 - * @param array|object $field
336 - * @param array $new_field
337 - *
338 - * @return void
339 - */
340 249 protected function prepare_field( $field, &$new_field ) {
341 250 // customize this function
342 251 }
343 252
@@ -344,10 +253,8 @@
344 253 /**
345 254 * Add any field types that will need an end section field.
346 255 *
347 256 * @since 4.04.03
348 - *
349 - * @return array
350 257 */
351 258 protected function fields_with_end() {
352 259 return array( 'divider' );
353 260 }
@@ -353,16 +260,11 @@
353 260 }
354 261
355 262 /**
356 263 * @since 4.04.03
357 - *
358 - * @param array $fields
359 - *
360 - * @return void
361 264 */
362 265 protected function maybe_add_end_fields( &$fields ) {
363 266 $with_end = $this->fields_with_end();
364 -
365 267 if ( empty( $with_end ) ) {
366 268 return;
367 269 }
368 270
@@ -368,14 +270,12 @@
368 270
369 271 $open = array();
370 272
371 273 $order = 0;
372 -
373 274 foreach ( $fields as $field ) {
374 - ++$order;
275 + $order ++;
375 276 $type = $this->get_field_type( $field );
376 277 $new_type = $this->convert_field_type( $type, $field );
377 -
378 278 if ( ! in_array( $new_type, $with_end ) && $new_type !== 'break' ) {
379 279 continue;
380 280 }
381 281
@@ -395,13 +295,8 @@
395 295 }
396 296
397 297 /**
398 298 * @since 4.04.03
399 - *
400 - * @param array $fields
401 - * @param int $order
402 - *
403 - * @return void
404 299 */
405 300 protected function insert_end_section( &$fields, &$order ) {
406 301 $sub = FrmFieldsHelper::setup_new_vars( 'end_divider' );
407 302 $sub['name'] = __( 'Section Buttons', 'formidable' );
@@ -406,9 +301,9 @@
406 301 $sub = FrmFieldsHelper::setup_new_vars( 'end_divider' );
407 302 $sub['name'] = __( 'Section Buttons', 'formidable' );
408 303 $subs = array( $sub );
409 304 $this->insert_fields_in_array( $subs, $order, 0, $fields );
410 - ++$order;
305 + $order ++;
411 306 }
412 307
413 308 /**
414 309 * Replace the original combo field with a group.
@@ -414,15 +309,8 @@
414 309 * Replace the original combo field with a group.
415 310 * This switches the name field to individual fields.
416 311 *
417 312 * @since 4.04.03
418 - *
419 - * @param array $subs
420 - * @param int $start
421 - * @param int $remove
422 - * @param array $fields
423 - *
424 - * @return void
425 313 */
426 314 protected function insert_fields_in_array( $subs, $start, $remove, &$fields ) {
427 315 array_splice( $fields, $start, $remove, $subs );
428 316 }
@@ -434,14 +322,12 @@
434 322 * This also eases the recursive use of the method,
435 323 * particularly the overrides in child classes, as
436 324 * there will be no need to rebuild the converter
437 325 * array at usage locations.
438 - *
439 - * @return string
440 326 */
441 327 protected function convert_field_type( $type, $field = array(), $use = '' ) {
442 328 if ( empty( $field ) ) {
443 - // For reverse compatibility.
329 + // For reverse compatability.
444 330 return $type;
445 331 }
446 332
447 333 return $use ? $use : $field['type'];
@@ -447,14 +333,12 @@
447 333 return $use ? $use : $field['type'];
448 334 }
449 335
450 336 /**
451 - * Add the new form to the database and return AJAX data.
337 + * Add the new form to the database and return AJAX data.å
452 338 *
453 339 * @param array $form Form to import.
454 - * @param array $upgrade_omit No field alternative.
455 - *
456 - * @return array
340 + * @param array $upgrade_omit No field alternative
457 341 */
458 342 protected function add_form( $form, $upgrade_omit = array() ) {
459 343
460 344 // Create empty form so we have an ID to work with.
@@ -485,9 +369,9 @@
485 369 * @param array $form parameters for the new form to be created. Only
486 370 * the name key is a must. The keys are the column
487 371 * names of the forms table in the DB.
488 372 *
489 - * @return bool|int The ID of the newly created form or false on failure.
373 + * @return int The ID of the newly created form.
490 374 */
491 375 protected function create_form( $form ) {
492 376 $form['form_key'] = $form['name'];
493 377 $form['status'] = 'published';
@@ -496,12 +380,8 @@
496 380 }
497 381
498 382 /**
499 383 * @since 4.04.03
500 - *
501 - * @param array $form
502 - *
503 - * @return array
504 384 */
505 385 protected function form_creation_error_response( $form ) {
506 386 return array(
507 387 'error' => true,
@@ -512,12 +392,10 @@
512 392
513 393 /**
514 394 * @since 4.04.03
515 395 *
516 - * @param int $form_id
396 + * @param int $form_id
517 397 * @param array $form
518 - *
519 - * @return void
520 398 */
521 399 protected function create_fields( $form_id, &$form ) {
522 400 foreach ( $form['fields'] as $key => $new_field ) {
523 401 $new_field['form_id'] = $form_id;
@@ -527,12 +405,9 @@
527 405
528 406 /**
529 407 * @since 4.04.03
530 408 *
531 - * @param array $form
532 - * @param int|string $form_id
533 - *
534 - * @return void
409 + * @param array $form
535 410 */
536 411 protected function create_emails( $form, $form_id ) {
537 412 foreach ( $form['actions'] as $action ) {
538 413 $this->save_action( $action, $form, $form_id );
@@ -541,22 +416,14 @@
541 416
542 417 /**
543 418 * @since 4.04.03
544 419 *
545 - * @param array $action
546 420 * @param array $form
547 - * @param int $form_id
548 - *
549 - * @return int|WP_Error
550 421 */
551 422 protected function save_action( $action, $form, $form_id ) {
552 - /**
553 - * @var FrmFormAction
554 - */
555 423 $action_control = FrmFormActionsController::get_form_actions( $action['type'] );
556 424 unset( $action['type'] );
557 425 $new_action = $action_control->prepare_new( $form_id );
558 -
559 426 foreach ( $action as $key => $value ) {
560 427 if ( $key === 'post_title' ) {
561 428 $new_action->post_title = $value;
562 429 } elseif ( $key === 'ID' ) {
@@ -577,12 +444,10 @@
577 444 * After a form has been successfully imported we track it, so that in the
578 445 * future we can alert users if they try to import a form that has already
579 446 * been imported.
580 447 *
581 - * @param int $source_id Imported plugin form ID.
582 - * @param int $new_form_id Formidable form ID.
583 - *
584 - * @return void
448 + * @param int $source_id Imported plugin form ID
449 + * @param int $new_form_id Formidable form ID
585 450 */
586 451 protected function track_import( $source_id, $new_form_id ) {
587 452
588 453 $imported = $this->get_tracked_import();
@@ -599,9 +464,9 @@
599 464 return get_option( $this->tracking, array() );
600 465 }
601 466
602 467 /**
603 - * @param int $source_id Imported plugin form ID.
468 + * @param int $source_id Imported plugin form ID
604 469 *
605 470 * @return int the ID of the created form or 0
606 471 */
607 472 private function is_imported( $source_id ) {
@@ -606,15 +471,13 @@
606 471 */
607 472 private function is_imported( $source_id ) {
608 473 $imported = $this->get_tracked_import();
609 474 $new_form_id = 0;
610 -
611 475 if ( ! isset( $imported[ $this->slug ] ) || ! in_array( $source_id, $imported[ $this->slug ] ) ) {
612 476 return $new_form_id;
613 477 }
614 478
615 479 $new_form_id = array_search( $source_id, array_reverse( $imported[ $this->slug ], true ) );
616 -
617 480 if ( ! empty( $new_form_id ) && empty( FrmForm::get_key_by_id( $new_form_id ) ) ) {
618 481 // Allow reimport if the form was deleted.
619 482 $new_form_id = 0;
620 483 }
@@ -630,13 +493,8 @@
630 493 protected function unsupported_field_types() {
631 494 return array();
632 495 }
633 496
634 - /**
635 - * @param string $type
636 - *
637 - * @return bool
638 - */
639 497 private function is_unsupported_field( $type ) {
640 498 $fields = $this->unsupported_field_types();
641 499
642 500 return in_array( $type, $fields, true );
@@ -650,13 +508,8 @@
650 508 protected function skip_pro_fields() {
651 509 return array();
652 510 }
653 511
654 - /**
655 - * @param string $type
656 - *
657 - * @return bool
658 - */
659 512 protected function should_skip_field( $type ) {
660 513 $skip_pro_fields = $this->skip_pro_fields();
661 514
662 515 return ( ! FrmAppHelper::pro_is_installed() && in_array( $type, $skip_pro_fields, true ) );
@@ -665,9 +518,9 @@
665 518 /**
666 519 * Replace 3rd-party form provider tags/shortcodes with our own Tags.
667 520 *
668 521 * @param string $string String to process the smart tag in.
669 - * @param array $fields List of fields for the form.
522 + * @param array $fields List of fields for the form.
670 523 *
671 524 * @return string
672 525 */
673 526 protected function replace_smart_tags( $string, $fields ) {
@@ -682,19 +535,14 @@
682 535 public function get_forms() {
683 536 return array();
684 537 }
685 538
686 - /**
687 - * @param int|string $id
688 - *
689 - * @return array
690 - */
691 539 public function get_form( $id ) {
692 540 return array();
693 541 }
694 542
695 543 /**
696 - * @param array|object $source_form
544 + * @param object|array $source_form
697 545 *
698 546 * @return string
699 547 */
700 548 protected function get_form_name( $source_form ) {
@@ -701,9 +549,9 @@
701 549 return __( 'Default Form', 'formidable' );
702 550 }
703 551
704 552 /**
705 - * @param array|object $source_form
553 + * @param object|array $source_form
706 554 *
707 555 * @return array
708 556 */
709 557 protected function get_form_fields( $source_form ) {
@@ -724,10 +572,9 @@
724 572 *
725 573 * @return string
726 574 */
727 575 protected function get_field_label( $field ) {
728 - $label = $field['label'] ?? '';
729 -
576 + $label = isset( $field['label'] ) ? $field['label'] : '';
730 577 if ( ! empty( $label ) ) {
731 578 return $label;
732 579 }
733 580