PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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 +19 -268 6.265.0 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;
@@ -54,29 +35,22 @@
54 35 if ( $needs_upgrade ) {
55 36 // update rewrite rules for views and other custom post types
56 37 flush_rewrite_rules();
57 38
58 - require_once ABSPATH . 'wp-admin/includes/upgrade.php';
39 + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
59 40
60 41 $old_db_version = get_option( 'frm_db_version' );
61 42
62 43 $this->create_tables();
63 44 $this->migrate_data( $old_db_version );
64 - $this->check_that_tables_exist();
65 45
66 - // SAVE DB VERSION.
46 + /***** SAVE DB VERSION *****/
67 47 update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version );
68 48
69 49 if ( ! $old_db_version ) {
70 50 $this->maybe_create_contact_form();
71 -
72 - if ( false === get_option( 'frm_first_activation' ) ) {
73 - update_option( 'frm_first_activation', time(), false );
74 - }
75 -
76 - $this->update_settings_for_new_install();
77 51 }
78 - }//end if
52 + }
79 53
80 54 do_action( 'frm_after_install' );
81 55
82 56 $frm_vars['doing_upgrade'] = false;
@@ -89,60 +63,10 @@
89 63 $frm_style->update( 'default' );
90 64 }
91 65 }
92 66
93 - /**
94 - * Updates some settings for new installs.
95 - *
96 - * @since 6.23
97 - *
98 - * @return void
99 - */
100 - private function update_settings_for_new_install() {
101 - $settings = FrmAppHelper::get_settings();
102 -
103 - $settings->denylist_check = 1;
104 - $settings->installed_after_welcome_tour_update = 1;
105 - $settings->store();
106 - }
107 -
108 - /**
109 - * If we fail to create the database tables, add an inbox notice.
110 - * This informs the user that they need to correct the issue and try again.
111 - *
112 - * @since 6.19
113 - *
114 - * @return void
115 - */
116 - private function check_that_tables_exist() {
117 - // Check the DB that the table $this->forms exists.
118 - global $wpdb;
119 - $exists = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $this->forms ) );
120 -
121 - if ( $exists ) {
122 - $inbox = new FrmInbox();
123 - $inbox->dismiss( 'failed-to-create-tables' );
124 - return;
125 - }
126 -
127 - $message = array(
128 - 'key' => 'failed-to-create-tables',
129 - '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>',
132 - 'type' => 'error',
133 - );
134 -
135 - $inbox = new FrmInbox();
136 - $inbox->add_message( $message );
137 - }
138 -
139 - /**
140 - * @return string
141 - */
142 67 public function collation() {
143 68 global $wpdb;
144 -
145 69 if ( ! $wpdb->has_cap( 'collation' ) ) {
146 70 return '';
147 71 }
148 72
@@ -148,11 +72,8 @@
148 72
149 73 return $wpdb->get_charset_collate();
150 74 }
151 75
152 - /**
153 - * @return void
154 - */
155 76 private function create_tables() {
156 77 $charset_collate = $this->collation();
157 78 $sql = array();
158 79
@@ -232,88 +153,16 @@
232 153 if ( function_exists( 'dbDelta' ) ) {
233 154 dbDelta( $q . $charset_collate . ';' );
234 155 } else {
235 156 global $wpdb;
236 - $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
157 + $wpdb->query( $q . $charset_collate ); // WPCS: unprepared SQL ok.
237 158 }
238 159 unset( $q );
239 160 }
240 -
241 - $this->add_composite_indexes_for_entries();
242 161 }
243 162
244 - /**
245 - * These indexes help optimize database queries for entries.
246 - *
247 - * @since 6.6
248 - * @since 6.16.3 idx_form_id_is_draft was also added to frm_items.
249 - * @since 6.17 idx_form_id_type was also added to frm_fields.
250 - *
251 - * @return void
252 - */
253 - private function add_composite_indexes_for_entries() {
254 - global $wpdb;
255 -
256 - $table_name = "{$wpdb->prefix}frm_items";
257 - $index_name = 'idx_is_draft_created_at';
258 -
259 - if ( ! self::index_exists( $table_name, $index_name ) ) {
260 - $wpdb->query( "CREATE INDEX idx_is_draft_created_at ON `{$wpdb->prefix}frm_items` (is_draft, created_at)" );
261 - }
262 -
263 - $table_name = "{$wpdb->prefix}frm_item_metas";
264 - $index_name = 'idx_field_id_item_id';
265 -
266 - if ( ! self::index_exists( $table_name, $index_name ) ) {
267 - $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" );
268 - }
269 -
270 - $table_name = "{$wpdb->prefix}frm_items";
271 - $index_name = 'idx_form_id_is_draft';
272 -
273 - if ( ! self::index_exists( $table_name, $index_name ) ) {
274 - $wpdb->query( "CREATE INDEX idx_form_id_is_draft ON `{$wpdb->prefix}frm_items` (form_id, is_draft)" );
275 - }
276 -
277 - $table_name = "{$wpdb->prefix}frm_fields";
278 - $index_name = 'idx_form_id_type';
279 -
280 - if ( ! self::index_exists( $table_name, $index_name ) ) {
281 - $wpdb->query( "CREATE INDEX idx_form_id_type ON `{$wpdb->prefix}frm_fields` (form_id, type(30))" );
282 - }
283 - }
284 -
285 - /**
286 - * Check that an index exists in a database table before trying to add it (which results in an error).
287 - *
288 - * @since 6.6
289 - *
290 - * @param string $table_name
291 - * @param string $index_name
292 - *
293 - * @return bool
294 - */
295 - private static function index_exists( $table_name, $index_name ) {
296 - global $wpdb;
297 - $row = $wpdb->get_row(
298 - $wpdb->prepare(
299 - 'SELECT 1 FROM information_schema.statistics
300 - WHERE table_schema = database()
301 - AND table_name = %s
302 - AND index_name = %s
303 - LIMIT 1',
304 - array( $table_name, $index_name )
305 - )
306 - );
307 - return (bool) $row;
308 - }
309 -
310 - /**
311 - * @return void
312 - */
313 163 private function maybe_create_contact_form() {
314 164 $form_exists = FrmForm::get_id_by_key( 'contact-form' );
315 -
316 165 if ( ! $form_exists ) {
317 166 $this->add_default_template();
318 167 }
319 168 }
@@ -321,10 +170,8 @@
321 170 /**
322 171 * Create the default contact form
323 172 *
324 173 * @since 3.06
325 - *
326 - * @return void
327 174 */
328 175 private function add_default_template() {
329 176 if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
330 177 // XML import is not enabled on your server.
@@ -342,16 +189,13 @@
342 189 }
343 190
344 191 /**
345 192 * @param int|string $old_db_version
346 - *
347 - * @return void
348 193 */
349 194 private function migrate_data( $old_db_version ) {
350 195 if ( ! $old_db_version ) {
351 196 $old_db_version = get_option( 'frm_db_version' );
352 197 }
353 -
354 198 if ( strpos( $old_db_version, '-' ) ) {
355 199 $last_upgrade = explode( '-', $old_db_version );
356 200 $old_db_version = (int) $last_upgrade[1];
357 201 }
@@ -360,10 +204,9 @@
360 204 // bail if we don't know the previous version
361 205 return;
362 206 }
363 207
364 - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 );
365 -
208 + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98 );
366 209 foreach ( $migrations as $migration ) {
367 210 if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
368 211 $function_name = 'migrate_to_' . $migration;
369 212 $this->$function_name();
@@ -378,12 +221,12 @@
378 221 }
379 222
380 223 global $wpdb, $wp_roles;
381 224
382 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
383 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
384 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
385 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
225 + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // WPCS: unprepared SQL ok.
226 + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // WPCS: unprepared SQL ok.
227 + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // WPCS: unprepared SQL ok.
228 + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); // WPCS: unprepared SQL ok.
386 229
387 230 delete_option( 'frm_options' );
388 231 delete_option( 'frm_db_version' );
389 232 delete_option( 'frm_install_running' );
@@ -390,15 +233,13 @@
390 233 delete_option( 'frm_lite_settings_upgrade' );
391 234 delete_option( 'frm-usage-uuid' );
392 235 delete_option( 'frm_inbox' );
393 236 delete_option( 'frmpro_css' );
394 - delete_option( FrmOnboardingWizardController::REDIRECT_STATUS_OPTION );
395 - delete_option( FrmEmailSummaryHelper::$option_name );
237 + delete_option( 'frm_welcome_redirect' );
396 238
397 239 // Delete roles.
398 240 $frm_roles = FrmAppHelper::frm_capabilities();
399 241 $roles = get_editable_roles();
400 -
401 242 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
402 243 foreach ( $roles as $role => $details ) {
403 244 $wp_roles->remove_cap( $role, $frm_role );
404 245 unset( $role, $details );
@@ -413,9 +254,8 @@
413 254 remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
414 255 remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
415 256
416 257 $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' ) );
417 -
418 258 foreach ( $post_ids as $post_id ) {
419 259 // Delete's each post.
420 260 wp_delete_post( $post_id, true );
421 261 }
@@ -424,9 +264,9 @@
424 264 // delete transients
425 265 delete_transient( 'frmpro_css' );
426 266 delete_transient( 'frm_options' );
427 267 delete_transient( 'frmpro_options' );
428 - delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME );
268 + delete_transient( 'frm_activation_redirect' );
429 269
430 270 $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_%' ) );
431 271
432 272 do_action( 'frm_after_uninstall' );
@@ -434,54 +274,11 @@
434 274 return true;
435 275 }
436 276
437 277 /**
438 - * In older versions of Lite, it's possible we've saved the wrong location ID.
439 - * So force it to get valid values again.
440 - *
441 - * @since 6.25
442 - *
443 - * @return void
444 - */
445 - private function migrate_to_104() {
446 - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'test' ) ) {
447 - FrmSquareLiteConnectHelper::get_location_id( true, 'test' );
448 - }
449 -
450 - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'live' ) ) {
451 - FrmSquareLiteConnectHelper::get_location_id( true, 'live' );
452 - }
453 - }
454 -
455 - /**
456 - * Disables summary email for multisite (not the main site) if recipient setting isn't changed.
457 - *
458 - * @since 6.8
459 - *
460 - * @return void
461 - */
462 - private function migrate_to_101() {
463 - if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) {
464 - return;
465 - }
466 -
467 - $frm_settings = FrmAppHelper::get_settings();
468 -
469 - if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) {
470 - // User changed it.
471 - return;
472 - }
473 -
474 - $frm_settings->summary_emails = 0;
475 - $frm_settings->store();
476 - }
477 -
478 - /**
479 278 * Clear frmpro_css transient.
480 279 *
481 280 * @since 4.10.02
482 - *
483 - * @return void
484 281 */
485 282 private function migrate_to_98() {
486 283 delete_transient( 'frmpro_css' );
487 284 }
@@ -489,10 +286,8 @@
489 286 /**
490 287 * Move default_blank and clear_on_focus to placeholder.
491 288 *
492 289 * @since 4.0
493 - *
494 - * @return void
495 290 */
496 291 private function migrate_to_97() {
497 292 $this->migrate_to_placeholder( 'clear_on_focus' );
498 293 $this->migrate_to_placeholder( 'default_blank' );
@@ -501,12 +296,8 @@
501 296 /**
502 297 * Move clear_on_focus or default_blank to placeholder.
503 298 *
504 299 * @since 4.0
505 - *
506 - * @param string $type Field option key to migrate.
507 - *
508 - * @return void
509 300 */
510 301 private function migrate_to_placeholder( $type = 'clear_on_focus' ) {
511 302 $query = array(
512 303 'field_options like' => '"' . $type . '";s:1:"1";',
@@ -517,9 +308,8 @@
517 308 foreach ( $fields as $field ) {
518 309 FrmAppHelper::unserialize_or_decode( $field->field_options );
519 310 FrmAppHelper::unserialize_or_decode( $field->options );
520 311 $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type );
521 -
522 312 if ( empty( $update_values ) ) {
523 313 continue;
524 314 }
525 315
@@ -528,17 +318,14 @@
528 318 }
529 319 }
530 320
531 321 /**
532 - * Delete unneeded default templates
322 + * Delete uneeded default templates
533 323 *
534 324 * @since 3.06
535 - *
536 - * @return void
537 325 */
538 326 private function migrate_to_90() {
539 327 $form = FrmForm::getOne( 'contact' );
540 -
541 328 if ( $form && $form->default_template == 1 ) {
542 329 FrmForm::destroy( 'contact' );
543 330 }
544 331 }
@@ -546,18 +333,16 @@
546 333 /**
547 334 * Reverse migration 17 -- Divide by 9
548 335 *
549 336 * @since 3.0.05
550 - *
551 - * @return void
552 337 */
553 338 private function migrate_to_86() {
554 339
555 340 $fields = $this->get_fields_with_size();
556 341
557 - foreach ( $fields as $f ) {
342 + foreach ( (array) $fields as $f ) {
558 343 FrmAppHelper::unserialize_or_decode( $f->field_options );
559 - $size = $f->field_options['size'];
344 + $size = $f->field_options['size'];
560 345 $this->maybe_convert_migrated_size( $size );
561 346
562 347 if ( $size === $f->field_options['size'] ) {
563 348 continue;
@@ -569,9 +354,8 @@
569 354 }
570 355
571 356 // reverse the extra size changes in widgets
572 357 $widgets = get_option( 'widget_frm_show_form' );
573 -
574 358 if ( empty( $widgets ) ) {
575 359 return;
576 360 }
577 361
@@ -577,11 +361,8 @@
577 361
578 362 $this->revert_widget_field_size();
579 363 }
580 364
581 - /**
582 - * @return array
583 - */
584 365 private function get_fields_with_size() {
585 366 $field_types = array(
586 367 'textarea',
587 368 'text',
@@ -609,20 +390,16 @@
609 390 /**
610 391 * Reverse the extra size changes in widgets
611 392 *
612 393 * @since 3.0.05
613 - *
614 - * @return void
615 394 */
616 395 private function revert_widget_field_size() {
617 396 $widgets = get_option( 'widget_frm_show_form' );
618 -
619 397 if ( empty( $widgets ) ) {
620 398 return;
621 399 }
622 400
623 401 FrmAppHelper::unserialize_or_decode( $widgets );
624 -
625 402 foreach ( $widgets as $k => $widget ) {
626 403 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
627 404 continue;
628 405 }
@@ -635,22 +412,16 @@
635 412 /**
636 413 * Divide by 9 to reverse the multiplication
637 414 *
638 415 * @since 3.0.05
639 - *
640 - * @param string $size Size string to maybe convert, passed by reference.
641 - *
642 - * @return void
643 416 */
644 417 private function maybe_convert_migrated_size( &$size ) {
645 418 $has_px_size = ! empty( $size ) && strpos( $size, 'px' );
646 -
647 419 if ( ! $has_px_size ) {
648 420 return;
649 421 }
650 422
651 423 $int_size = str_replace( 'px', '', $size );
652 -
653 424 if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) {
654 425 return;
655 426 }
656 427
@@ -663,22 +434,19 @@
663 434 * Migrate old styling settings. If sites are using the old
664 435 * default 400px field width, switch it to 100%
665 436 *
666 437 * @since 2.0.4
667 - *
668 - * @return void
669 438 */
670 439 private function migrate_to_25() {
671 440 // get the style that was created with the style migration
672 441 $frm_style = new FrmStyle();
673 442 $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
674 -
675 443 if ( empty( $styles ) ) {
676 444 return;
677 445 }
678 446
679 447 foreach ( $styles as $style ) {
680 - if ( $style->post_content['field_width'] === '400px' ) {
448 + if ( $style->post_content['field_width'] == '400px' ) {
681 449 $style->post_content['field_width'] = '100%';
682 450 $frm_style->save( (array) $style );
683 451
684 452 return;
@@ -690,24 +458,19 @@
690 458 * Check if the parent_form_id columns exists.
691 459 * If not, try and add it again
692 460 *
693 461 * @since 2.0.2
694 - *
695 - * @return void
696 462 */
697 463 private function migrate_to_23() {
698 464 global $wpdb;
699 - $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
700 -
465 + $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // WPCS: unprepared SQL ok.
701 466 if ( empty( $exists ) ) {
702 - $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
467 + $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // WPCS: unprepared SQL ok.
703 468 }
704 469 }
705 470
706 471 /**
707 472 * Change field size from character to pixel -- Multiply by 9
708 - *
709 - * @return void
710 473 */
711 474 private function migrate_to_17() {
712 475 $fields = $this->get_fields_with_size();
713 476
@@ -712,9 +475,8 @@
712 475 $fields = $this->get_fields_with_size();
713 476
714 477 foreach ( $fields as $f ) {
715 478 FrmAppHelper::unserialize_or_decode( $f->field_options );
716 -
717 479 if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
718 480 continue;
719 481 }
720 482
@@ -728,20 +490,16 @@
728 490 }
729 491
730 492 /**
731 493 * Change the characters in widgets to pixels
732 - *
733 - * @return void
734 494 */
735 495 private function adjust_widget_size() {
736 496 $widgets = get_option( 'widget_frm_show_form' );
737 -
738 497 if ( empty( $widgets ) ) {
739 498 return;
740 499 }
741 500
742 501 FrmAppHelper::unserialize_or_decode( $widgets );
743 -
744 502 foreach ( $widgets as $k => $widget ) {
745 503 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
746 504 continue;
747 505 }
@@ -749,17 +507,12 @@
749 507 }
750 508 update_option( 'widget_frm_show_form', $widgets );
751 509 }
752 510
753 - /**
754 - * @param string $size
755 - *
756 - * @return void
757 - */
758 511 private function convert_character_to_px( &$size ) {
759 512 $pixel_conversion = 9;
760 513
761 - $size = round( $pixel_conversion * (int) $size );
514 + $size = round( $pixel_conversion * (int) $size );
762 515 $size .= 'px';
763 516 }
764 517
765 518 /**
@@ -829,13 +582,11 @@
829 582 unset( $sending, $img );
830 583
831 584 $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
832 585 $draft_link = FrmFormsHelper::get_draft_link();
833 -
834 586 foreach ( $forms as $form ) {
835 587 FrmAppHelper::unserialize_or_decode( $form->options );
836 -
837 - if ( empty( $form->options['submit_html'] ) ) {
588 + if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) {
838 589 continue;
839 590 }
840 591
841 592 if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {