PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +39 -40 6.26 → trunk View file →
@@ -37,9 +37,9 @@
37 37
38 38 /**
39 39 * @var array
40 40 */
41 - protected $fields_map = array();
41 + protected $fields_map = array();
42 42
43 43 /**
44 44 * @var mixed
45 45 */
@@ -47,9 +47,9 @@
47 47
48 48 /**
49 49 * @var array
50 50 */
51 - protected $current_section = array();
51 + protected $current_section = array();
52 52
53 53 /**
54 54 * Define required properties.
55 55 */
@@ -64,9 +64,9 @@
64 64
65 65 $this->source_active = is_plugin_active( $this->path );
66 66
67 67 if ( ! $this->source_active ) {
68 - // if source plugin is not installed, do nothing
68 + // If source plugin is not installed, do nothing
69 69 return;
70 70 }
71 71
72 72 $this->maybe_add_to_import_page();
@@ -89,8 +89,9 @@
89 89 * @return void
90 90 */
91 91 public function import_page() {
92 92 $forms = $this->get_forms();
93 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
93 94 ?>
94 95 <div class="wrap">
95 96 <h2 class="frm-h2"><?php echo esc_html( $this->name ); ?> Importer</h2>
96 97 <p class="howto">Import forms and settings automatically from <?php echo esc_html( $this->name ); ?>.</p>
@@ -166,8 +167,9 @@
166 167 </div>
167 168 </div>
168 169 </div>
169 170 <?php
171 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
170 172 }
171 173
172 174 /**
173 175 * Import all forms using ajax
@@ -174,9 +176,8 @@
174 176 *
175 177 * @return void
176 178 */
177 179 public function import_forms() {
178 -
179 180 check_ajax_referer( 'frm_ajax', 'nonce' );
180 181 FrmAppHelper::permission_check( 'frm_edit_forms' );
181 182
182 183 $forms = FrmAppHelper::get_simple_request(
@@ -207,9 +208,8 @@
207 208 *
208 209 * @return array
209 210 */
210 211 protected function import_form( $source_id ) {
211 -
212 212 $source_form = $this->get_form( $source_id );
213 213 $source_form_name = $this->get_form_name( $source_form );
214 214 $source_fields = $this->get_form_fields( $source_form );
215 215 $this->maybe_add_end_fields( $source_fields );
@@ -216,9 +216,9 @@
216 216
217 217 $this->current_source_form = $source_form;
218 218
219 219 // If form does not contain fields, bail.
220 - if ( empty( $source_fields ) ) {
220 + if ( ! $source_fields ) {
221 221 wp_send_json_success(
222 222 array(
223 223 'error' => true,
224 224 'name' => esc_html( $source_form_name ),
@@ -264,9 +264,9 @@
264 264 *
265 265 * @return void
266 266 */
267 267 protected function prepare_form( $form, &$new_form ) {
268 - // customize this function
268 + // Customize this function
269 269 }
270 270
271 271 /**
272 272 * @param array $fields
@@ -278,13 +278,12 @@
278 278 $field_order = 1;
279 279
280 280 foreach ( $fields as $field ) {
281 281 $field = (array) $field;
282 -
283 282 $label = $this->get_field_label( $field );
284 283 $type = $this->get_field_type( $field );
285 284
286 - // check if field is unsupported. If unsupported make note and continue
285 + // Check if field is unsupported. If unsupported make note and continue
287 286 if ( $this->is_unsupported_field( $type ) ) {
288 287 $this->response['unsupported'][] = $label;
289 288 continue;
290 289 }
@@ -293,10 +292,9 @@
293 292 $this->response['upgrade_omit'][] = $label;
294 293 continue;
295 294 }
296 295
297 - $new_type = $this->convert_field_type( $type, $field );
298 -
296 + $new_type = $this->convert_field_type( $type, $field );
299 297 $new_field = FrmFieldsHelper::setup_new_vars( $new_type );
300 298 $new_field['name'] = $label;
301 299 $new_field['field_order'] = $field_order;
302 300 $new_field['original'] = $type;
@@ -302,9 +300,9 @@
302 300 $new_field['original'] = $type;
303 301
304 302 $this->prepare_field( $field, $new_field );
305 303
306 - $in_section = ! empty( $this->current_section ) && ! in_array( $new_type, $this->fields_with_end() ) && $new_type !== 'break';
304 + $in_section = $this->current_section && ! in_array( $new_type, $this->fields_with_end(), true ) && $new_type !== 'break';
307 305
308 306 if ( $in_section ) {
309 307 $new_field['field_options']['in_section'] = $this->current_section['id'];
310 308 }
@@ -310,9 +308,9 @@
310 308 }
311 309
312 310 $form['fields'][] = $new_field;
313 311
314 - if ( in_array( $new_type, $this->fields_with_end() ) ) {
312 + if ( in_array( $new_type, $this->fields_with_end(), true ) ) {
315 313 $this->current_section = $field;
316 314 } elseif ( $new_type === 'break' || $new_type === 'end_divider' ) {
317 315 $this->current_section = array();
318 316 }
@@ -317,18 +315,20 @@
317 315 $this->current_section = array();
318 316 }
319 317
320 318 // This may occasionally skip one level/order e.g. after adding a
321 - // list field, as field_order would already be prepared to be used.
319 + // List field, as field_order would already be prepared to be used.
322 320 ++$field_order;
323 321
324 - if ( ! empty( $new_field['fields'] ) && is_array( $new_field['fields'] ) ) {
325 - // we have (inner) fields to merge
322 + if ( empty( $new_field['fields'] ) || ! is_array( $new_field['fields'] ) ) {
323 + continue;
324 + }
326 325
327 - $form['fields'] = array_merge( $form['fields'], $new_field['fields'] );
328 - // set the new field_order as it would have changed
329 - $field_order = $new_field['current_order'];
330 - }
326 + // we have (inner) fields to merge
327 +
328 + $form['fields'] = array_merge( $form['fields'], $new_field['fields'] );
329 + // Set the new field_order as it would have changed
330 + $field_order = $new_field['current_order'];
331 331 }//end foreach
332 332 }
333 333
334 334 /**
@@ -337,9 +337,9 @@
337 337 *
338 338 * @return void
339 339 */
340 340 protected function prepare_field( $field, &$new_field ) {
341 - // customize this function
341 + // Customize this function
342 342 }
343 343
344 344 /**
345 345 * Add any field types that will need an end section field.
@@ -361,14 +361,13 @@
361 361 */
362 362 protected function maybe_add_end_fields( &$fields ) {
363 363 $with_end = $this->fields_with_end();
364 364
365 - if ( empty( $with_end ) ) {
365 + if ( ! $with_end ) {
366 366 return;
367 367 }
368 368
369 - $open = array();
370 -
369 + $open = array();
371 370 $order = 0;
372 371
373 372 foreach ( $fields as $field ) {
374 373 ++$order;
@@ -374,23 +373,23 @@
374 373 ++$order;
375 374 $type = $this->get_field_type( $field );
376 375 $new_type = $this->convert_field_type( $type, $field );
377 376
378 - if ( ! in_array( $new_type, $with_end ) && $new_type !== 'break' ) {
377 + if ( ! in_array( $new_type, $with_end, true ) && $new_type !== 'break' ) {
379 378 continue;
380 379 }
381 380
382 - if ( ! empty( $open ) ) {
381 + if ( $open ) {
383 382 $this->insert_end_section( $fields, $order );
384 383 $open = array();
385 384 }
386 385
387 - if ( in_array( $new_type, $with_end ) ) {
386 + if ( in_array( $new_type, $with_end, true ) ) {
388 387 $open = $field;
389 388 }
390 389 }
391 390
392 - if ( ! empty( $open ) ) {
391 + if ( $open ) {
393 392 $this->insert_end_section( $fields, $order );
394 393 }
395 394 }
396 395
@@ -438,9 +437,9 @@
438 437 *
439 438 * @return string
440 439 */
441 440 protected function convert_field_type( $type, $field = array(), $use = '' ) {
442 - if ( empty( $field ) ) {
441 + if ( ! $field ) {
443 442 // For reverse compatibility.
444 443 return $type;
445 444 }
446 445
@@ -455,13 +454,12 @@
455 454 *
456 455 * @return array
457 456 */
458 457 protected function add_form( $form, $upgrade_omit = array() ) {
459 -
460 458 // Create empty form so we have an ID to work with.
461 459 $form_id = $this->create_form( $form );
462 460
463 - if ( empty( $form_id ) ) {
461 + if ( ! $form_id ) {
464 462 return $this->form_creation_error_response( $form );
465 463 }
466 464
467 465 $this->create_fields( $form_id, $form );
@@ -583,9 +581,8 @@
583 581 *
584 582 * @return void
585 583 */
586 584 protected function track_import( $source_id, $new_form_id ) {
587 -
588 585 $imported = $this->get_tracked_import();
589 586
590 587 $imported[ $this->slug ][ $new_form_id ] = $source_id;
591 588
@@ -607,17 +604,19 @@
607 604 private function is_imported( $source_id ) {
608 605 $imported = $this->get_tracked_import();
609 606 $new_form_id = 0;
610 607
608 + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
611 609 if ( ! isset( $imported[ $this->slug ] ) || ! in_array( $source_id, $imported[ $this->slug ] ) ) {
612 610 return $new_form_id;
613 611 }
614 612
613 + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
615 614 $new_form_id = array_search( $source_id, array_reverse( $imported[ $this->slug ], true ) );
616 615
617 - if ( ! empty( $new_form_id ) && empty( FrmForm::get_key_by_id( $new_form_id ) ) ) {
616 + if ( $new_form_id && ! FrmForm::get_key_by_id( $new_form_id ) ) {
618 617 // Allow reimport if the form was deleted.
619 - $new_form_id = 0;
618 + return 0;
620 619 }
621 620
622 621 return $new_form_id;
623 622 }
@@ -636,11 +635,9 @@
636 635 *
637 636 * @return bool
638 637 */
639 638 private function is_unsupported_field( $type ) {
640 - $fields = $this->unsupported_field_types();
641 -
642 - return in_array( $type, $fields, true );
639 + return in_array( $type, $this->unsupported_field_types(), true );
643 640 }
644 641
645 642 /**
646 643 * Strict PRO fields with no Lite alternatives.
@@ -656,11 +653,13 @@
656 653 *
657 654 * @return bool
658 655 */
659 656 protected function should_skip_field( $type ) {
660 - $skip_pro_fields = $this->skip_pro_fields();
657 + if ( FrmAppHelper::pro_is_installed() ) {
658 + return false;
659 + }
661 660
662 - return ( ! FrmAppHelper::pro_is_installed() && in_array( $type, $skip_pro_fields, true ) );
661 + return in_array( $type, $this->skip_pro_fields(), true );
663 662 }
664 663
665 664 /**
666 665 * Replace 3rd-party form provider tags/shortcodes with our own Tags.
@@ -726,9 +725,9 @@
726 725 */
727 726 protected function get_field_label( $field ) {
728 727 $label = $field['label'] ?? '';
729 728
730 - if ( ! empty( $label ) ) {
729 + if ( $label ) {
731 730 return $label;
732 731 }
733 732
734 733 $type = $this->get_field_type( $field );