| @@ -35,29 +35,22 @@ | ||
| 35 | 35 | if ( $needs_upgrade ) { |
| 36 | 36 | // update rewrite rules for views and other custom post types |
| 37 | 37 | flush_rewrite_rules(); |
| 38 | 38 | |
| 39 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | |
| 39 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); | |
| 40 | 40 | |
| 41 | 41 | $old_db_version = get_option( 'frm_db_version' ); |
| 42 | 42 | |
| 43 | 43 | $this->create_tables(); |
| 44 | 44 | $this->migrate_data( $old_db_version ); |
| 45 | - $this->check_that_tables_exist(); | |
| 46 | 45 | |
| 47 | - // SAVE DB VERSION. | |
| 46 | + /***** SAVE DB VERSION *****/ | |
| 48 | 47 | update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version ); |
| 49 | 48 | |
| 50 | 49 | if ( ! $old_db_version ) { |
| 51 | 50 | $this->maybe_create_contact_form(); |
| 52 | - | |
| 53 | - if ( false === get_option( 'frm_first_activation' ) ) { | |
| 54 | - update_option( 'frm_first_activation', time(), false ); | |
| 55 | - } | |
| 56 | - | |
| 57 | - $this->update_settings_for_new_install(); | |
| 58 | 51 | } |
| 59 | - }//end if | |
| 52 | + } | |
| 60 | 53 | |
| 61 | 54 | do_action( 'frm_after_install' ); |
| 62 | 55 | |
| 63 | 56 | $frm_vars['doing_upgrade'] = false; |
| @@ -70,54 +63,8 @@ | ||
| 70 | 63 | $frm_style->update( 'default' ); |
| 71 | 64 | } |
| 72 | 65 | } |
| 73 | 66 | |
| 74 | - /** | |
| 75 | - * Updates some settings for new installs. | |
| 76 | - * | |
| 77 | - * @since 6.23 | |
| 78 | - */ | |
| 79 | - private function update_settings_for_new_install() { | |
| 80 | - $settings = FrmAppHelper::get_settings(); | |
| 81 | - | |
| 82 | - $settings->denylist_check = 1; | |
| 83 | - $settings->store(); | |
| 84 | - } | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * If we fail to create the database tables, add an inbox notice. | |
| 88 | - * This informs the user that they need to correct the issue and try again. | |
| 89 | - * | |
| 90 | - * @since 6.19 | |
| 91 | - * | |
| 92 | - * @return void | |
| 93 | - */ | |
| 94 | - private function check_that_tables_exist() { | |
| 95 | - // Check the DB that the table $this->forms exists. | |
| 96 | - global $wpdb; | |
| 97 | - $exists = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $this->forms ) ); | |
| 98 | - | |
| 99 | - if ( $exists ) { | |
| 100 | - $inbox = new FrmInbox(); | |
| 101 | - $inbox->dismiss( 'failed-to-create-tables' ); | |
| 102 | - return; | |
| 103 | - } | |
| 104 | - | |
| 105 | - $message = array( | |
| 106 | - 'key' => 'failed-to-create-tables', | |
| 107 | - 'subject' => 'Something went wrong setting up the database', | |
| 108 | - '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.', | |
| 109 | - 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>', | |
| 110 | - 'type' => 'error', | |
| 111 | - ); | |
| 112 | - | |
| 113 | - $inbox = new FrmInbox(); | |
| 114 | - $inbox->add_message( $message ); | |
| 115 | - } | |
| 116 | - | |
| 117 | - /** | |
| 118 | - * @return string | |
| 119 | - */ | |
| 120 | 67 | public function collation() { |
| 121 | 68 | global $wpdb; |
| 122 | 69 | if ( ! $wpdb->has_cap( 'collation' ) ) { |
| 123 | 70 | return ''; |
| @@ -210,77 +157,10 @@ | ||
| 210 | 157 | $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 211 | 158 | } |
| 212 | 159 | unset( $q ); |
| 213 | 160 | } |
| 214 | - | |
| 215 | - $this->add_composite_indexes_for_entries(); | |
| 216 | 161 | } |
| 217 | 162 | |
| 218 | - /** | |
| 219 | - * These indexes help optimize database queries for entries. | |
| 220 | - * | |
| 221 | - * @since 6.6 | |
| 222 | - * @since 6.16.3 idx_form_id_is_draft was also added to frm_items. | |
| 223 | - * @since 6.17 idx_form_id_type was also added to frm_fields. | |
| 224 | - * | |
| 225 | - * @return void | |
| 226 | - */ | |
| 227 | - private function add_composite_indexes_for_entries() { | |
| 228 | - global $wpdb; | |
| 229 | - | |
| 230 | - $table_name = "{$wpdb->prefix}frm_items"; | |
| 231 | - $index_name = 'idx_is_draft_created_at'; | |
| 232 | - | |
| 233 | - if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 234 | - $wpdb->query( "CREATE INDEX idx_is_draft_created_at ON `{$wpdb->prefix}frm_items` (is_draft, created_at)" ); | |
| 235 | - } | |
| 236 | - | |
| 237 | - $table_name = "{$wpdb->prefix}frm_item_metas"; | |
| 238 | - $index_name = 'idx_field_id_item_id'; | |
| 239 | - | |
| 240 | - if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 241 | - $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" ); | |
| 242 | - } | |
| 243 | - | |
| 244 | - $table_name = "{$wpdb->prefix}frm_items"; | |
| 245 | - $index_name = 'idx_form_id_is_draft'; | |
| 246 | - | |
| 247 | - if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 248 | - $wpdb->query( "CREATE INDEX idx_form_id_is_draft ON `{$wpdb->prefix}frm_items` (form_id, is_draft)" ); | |
| 249 | - } | |
| 250 | - | |
| 251 | - $table_name = "{$wpdb->prefix}frm_fields"; | |
| 252 | - $index_name = 'idx_form_id_type'; | |
| 253 | - | |
| 254 | - if ( ! self::index_exists( $table_name, $index_name ) ) { | |
| 255 | - $wpdb->query( "CREATE INDEX idx_form_id_type ON `{$wpdb->prefix}frm_fields` (form_id, type(30))" ); | |
| 256 | - } | |
| 257 | - } | |
| 258 | - | |
| 259 | - /** | |
| 260 | - * Check that an index exists in a database table before trying to add it (which results in an error). | |
| 261 | - * | |
| 262 | - * @since 6.6 | |
| 263 | - * | |
| 264 | - * @param string $table_name | |
| 265 | - * @param string $index_name | |
| 266 | - * @return bool | |
| 267 | - */ | |
| 268 | - private static function index_exists( $table_name, $index_name ) { | |
| 269 | - global $wpdb; | |
| 270 | - $row = $wpdb->get_row( | |
| 271 | - $wpdb->prepare( | |
| 272 | - 'SELECT 1 FROM information_schema.statistics | |
| 273 | - WHERE table_schema = database() | |
| 274 | - AND table_name = %s | |
| 275 | - AND index_name = %s | |
| 276 | - LIMIT 1', | |
| 277 | - array( $table_name, $index_name ) | |
| 278 | - ) | |
| 279 | - ); | |
| 280 | - return (bool) $row; | |
| 281 | - } | |
| 282 | - | |
| 283 | 163 | private function maybe_create_contact_form() { |
| 284 | 164 | $form_exists = FrmForm::get_id_by_key( 'contact-form' ); |
| 285 | 165 | if ( ! $form_exists ) { |
| 286 | 166 | $this->add_default_template(); |
| @@ -324,9 +204,9 @@ | ||
| 324 | 204 | // bail if we don't know the previous version |
| 325 | 205 | return; |
| 326 | 206 | } |
| 327 | 207 | |
| 328 | - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 ); | |
| 208 | + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98 ); | |
| 329 | 209 | foreach ( $migrations as $migration ) { |
| 330 | 210 | if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) { |
| 331 | 211 | $function_name = 'migrate_to_' . $migration; |
| 332 | 212 | $this->$function_name(); |
| @@ -353,10 +233,9 @@ | ||
| 353 | 233 | delete_option( 'frm_lite_settings_upgrade' ); |
| 354 | 234 | delete_option( 'frm-usage-uuid' ); |
| 355 | 235 | delete_option( 'frm_inbox' ); |
| 356 | 236 | delete_option( 'frmpro_css' ); |
| 357 | - delete_option( FrmOnboardingWizardController::REDIRECT_STATUS_OPTION ); | |
| 358 | - delete_option( FrmEmailSummaryHelper::$option_name ); | |
| 237 | + delete_option( 'frm_welcome_redirect' ); | |
| 359 | 238 | |
| 360 | 239 | // Delete roles. |
| 361 | 240 | $frm_roles = FrmAppHelper::frm_capabilities(); |
| 362 | 241 | $roles = get_editable_roles(); |
| @@ -385,9 +264,9 @@ | ||
| 385 | 264 | // delete transients |
| 386 | 265 | delete_transient( 'frmpro_css' ); |
| 387 | 266 | delete_transient( 'frm_options' ); |
| 388 | 267 | delete_transient( 'frmpro_options' ); |
| 389 | - delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME ); | |
| 268 | + delete_transient( 'frm_activation_redirect' ); | |
| 390 | 269 | |
| 391 | 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_%' ) ); |
| 392 | 271 | |
| 393 | 272 | do_action( 'frm_after_uninstall' ); |
| @@ -395,46 +274,8 @@ | ||
| 395 | 274 | return true; |
| 396 | 275 | } |
| 397 | 276 | |
| 398 | 277 | /** |
| 399 | - * In older versions of Lite, it's possible we've saved the wrong location ID. | |
| 400 | - * So force it to get valid values again. | |
| 401 | - * | |
| 402 | - * @since 6.25 | |
| 403 | - * | |
| 404 | - * @return void | |
| 405 | - */ | |
| 406 | - private function migrate_to_104() { | |
| 407 | - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'test' ) ) { | |
| 408 | - FrmSquareLiteConnectHelper::get_location_id( true, 'test' ); | |
| 409 | - } | |
| 410 | - | |
| 411 | - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'live' ) ) { | |
| 412 | - FrmSquareLiteConnectHelper::get_location_id( true, 'live' ); | |
| 413 | - } | |
| 414 | - } | |
| 415 | - | |
| 416 | - /** | |
| 417 | - * Disables summary email for multisite (not the main site) if recipient setting isn't changed. | |
| 418 | - * | |
| 419 | - * @since 6.8 | |
| 420 | - */ | |
| 421 | - private function migrate_to_101() { | |
| 422 | - if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) { | |
| 423 | - return; | |
| 424 | - } | |
| 425 | - | |
| 426 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 427 | - if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) { | |
| 428 | - // User changed it. | |
| 429 | - return; | |
| 430 | - } | |
| 431 | - | |
| 432 | - $frm_settings->summary_emails = 0; | |
| 433 | - $frm_settings->store(); | |
| 434 | - } | |
| 435 | - | |
| 436 | - /** | |
| 437 | 278 | * Clear frmpro_css transient. |
| 438 | 279 | * |
| 439 | 280 | * @since 4.10.02 |
| 440 | 281 | */ |
| @@ -477,9 +318,9 @@ | ||
| 477 | 318 | } |
| 478 | 319 | } |
| 479 | 320 | |
| 480 | 321 | /** |
| 481 | - * Delete unneeded default templates | |
| 322 | + * Delete uneeded default templates | |
| 482 | 323 | * |
| 483 | 324 | * @since 3.06 |
| 484 | 325 | */ |
| 485 | 326 | private function migrate_to_90() { |
| @@ -499,9 +340,9 @@ | ||
| 499 | 340 | $fields = $this->get_fields_with_size(); |
| 500 | 341 | |
| 501 | 342 | foreach ( (array) $fields as $f ) { |
| 502 | 343 | FrmAppHelper::unserialize_or_decode( $f->field_options ); |
| 503 | - $size = $f->field_options['size']; | |
| 344 | + $size = $f->field_options['size']; | |
| 504 | 345 | $this->maybe_convert_migrated_size( $size ); |
| 505 | 346 | |
| 506 | 347 | if ( $size === $f->field_options['size'] ) { |
| 507 | 348 | continue; |
| @@ -603,9 +444,9 @@ | ||
| 603 | 444 | return; |
| 604 | 445 | } |
| 605 | 446 | |
| 606 | 447 | foreach ( $styles as $style ) { |
| 607 | - if ( $style->post_content['field_width'] === '400px' ) { | |
| 448 | + if ( $style->post_content['field_width'] == '400px' ) { | |
| 608 | 449 | $style->post_content['field_width'] = '100%'; |
| 609 | 450 | $frm_style->save( (array) $style ); |
| 610 | 451 | |
| 611 | 452 | return; |
| @@ -669,9 +510,9 @@ | ||
| 669 | 510 | |
| 670 | 511 | private function convert_character_to_px( &$size ) { |
| 671 | 512 | $pixel_conversion = 9; |
| 672 | 513 | |
| 673 | - $size = round( $pixel_conversion * (int) $size ); | |
| 514 | + $size = round( $pixel_conversion * (int) $size ); | |
| 674 | 515 | $size .= 'px'; |
| 675 | 516 | } |
| 676 | 517 | |
| 677 | 518 | /** |
| @@ -743,9 +584,9 @@ | ||
| 743 | 584 | $new_default_html = FrmFormsHelper::get_default_html( 'submit' ); |
| 744 | 585 | $draft_link = FrmFormsHelper::get_draft_link(); |
| 745 | 586 | foreach ( $forms as $form ) { |
| 746 | 587 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 747 | - if ( empty( $form->options['submit_html'] ) ) { | |
| 588 | + if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) { | |
| 748 | 589 | continue; |
| 749 | 590 | } |
| 750 | 591 | |
| 751 | 592 | if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |