PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.19
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.19
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/FrmMigrate.php +26 -168 6.276.19 View file →
@@ -3,27 +3,11 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmMigrate {
7 -
8 - /**
9 - * @var string
10 - */
11 7 public $fields;
12 -
13 - /**
14 - * @var string
15 - */
16 8 public $forms;
17 -
18 - /**
19 - * @var string
20 - */
21 9 public $entries;
22 -
23 - /**
24 - * @var string
25 - */
26 10 public $entry_metas;
27 11
28 12 public function __construct() {
29 13 global $wpdb;
@@ -32,11 +16,8 @@
32 16 $this->entries = $wpdb->prefix . 'frm_items';
33 17 $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
34 18 }
35 19
36 - /**
37 - * @return void
38 - */
39 20 public function upgrade() {
40 21 do_action( 'frm_before_install' );
41 22
42 23 global $wpdb, $frm_vars;
@@ -51,10 +32,8 @@
51 32 )
52 33 );
53 34
54 35 if ( $needs_upgrade ) {
55 - $this->maybe_delete_htaccess_file();
56 -
57 36 // update rewrite rules for views and other custom post types
58 37 flush_rewrite_rules();
59 38
60 39 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
@@ -73,10 +52,8 @@
73 52
74 53 if ( false === get_option( 'frm_first_activation' ) ) {
75 54 update_option( 'frm_first_activation', time(), false );
76 55 }
77 -
78 - $this->update_settings_for_new_install();
79 56 }
80 57 }//end if
81 58
82 59 do_action( 'frm_after_install' );
@@ -92,46 +69,8 @@
92 69 }
93 70 }
94 71
95 72 /**
96 - * Check if the .htaccess file should be deleted based on server response.
97 - * If a server has AllowOverride FileInfo but not AllowOverride AuthConfig, JS and CSS files
98 - * will result in a 500 error.
99 - *
100 - * @since 6.27
101 - *
102 - * @return void
103 - */
104 - private function maybe_delete_htaccess_file() {
105 - $css_file_request = wp_remote_get( FrmAppHelper::plugin_url() . '/css/frm_fonts.css' );
106 -
107 - if ( 200 === wp_remote_retrieve_response_code( $css_file_request ) ) {
108 - return;
109 - }
110 -
111 - $htaccess_path = FrmAppHelper::plugin_path() . '/.htaccess';
112 -
113 - if ( file_exists( $htaccess_path ) ) {
114 - wp_delete_file( $htaccess_path );
115 - }
116 - }
117 -
118 - /**
119 - * Updates some settings for new installs.
120 - *
121 - * @since 6.23
122 - *
123 - * @return void
124 - */
125 - private function update_settings_for_new_install() {
126 - $settings = FrmAppHelper::get_settings();
127 -
128 - $settings->denylist_check = 1;
129 - $settings->installed_after_welcome_tour_update = 1;
130 - $settings->store();
131 - }
132 -
133 - /**
134 73 * If we fail to create the database tables, add an inbox notice.
135 74 * This informs the user that they need to correct the issue and try again.
136 75 *
137 76 * @since 6.19
@@ -151,9 +90,9 @@
151 90
152 91 $message = array(
153 92 'key' => 'failed-to-create-tables',
154 93 'subject' => 'Something went wrong setting up the database',
155 - 'message' => 'For steps to continue, see our <a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">documentation</a>. If you need assistance, we recommend that you reach out to your hosting provider. Then <a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_add_tables=1' ) ) . '">click here</a> to try again.', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
94 + 'message' => 'For steps to continue, see our <a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">documentation</a>. If you need assistance, we recommend that you reach out to your hosting provider. Then <a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_add_tables=1' ) ) . '">click here</a> to try again.',
156 95 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>',
157 96 'type' => 'error',
158 97 );
159 98
@@ -165,14 +104,15 @@
165 104 * @return string
166 105 */
167 106 public function collation() {
168 107 global $wpdb;
169 - return $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : '';
108 + if ( ! $wpdb->has_cap( 'collation' ) ) {
109 + return '';
110 + }
111 +
112 + return $wpdb->get_charset_collate();
170 113 }
171 114
172 - /**
173 - * @return void
174 - */
175 115 private function create_tables() {
176 116 $charset_collate = $this->collation();
177 117 $sql = array();
178 118
@@ -308,9 +248,8 @@
308 248 * @since 6.6
309 249 *
310 250 * @param string $table_name
311 251 * @param string $index_name
312 - *
313 252 * @return bool
314 253 */
315 254 private static function index_exists( $table_name, $index_name ) {
316 255 global $wpdb;
@@ -326,14 +265,10 @@
326 265 );
327 266 return (bool) $row;
328 267 }
329 268
330 - /**
331 - * @return void
332 - */
333 269 private function maybe_create_contact_form() {
334 270 $form_exists = FrmForm::get_id_by_key( 'contact-form' );
335 -
336 271 if ( ! $form_exists ) {
337 272 $this->add_default_template();
338 273 }
339 274 }
@@ -341,10 +276,8 @@
341 276 /**
342 277 * Create the default contact form
343 278 *
344 279 * @since 3.06
345 - *
346 - * @return void
347 280 */
348 281 private function add_default_template() {
349 282 if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
350 283 // XML import is not enabled on your server.
@@ -352,9 +285,10 @@
352 285 }
353 286
354 287 $set_err = libxml_use_internal_errors( true );
355 288 $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
356 - $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml';
289 +
290 + $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml';
357 291 FrmXMLHelper::import_xml( $file );
358 292
359 293 libxml_use_internal_errors( $set_err );
360 294 FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
@@ -361,17 +295,14 @@
361 295 }
362 296
363 297 /**
364 298 * @param int|string $old_db_version
365 - *
366 - * @return void
367 299 */
368 300 private function migrate_data( $old_db_version ) {
369 301 if ( ! $old_db_version ) {
370 302 $old_db_version = get_option( 'frm_db_version' );
371 303 }
372 -
373 - if ( str_contains( $old_db_version, '-' ) ) {
304 + if ( strpos( $old_db_version, '-' ) ) {
374 305 $last_upgrade = explode( '-', $old_db_version );
375 306 $old_db_version = (int) $last_upgrade[1];
376 307 }
377 308
@@ -379,10 +310,9 @@
379 310 // bail if we don't know the previous version
380 311 return;
381 312 }
382 313
383 - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 );
384 -
314 + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101 );
385 315 foreach ( $migrations as $migration ) {
386 316 if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
387 317 $function_name = 'migrate_to_' . $migration;
388 318 $this->$function_name();
@@ -415,9 +345,8 @@
415 345
416 346 // Delete roles.
417 347 $frm_roles = FrmAppHelper::frm_capabilities();
418 348 $roles = get_editable_roles();
419 -
420 349 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
421 350 foreach ( $roles as $role => $details ) {
422 351 $wp_roles->remove_cap( $role, $frm_role );
423 352 unset( $role, $details );
@@ -431,10 +360,9 @@
431 360 // prevent the post deletion from triggering entries to be deleted
432 361 remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
433 362 remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
434 363
435 - $post_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type in (%s, %s, %s)', FrmFormActionsController::$action_post_type, FrmStylesController::$post_type, 'frm_display' ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
436 -
364 + $post_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type in (%s, %s, %s)', FrmFormActionsController::$action_post_type, FrmStylesController::$post_type, 'frm_display' ) );
437 365 foreach ( $post_ids as $post_id ) {
438 366 // Delete's each post.
439 367 wp_delete_post( $post_id, true );
440 368 }
@@ -445,9 +373,9 @@
445 373 delete_transient( 'frm_options' );
446 374 delete_transient( 'frmpro_options' );
447 375 delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME );
448 376
449 - $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
377 + $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
450 378
451 379 do_action( 'frm_after_uninstall' );
452 380
453 381 return true;
@@ -453,31 +381,11 @@
453 381 return true;
454 382 }
455 383
456 384 /**
457 - * In older versions of Lite, it's possible we've saved the wrong location ID.
458 - * So force it to get valid values again.
459 - *
460 - * @since 6.25
461 - *
462 - * @return void
463 - */
464 - private function migrate_to_104() {
465 - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'test' ) ) {
466 - FrmSquareLiteConnectHelper::get_location_id( true, 'test' );
467 - }
468 -
469 - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'live' ) ) {
470 - FrmSquareLiteConnectHelper::get_location_id( true, 'live' );
471 - }
472 - }
473 -
474 - /**
475 385 * Disables summary email for multisite (not the main site) if recipient setting isn't changed.
476 386 *
477 387 * @since 6.8
478 - *
479 - * @return void
480 388 */
481 389 private function migrate_to_101() {
482 390 if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) {
483 391 return;
@@ -483,9 +391,8 @@
483 391 return;
484 392 }
485 393
486 394 $frm_settings = FrmAppHelper::get_settings();
487 -
488 395 if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) {
489 396 // User changed it.
490 397 return;
491 398 }
@@ -497,10 +404,8 @@
497 404 /**
498 405 * Clear frmpro_css transient.
499 406 *
500 407 * @since 4.10.02
501 - *
502 - * @return void
503 408 */
504 409 private function migrate_to_98() {
505 410 delete_transient( 'frmpro_css' );
506 411 }
@@ -508,10 +413,8 @@
508 413 /**
509 414 * Move default_blank and clear_on_focus to placeholder.
510 415 *
511 416 * @since 4.0
512 - *
513 - * @return void
514 417 */
515 418 private function migrate_to_97() {
516 419 $this->migrate_to_placeholder( 'clear_on_focus' );
517 420 $this->migrate_to_placeholder( 'default_blank' );
@@ -520,12 +423,8 @@
520 423 /**
521 424 * Move clear_on_focus or default_blank to placeholder.
522 425 *
523 426 * @since 4.0
524 - *
525 - * @param string $type Field option key to migrate.
526 - *
527 - * @return void
528 427 */
529 428 private function migrate_to_placeholder( $type = 'clear_on_focus' ) {
530 429 $query = array(
531 430 'field_options like' => '"' . $type . '";s:1:"1";',
@@ -536,10 +435,9 @@
536 435 foreach ( $fields as $field ) {
537 436 FrmAppHelper::unserialize_or_decode( $field->field_options );
538 437 FrmAppHelper::unserialize_or_decode( $field->options );
539 438 $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type );
540 -
541 - if ( ! $update_values ) {
439 + if ( empty( $update_values ) ) {
542 440 continue;
543 441 }
544 442
545 443 FrmField::update( $field->id, $update_values );
@@ -550,15 +448,11 @@
550 448 /**
551 449 * Delete unneeded default templates
552 450 *
553 451 * @since 3.06
554 - *
555 - * @return void
556 452 */
557 453 private function migrate_to_90() {
558 454 $form = FrmForm::getOne( 'contact' );
559 -
560 - // phpcs:ignore Universal.Operators.StrictComparisons
561 455 if ( $form && $form->default_template == 1 ) {
562 456 FrmForm::destroy( 'contact' );
563 457 }
564 458 }
@@ -566,15 +460,14 @@
566 460 /**
567 461 * Reverse migration 17 -- Divide by 9
568 462 *
569 463 * @since 3.0.05
570 - *
571 - * @return void
572 464 */
573 465 private function migrate_to_86() {
466 +
574 467 $fields = $this->get_fields_with_size();
575 468
576 - foreach ( $fields as $f ) {
469 + foreach ( (array) $fields as $f ) {
577 470 FrmAppHelper::unserialize_or_decode( $f->field_options );
578 471 $size = $f->field_options['size'];
579 472 $this->maybe_convert_migrated_size( $size );
580 473
@@ -588,10 +481,9 @@
588 481 }
589 482
590 483 // reverse the extra size changes in widgets
591 484 $widgets = get_option( 'widget_frm_show_form' );
592 -
593 - if ( ! $widgets ) {
485 + if ( empty( $widgets ) ) {
594 486 return;
595 487 }
596 488
597 489 $this->revert_widget_field_size();
@@ -596,11 +488,8 @@
596 488
597 489 $this->revert_widget_field_size();
598 490 }
599 491
600 - /**
601 - * @return array
602 - */
603 492 private function get_fields_with_size() {
604 493 $field_types = array(
605 494 'textarea',
606 495 'text',
@@ -628,20 +517,16 @@
628 517 /**
629 518 * Reverse the extra size changes in widgets
630 519 *
631 520 * @since 3.0.05
632 - *
633 - * @return void
634 521 */
635 522 private function revert_widget_field_size() {
636 523 $widgets = get_option( 'widget_frm_show_form' );
637 -
638 - if ( ! $widgets ) {
524 + if ( empty( $widgets ) ) {
639 525 return;
640 526 }
641 527
642 528 FrmAppHelper::unserialize_or_decode( $widgets );
643 -
644 529 foreach ( $widgets as $k => $widget ) {
645 530 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
646 531 continue;
647 532 }
@@ -647,9 +532,8 @@
647 532 }
648 533
649 534 $this->maybe_convert_migrated_size( $widgets[ $k ]['size'] );
650 535 }
651 -
652 536 update_option( 'widget_frm_show_form', $widgets );
653 537 }
654 538
655 539 /**
@@ -655,28 +539,23 @@
655 539 /**
656 540 * Divide by 9 to reverse the multiplication
657 541 *
658 542 * @since 3.0.05
659 - *
660 - * @param string $size Size string to maybe convert, passed by reference.
661 - *
662 - * @return void
663 543 */
664 544 private function maybe_convert_migrated_size( &$size ) {
665 - $has_px_size = ! empty( $size ) && str_contains( $size, 'px' );
666 -
545 + $has_px_size = ! empty( $size ) && strpos( $size, 'px' );
667 546 if ( ! $has_px_size ) {
668 547 return;
669 548 }
670 549
671 550 $int_size = str_replace( 'px', '', $size );
672 -
673 551 if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) {
674 552 return;
675 553 }
676 554
677 555 $pixel_conversion = 9;
678 - $size = round( (int) $int_size / $pixel_conversion );
556 +
557 + $size = round( (int) $int_size / $pixel_conversion );
679 558 }
680 559
681 560 /**
682 561 * Migrate old styling settings. If sites are using the old
@@ -682,17 +561,14 @@
682 561 * Migrate old styling settings. If sites are using the old
683 562 * default 400px field width, switch it to 100%
684 563 *
685 564 * @since 2.0.4
686 - *
687 - * @return void
688 565 */
689 566 private function migrate_to_25() {
690 567 // get the style that was created with the style migration
691 568 $frm_style = new FrmStyle();
692 569 $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
693 -
694 - if ( ! $styles ) {
570 + if ( empty( $styles ) ) {
695 571 return;
696 572 }
697 573
698 574 foreach ( $styles as $style ) {
@@ -709,16 +585,13 @@
709 585 * Check if the parent_form_id columns exists.
710 586 * If not, try and add it again
711 587 *
712 588 * @since 2.0.2
713 - *
714 - * @return void
715 589 */
716 590 private function migrate_to_23() {
717 591 global $wpdb;
718 592 $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
719 -
720 - if ( ! $exists ) {
593 + if ( empty( $exists ) ) {
721 594 $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
722 595 }
723 596 }
724 597
@@ -723,10 +596,8 @@
723 596 }
724 597
725 598 /**
726 599 * Change field size from character to pixel -- Multiply by 9
727 - *
728 - * @return void
729 600 */
730 601 private function migrate_to_17() {
731 602 $fields = $this->get_fields_with_size();
732 603
@@ -731,9 +602,8 @@
731 602 $fields = $this->get_fields_with_size();
732 603
733 604 foreach ( $fields as $f ) {
734 605 FrmAppHelper::unserialize_or_decode( $f->field_options );
735 -
736 606 if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
737 607 continue;
738 608 }
739 609
@@ -747,20 +617,16 @@
747 617 }
748 618
749 619 /**
750 620 * Change the characters in widgets to pixels
751 - *
752 - * @return void
753 621 */
754 622 private function adjust_widget_size() {
755 623 $widgets = get_option( 'widget_frm_show_form' );
756 -
757 - if ( ! $widgets ) {
624 + if ( empty( $widgets ) ) {
758 625 return;
759 626 }
760 627
761 628 FrmAppHelper::unserialize_or_decode( $widgets );
762 -
763 629 foreach ( $widgets as $k => $widget ) {
764 630 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
765 631 continue;
766 632 }
@@ -765,17 +631,11 @@
765 631 continue;
766 632 }
767 633 $this->convert_character_to_px( $widgets[ $k ]['size'] );
768 634 }
769 -
770 635 update_option( 'widget_frm_show_form', $widgets );
771 636 }
772 637
773 - /**
774 - * @param string $size
775 - *
776 - * @return void
777 - */
778 638 private function convert_character_to_px( &$size ) {
779 639 $pixel_conversion = 9;
780 640
781 641 $size = round( $pixel_conversion * (int) $size );
@@ -834,9 +694,10 @@
834 694
835 695 private function migrate_to_11() {
836 696 global $wpdb;
837 697
838 - $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
698 + $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
699 +
839 700 $sending = __( 'Sending', 'formidable' );
840 701 $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
841 702 $old_default_html = <<<DEFAULT_HTML
842 703 <div class="frm_submit">
@@ -848,21 +709,18 @@
848 709 unset( $sending, $img );
849 710
850 711 $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
851 712 $draft_link = FrmFormsHelper::get_draft_link();
852 -
853 713 foreach ( $forms as $form ) {
854 714 FrmAppHelper::unserialize_or_decode( $form->options );
855 -
856 715 if ( empty( $form->options['submit_html'] ) ) {
857 716 continue;
858 717 }
859 718
860 - // phpcs:ignore Universal.Operators.StrictComparisons
861 719 if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
862 720 $form->options['submit_html'] = $new_default_html;
863 721 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
864 - } elseif ( ! str_contains( $form->options['submit_html'], 'save_draft' ) ) {
722 + } elseif ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
865 723 $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
866 724 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
867 725 }
868 726 unset( $form );