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/FrmMigrate.php +111 -47 6.26 → trunk View file →
@@ -24,14 +24,20 @@
24 24 * @var string
25 25 */
26 26 public $entry_metas;
27 27
28 + /**
29 + * @var string
30 + */
31 + public $gated_tokens;
32 +
28 33 public function __construct() {
29 34 global $wpdb;
30 - $this->fields = $wpdb->prefix . 'frm_fields';
31 - $this->forms = $wpdb->prefix . 'frm_forms';
32 - $this->entries = $wpdb->prefix . 'frm_items';
33 - $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
35 + $this->fields = $wpdb->prefix . 'frm_fields';
36 + $this->forms = $wpdb->prefix . 'frm_forms';
37 + $this->entries = $wpdb->prefix . 'frm_items';
38 + $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
39 + $this->gated_tokens = $wpdb->prefix . 'frm_gated_tokens';
34 40 }
35 41
36 42 /**
37 43 * @return void
@@ -51,9 +57,11 @@
51 57 )
52 58 );
53 59
54 60 if ( $needs_upgrade ) {
55 - // update rewrite rules for views and other custom post types
61 + $this->maybe_delete_htaccess_file();
62 +
63 + // Update rewrite rules for views and other custom post types
56 64 flush_rewrite_rules();
57 65
58 66 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
59 67
@@ -82,16 +90,41 @@
82 90 $frm_vars['doing_upgrade'] = false;
83 91
84 92 FrmAppHelper::save_combined_js();
85 93
86 - // update the styling settings
87 - if ( function_exists( 'get_filesystem_method' ) ) {
88 - $frm_style = new FrmStyle();
89 - $frm_style->update( 'default' );
94 + // Update the styling settings
95 + if ( ! function_exists( 'get_filesystem_method' ) ) {
96 + return;
90 97 }
98 +
99 + $frm_style = new FrmStyle();
100 + $frm_style->update( 'default' );
91 101 }
92 102
93 103 /**
104 + * Check if the .htaccess file should be deleted based on server response.
105 + * If a server has AllowOverride FileInfo but not AllowOverride AuthConfig, JS and CSS files
106 + * will result in a 500 error.
107 + *
108 + * @since 6.27
109 + *
110 + * @return void
111 + */
112 + private function maybe_delete_htaccess_file() {
113 + $css_file_request = wp_remote_get( FrmAppHelper::plugin_url() . '/css/frm_fonts.css' );
114 +
115 + if ( 200 === wp_remote_retrieve_response_code( $css_file_request ) ) {
116 + return;
117 + }
118 +
119 + $htaccess_path = FrmAppHelper::plugin_path() . '/.htaccess';
120 +
121 + if ( file_exists( $htaccess_path ) ) {
122 + wp_delete_file( $htaccess_path );
123 + }
124 + }
125 +
126 + /**
94 127 * Updates some settings for new installs.
95 128 *
96 129 * @since 6.23
97 130 *
@@ -126,10 +159,10 @@
126 159
127 160 $message = array(
128 161 'key' => 'failed-to-create-tables',
129 162 'subject' => 'Something went wrong setting up the database',
130 - '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.',
131 - 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>',
163 + 'message' => 'For steps to continue, see our <a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables" target="_blank" rel="noopener">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
164 + 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables" target="_blank" rel="noopener">Learn More</a>', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
132 165 'type' => 'error',
133 166 );
134 167
135 168 $inbox = new FrmInbox();
@@ -140,14 +173,9 @@
140 173 * @return string
141 174 */
142 175 public function collation() {
143 176 global $wpdb;
144 -
145 - if ( ! $wpdb->has_cap( 'collation' ) ) {
146 - return '';
147 - }
148 -
149 - return $wpdb->get_charset_collate();
177 + return $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : '';
150 178 }
151 179
152 180 /**
153 181 * @return void
@@ -227,8 +255,25 @@
227 255 KEY field_id (field_id),
228 256 KEY item_id (item_id)
229 257 )';
230 258
259 + /* Create/Upgrade Gated Tokens Table */
260 + $sql[] = 'CREATE TABLE ' . $this->gated_tokens . ' (
261 + id BIGINT UNSIGNED NOT NULL auto_increment,
262 + token_hash varchar(64) NOT NULL,
263 + action_id BIGINT UNSIGNED NOT NULL,
264 + entry_id BIGINT UNSIGNED NOT NULL,
265 + user_id BIGINT UNSIGNED default NULL,
266 + ip_address varchar(255) default NULL,
267 + created_at int UNSIGNED NOT NULL,
268 + expired_at int UNSIGNED default NULL,
269 + PRIMARY KEY (id),
270 + UNIQUE KEY token_hash (token_hash),
271 + KEY action_id (action_id),
272 + KEY user_id (user_id),
273 + KEY expired_at (expired_at)
274 + )';
275 +
231 276 foreach ( $sql as $q ) {
232 277 if ( function_exists( 'dbDelta' ) ) {
233 278 dbDelta( $q . $charset_collate . ';' );
234 279 } else {
@@ -332,10 +377,9 @@
332 377 }
333 378
334 379 $set_err = libxml_use_internal_errors( true );
335 380 $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
336 -
337 - $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml';
381 + $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml';
338 382 FrmXMLHelper::import_xml( $file );
339 383
340 384 libxml_use_internal_errors( $set_err );
341 385 FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
@@ -350,28 +394,33 @@
350 394 if ( ! $old_db_version ) {
351 395 $old_db_version = get_option( 'frm_db_version' );
352 396 }
353 397
354 - if ( strpos( $old_db_version, '-' ) ) {
398 + if ( str_contains( $old_db_version, '-' ) ) {
355 399 $last_upgrade = explode( '-', $old_db_version );
356 - $old_db_version = (int) $last_upgrade[1];
400 + $old_db_version = intval( end( $last_upgrade ) );
357 401 }
358 402
359 403 if ( ! is_numeric( $old_db_version ) ) {
360 - // bail if we don't know the previous version
404 + // Bail if we don't know the previous version
361 405 return;
362 406 }
363 407
364 - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 );
408 + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104, 105 );
365 409
366 410 foreach ( $migrations as $migration ) {
367 - if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
368 - $function_name = 'migrate_to_' . $migration;
369 - $this->$function_name();
411 + if ( FrmAppHelper::$db_version < $migration || $old_db_version >= $migration ) {
412 + continue;
370 413 }
414 +
415 + $function_name = 'migrate_to_' . $migration;
416 + $this->$function_name();
371 417 }
372 418 }
373 419
420 + /**
421 + * @return bool
422 + */
374 423 public function uninstall() {
375 424 if ( ! current_user_can( 'administrator' ) ) {
376 425 $frm_settings = FrmAppHelper::get_settings();
377 426 wp_die( esc_html( $frm_settings->admin_permission ) );
@@ -382,8 +431,9 @@
382 431 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
383 432 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
384 433 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
385 434 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
435 + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->gated_tokens ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
386 436
387 437 delete_option( 'frm_options' );
388 438 delete_option( 'frm_db_version' );
389 439 delete_option( 'frm_install_running' );
@@ -406,15 +456,15 @@
406 456 unset( $frm_role, $frm_role_description );
407 457 }
408 458 unset( $roles, $frm_roles );
409 459
410 - // delete actions, views, and styles
460 + // Delete actions, views, and styles
411 461
412 - // prevent the post deletion from triggering entries to be deleted
462 + // Prevent the post deletion from triggering entries to be deleted
413 463 remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
414 464 remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
415 465
416 - $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' ) );
466 + $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
417 467
418 468 foreach ( $post_ids as $post_id ) {
419 469 // Delete's each post.
420 470 wp_delete_post( $post_id, true );
@@ -420,15 +470,15 @@
420 470 wp_delete_post( $post_id, true );
421 471 }
422 472 unset( $post_ids );
423 473
424 - // delete transients
474 + // Delete transients
425 475 delete_transient( 'frmpro_css' );
426 476 delete_transient( 'frm_options' );
427 477 delete_transient( 'frmpro_options' );
428 478 delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME );
429 479
430 - $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_%' ) );
480 + $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
431 481
432 482 do_action( 'frm_after_uninstall' );
433 483
434 484 return true;
@@ -452,8 +502,21 @@
452 502 }
453 503 }
454 504
455 505 /**
506 + * Add new wp_options row for custom setting.
507 + *
508 + * @since 6.26
509 + *
510 + * @return void
511 + */
512 + private function migrate_to_105() {
513 + if ( ! FrmAppHelper::pro_is_installed() ) {
514 + update_option( 'frm_show_pricing_fields_modal', 1, false );
515 + }
516 + }
517 +
518 + /**
456 519 * Disables summary email for multisite (not the main site) if recipient setting isn't changed.
457 520 *
458 521 * @since 6.8
459 522 *
@@ -518,9 +581,9 @@
518 581 FrmAppHelper::unserialize_or_decode( $field->field_options );
519 582 FrmAppHelper::unserialize_or_decode( $field->options );
520 583 $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type );
521 584
522 - if ( empty( $update_values ) ) {
585 + if ( ! $update_values ) {
523 586 continue;
524 587 }
525 588
526 589 FrmField::update( $field->id, $update_values );
@@ -537,8 +600,9 @@
537 600 */
538 601 private function migrate_to_90() {
539 602 $form = FrmForm::getOne( 'contact' );
540 603
604 + // phpcs:ignore Universal.Operators.StrictComparisons
541 605 if ( $form && $form->default_template == 1 ) {
542 606 FrmForm::destroy( 'contact' );
543 607 }
544 608 }
@@ -550,9 +614,8 @@
550 614 *
551 615 * @return void
552 616 */
553 617 private function migrate_to_86() {
554 -
555 618 $fields = $this->get_fields_with_size();
556 619
557 620 foreach ( $fields as $f ) {
558 621 FrmAppHelper::unserialize_or_decode( $f->field_options );
@@ -567,12 +630,12 @@
567 630 FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
568 631 unset( $f );
569 632 }
570 633
571 - // reverse the extra size changes in widgets
634 + // Reverse the extra size changes in widgets
572 635 $widgets = get_option( 'widget_frm_show_form' );
573 636
574 - if ( empty( $widgets ) ) {
637 + if ( ! $widgets ) {
575 638 return;
576 639 }
577 640
578 641 $this->revert_widget_field_size();
@@ -615,9 +678,9 @@
615 678 */
616 679 private function revert_widget_field_size() {
617 680 $widgets = get_option( 'widget_frm_show_form' );
618 681
619 - if ( empty( $widgets ) ) {
682 + if ( ! $widgets ) {
620 683 return;
621 684 }
622 685
623 686 FrmAppHelper::unserialize_or_decode( $widgets );
@@ -628,8 +691,9 @@
628 691 }
629 692
630 693 $this->maybe_convert_migrated_size( $widgets[ $k ]['size'] );
631 694 }
695 +
632 696 update_option( 'widget_frm_show_form', $widgets );
633 697 }
634 698
635 699 /**
@@ -641,9 +705,9 @@
641 705 *
642 706 * @return void
643 707 */
644 708 private function maybe_convert_migrated_size( &$size ) {
645 - $has_px_size = ! empty( $size ) && strpos( $size, 'px' );
709 + $has_px_size = $size && str_contains( $size, 'px' );
646 710
647 711 if ( ! $has_px_size ) {
648 712 return;
649 713 }
@@ -654,10 +718,9 @@
654 718 return;
655 719 }
656 720
657 721 $pixel_conversion = 9;
658 -
659 - $size = round( (int) $int_size / $pixel_conversion );
722 + $size = round( (int) $int_size / $pixel_conversion );
660 723 }
661 724
662 725 /**
663 726 * Migrate old styling settings. If sites are using the old
@@ -667,13 +730,13 @@
667 730 *
668 731 * @return void
669 732 */
670 733 private function migrate_to_25() {
671 - // get the style that was created with the style migration
734 + // Get the style that was created with the style migration
672 735 $frm_style = new FrmStyle();
673 736 $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
674 737
675 - if ( empty( $styles ) ) {
738 + if ( ! $styles ) {
676 739 return;
677 740 }
678 741
679 742 foreach ( $styles as $style ) {
@@ -697,9 +760,9 @@
697 760 private function migrate_to_23() {
698 761 global $wpdb;
699 762 $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
700 763
701 - if ( empty( $exists ) ) {
764 + if ( ! $exists ) {
702 765 $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
703 766 }
704 767 }
705 768
@@ -734,9 +797,9 @@
734 797 */
735 798 private function adjust_widget_size() {
736 799 $widgets = get_option( 'widget_frm_show_form' );
737 800
738 - if ( empty( $widgets ) ) {
801 + if ( ! $widgets ) {
739 802 return;
740 803 }
741 804
742 805 FrmAppHelper::unserialize_or_decode( $widgets );
@@ -746,8 +809,9 @@
746 809 continue;
747 810 }
748 811 $this->convert_character_to_px( $widgets[ $k ]['size'] );
749 812 }
813 +
750 814 update_option( 'widget_frm_show_form', $widgets );
751 815 }
752 816
753 817 /**
@@ -798,9 +862,9 @@
798 862 * post_excerpt: message
799 863 */
800 864 foreach ( $forms as $form ) {
801 865 if ( $form->is_template && $form->default_template ) {
802 - // don't migrate the default templates since the email will be added anyway
866 + // Don't migrate the default templates since the email will be added anyway
803 867 continue;
804 868 }
805 869
806 870 // Format form options
@@ -814,10 +878,9 @@
814 878
815 879 private function migrate_to_11() {
816 880 global $wpdb;
817 881
818 - $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
819 -
882 + $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
820 883 $sending = __( 'Sending', 'formidable' );
821 884 $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
822 885 $old_default_html = <<<DEFAULT_HTML
823 886 <div class="frm_submit">
@@ -837,12 +900,13 @@
837 900 if ( empty( $form->options['submit_html'] ) ) {
838 901 continue;
839 902 }
840 903
904 + // phpcs:ignore Universal.Operators.StrictComparisons
841 905 if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
842 906 $form->options['submit_html'] = $new_default_html;
843 907 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
844 - } elseif ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
908 + } elseif ( ! str_contains( $form->options['submit_html'], 'save_draft' ) ) {
845 909 $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
846 910 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
847 911 }
848 912 unset( $form );