| @@ -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 |
| @@ -53,9 +59,9 @@ | ||
| 53 | 59 | |
| 54 | 60 | if ( $needs_upgrade ) { |
| 55 | 61 | $this->maybe_delete_htaccess_file(); |
| 56 | 62 | |
| 57 | - // update rewrite rules for views and other custom post types | |
| 63 | + // Update rewrite rules for views and other custom post types | |
| 58 | 64 | flush_rewrite_rules(); |
| 59 | 65 | |
| 60 | 66 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 61 | 67 | |
| @@ -84,13 +90,15 @@ | ||
| 84 | 90 | $frm_vars['doing_upgrade'] = false; |
| 85 | 91 | |
| 86 | 92 | FrmAppHelper::save_combined_js(); |
| 87 | 93 | |
| 88 | - // update the styling settings | |
| 89 | - if ( function_exists( 'get_filesystem_method' ) ) { | |
| 90 | - $frm_style = new FrmStyle(); | |
| 91 | - $frm_style->update( 'default' ); | |
| 94 | + // Update the styling settings | |
| 95 | + if ( ! function_exists( 'get_filesystem_method' ) ) { | |
| 96 | + return; | |
| 92 | 97 | } |
| 98 | + | |
| 99 | + $frm_style = new FrmStyle(); | |
| 100 | + $frm_style->update( 'default' ); | |
| 93 | 101 | } |
| 94 | 102 | |
| 95 | 103 | /** |
| 96 | 104 | * Check if the .htaccess file should be deleted based on server response. |
| @@ -151,10 +159,10 @@ | ||
| 151 | 159 | |
| 152 | 160 | $message = array( |
| 153 | 161 | 'key' => 'failed-to-create-tables', |
| 154 | 162 | '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 | |
| 156 | - '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 | |
| 157 | 165 | 'type' => 'error', |
| 158 | 166 | ); |
| 159 | 167 | |
| 160 | 168 | $inbox = new FrmInbox(); |
| @@ -247,8 +255,25 @@ | ||
| 247 | 255 | KEY field_id (field_id), |
| 248 | 256 | KEY item_id (item_id) |
| 249 | 257 | )'; |
| 250 | 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 | + | |
| 251 | 276 | foreach ( $sql as $q ) { |
| 252 | 277 | if ( function_exists( 'dbDelta' ) ) { |
| 253 | 278 | dbDelta( $q . $charset_collate . ';' ); |
| 254 | 279 | } else { |
| @@ -371,26 +396,31 @@ | ||
| 371 | 396 | } |
| 372 | 397 | |
| 373 | 398 | if ( str_contains( $old_db_version, '-' ) ) { |
| 374 | 399 | $last_upgrade = explode( '-', $old_db_version ); |
| 375 | - $old_db_version = (int) $last_upgrade[1]; | |
| 400 | + $old_db_version = intval( end( $last_upgrade ) ); | |
| 376 | 401 | } |
| 377 | 402 | |
| 378 | 403 | if ( ! is_numeric( $old_db_version ) ) { |
| 379 | - // bail if we don't know the previous version | |
| 404 | + // Bail if we don't know the previous version | |
| 380 | 405 | return; |
| 381 | 406 | } |
| 382 | 407 | |
| 383 | - $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 ); | |
| 384 | 409 | |
| 385 | 410 | foreach ( $migrations as $migration ) { |
| 386 | - if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) { | |
| 387 | - $function_name = 'migrate_to_' . $migration; | |
| 388 | - $this->$function_name(); | |
| 411 | + if ( FrmAppHelper::$db_version < $migration || $old_db_version >= $migration ) { | |
| 412 | + continue; | |
| 389 | 413 | } |
| 414 | + | |
| 415 | + $function_name = 'migrate_to_' . $migration; | |
| 416 | + $this->$function_name(); | |
| 390 | 417 | } |
| 391 | 418 | } |
| 392 | 419 | |
| 420 | + /** | |
| 421 | + * @return bool | |
| 422 | + */ | |
| 393 | 423 | public function uninstall() { |
| 394 | 424 | if ( ! current_user_can( 'administrator' ) ) { |
| 395 | 425 | $frm_settings = FrmAppHelper::get_settings(); |
| 396 | 426 | wp_die( esc_html( $frm_settings->admin_permission ) ); |
| @@ -401,8 +431,9 @@ | ||
| 401 | 431 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 402 | 432 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 403 | 433 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 404 | 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 | |
| 405 | 436 | |
| 406 | 437 | delete_option( 'frm_options' ); |
| 407 | 438 | delete_option( 'frm_db_version' ); |
| 408 | 439 | delete_option( 'frm_install_running' ); |
| @@ -425,11 +456,11 @@ | ||
| 425 | 456 | unset( $frm_role, $frm_role_description ); |
| 426 | 457 | } |
| 427 | 458 | unset( $roles, $frm_roles ); |
| 428 | 459 | |
| 429 | - // delete actions, views, and styles | |
| 460 | + // Delete actions, views, and styles | |
| 430 | 461 | |
| 431 | - // prevent the post deletion from triggering entries to be deleted | |
| 462 | + // Prevent the post deletion from triggering entries to be deleted | |
| 432 | 463 | remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' ); |
| 433 | 464 | remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' ); |
| 434 | 465 | |
| 435 | 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 |
| @@ -439,9 +470,9 @@ | ||
| 439 | 470 | wp_delete_post( $post_id, true ); |
| 440 | 471 | } |
| 441 | 472 | unset( $post_ids ); |
| 442 | 473 | |
| 443 | - // delete transients | |
| 474 | + // Delete transients | |
| 444 | 475 | delete_transient( 'frmpro_css' ); |
| 445 | 476 | delete_transient( 'frm_options' ); |
| 446 | 477 | delete_transient( 'frmpro_options' ); |
| 447 | 478 | delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME ); |
| @@ -471,8 +502,21 @@ | ||
| 471 | 502 | } |
| 472 | 503 | } |
| 473 | 504 | |
| 474 | 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 | + /** | |
| 475 | 519 | * Disables summary email for multisite (not the main site) if recipient setting isn't changed. |
| 476 | 520 | * |
| 477 | 521 | * @since 6.8 |
| 478 | 522 | * |
| @@ -586,9 +630,9 @@ | ||
| 586 | 630 | FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
| 587 | 631 | unset( $f ); |
| 588 | 632 | } |
| 589 | 633 | |
| 590 | - // reverse the extra size changes in widgets | |
| 634 | + // Reverse the extra size changes in widgets | |
| 591 | 635 | $widgets = get_option( 'widget_frm_show_form' ); |
| 592 | 636 | |
| 593 | 637 | if ( ! $widgets ) { |
| 594 | 638 | return; |
| @@ -661,9 +705,9 @@ | ||
| 661 | 705 | * |
| 662 | 706 | * @return void |
| 663 | 707 | */ |
| 664 | 708 | private function maybe_convert_migrated_size( &$size ) { |
| 665 | - $has_px_size = ! empty( $size ) && str_contains( $size, 'px' ); | |
| 709 | + $has_px_size = $size && str_contains( $size, 'px' ); | |
| 666 | 710 | |
| 667 | 711 | if ( ! $has_px_size ) { |
| 668 | 712 | return; |
| 669 | 713 | } |
| @@ -686,9 +730,9 @@ | ||
| 686 | 730 | * |
| 687 | 731 | * @return void |
| 688 | 732 | */ |
| 689 | 733 | private function migrate_to_25() { |
| 690 | - // get the style that was created with the style migration | |
| 734 | + // Get the style that was created with the style migration | |
| 691 | 735 | $frm_style = new FrmStyle(); |
| 692 | 736 | $styles = $frm_style->get_all( 'post_date', 'ASC', 1 ); |
| 693 | 737 | |
| 694 | 738 | if ( ! $styles ) { |
| @@ -818,9 +862,9 @@ | ||
| 818 | 862 | * post_excerpt: message |
| 819 | 863 | */ |
| 820 | 864 | foreach ( $forms as $form ) { |
| 821 | 865 | if ( $form->is_template && $form->default_template ) { |
| 822 | - // 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 | |
| 823 | 867 | continue; |
| 824 | 868 | } |
| 825 | 869 | |
| 826 | 870 | // Format form options |