| @@ -3,46 +3,21 @@ | ||
| 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 | - /** | |
| 29 | - * @var string | |
| 30 | - */ | |
| 31 | - public $gated_tokens; | |
| 32 | - | |
| 33 | 12 | public function __construct() { |
| 34 | 13 | global $wpdb; |
| 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'; | |
| 14 | + $this->fields = $wpdb->prefix . 'frm_fields'; | |
| 15 | + $this->forms = $wpdb->prefix . 'frm_forms'; | |
| 16 | + $this->entries = $wpdb->prefix . 'frm_items'; | |
| 17 | + $this->entry_metas = $wpdb->prefix . 'frm_item_metas'; | |
| 40 | 18 | } |
| 41 | 19 | |
| 42 | - /** | |
| 43 | - * @return void | |
| 44 | - */ | |
| 45 | 20 | public function upgrade() { |
| 46 | 21 | do_action( 'frm_before_install' ); |
| 47 | 22 | |
| 48 | 23 | global $wpdb, $frm_vars; |
| @@ -57,11 +32,9 @@ | ||
| 57 | 32 | ) |
| 58 | 33 | ); |
| 59 | 34 | |
| 60 | 35 | if ( $needs_upgrade ) { |
| 61 | - $this->maybe_delete_htaccess_file(); | |
| 62 | - | |
| 63 | - // Update rewrite rules for views and other custom post types | |
| 36 | + // update rewrite rules for views and other custom post types | |
| 64 | 37 | flush_rewrite_rules(); |
| 65 | 38 | |
| 66 | 39 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 67 | 40 | |
| @@ -90,52 +63,24 @@ | ||
| 90 | 63 | $frm_vars['doing_upgrade'] = false; |
| 91 | 64 | |
| 92 | 65 | FrmAppHelper::save_combined_js(); |
| 93 | 66 | |
| 94 | - // Update the styling settings | |
| 95 | - if ( ! function_exists( 'get_filesystem_method' ) ) { | |
| 96 | - return; | |
| 67 | + // update the styling settings | |
| 68 | + if ( function_exists( 'get_filesystem_method' ) ) { | |
| 69 | + $frm_style = new FrmStyle(); | |
| 70 | + $frm_style->update( 'default' ); | |
| 97 | 71 | } |
| 98 | - | |
| 99 | - $frm_style = new FrmStyle(); | |
| 100 | - $frm_style->update( 'default' ); | |
| 101 | 72 | } |
| 102 | 73 | |
| 103 | 74 | /** |
| 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 | - /** | |
| 127 | 75 | * Updates some settings for new installs. |
| 128 | 76 | * |
| 129 | 77 | * @since 6.23 |
| 130 | - * | |
| 131 | - * @return void | |
| 132 | 78 | */ |
| 133 | 79 | private function update_settings_for_new_install() { |
| 134 | 80 | $settings = FrmAppHelper::get_settings(); |
| 135 | 81 | |
| 136 | - $settings->denylist_check = 1; | |
| 137 | - $settings->installed_after_welcome_tour_update = 1; | |
| 82 | + $settings->denylist_check = 1; | |
| 138 | 83 | $settings->store(); |
| 139 | 84 | } |
| 140 | 85 | |
| 141 | 86 | /** |
| @@ -159,9 +104,9 @@ | ||
| 159 | 104 | |
| 160 | 105 | $message = array( |
| 161 | 106 | 'key' => 'failed-to-create-tables', |
| 162 | 107 | 'subject' => 'Something went wrong setting up the database', |
| 163 | - '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 | |
| 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.', | |
| 164 | 109 | 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>', |
| 165 | 110 | 'type' => 'error', |
| 166 | 111 | ); |
| 167 | 112 | |
| @@ -173,14 +118,15 @@ | ||
| 173 | 118 | * @return string |
| 174 | 119 | */ |
| 175 | 120 | public function collation() { |
| 176 | 121 | global $wpdb; |
| 177 | - return $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : ''; | |
| 122 | + if ( ! $wpdb->has_cap( 'collation' ) ) { | |
| 123 | + return ''; | |
| 124 | + } | |
| 125 | + | |
| 126 | + return $wpdb->get_charset_collate(); | |
| 178 | 127 | } |
| 179 | 128 | |
| 180 | - /** | |
| 181 | - * @return void | |
| 182 | - */ | |
| 183 | 129 | private function create_tables() { |
| 184 | 130 | $charset_collate = $this->collation(); |
| 185 | 131 | $sql = array(); |
| 186 | 132 | |
| @@ -255,25 +201,8 @@ | ||
| 255 | 201 | KEY field_id (field_id), |
| 256 | 202 | KEY item_id (item_id) |
| 257 | 203 | )'; |
| 258 | 204 | |
| 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 | - | |
| 276 | 205 | foreach ( $sql as $q ) { |
| 277 | 206 | if ( function_exists( 'dbDelta' ) ) { |
| 278 | 207 | dbDelta( $q . $charset_collate . ';' ); |
| 279 | 208 | } else { |
| @@ -333,9 +262,8 @@ | ||
| 333 | 262 | * @since 6.6 |
| 334 | 263 | * |
| 335 | 264 | * @param string $table_name |
| 336 | 265 | * @param string $index_name |
| 337 | - * | |
| 338 | 266 | * @return bool |
| 339 | 267 | */ |
| 340 | 268 | private static function index_exists( $table_name, $index_name ) { |
| 341 | 269 | global $wpdb; |
| @@ -351,14 +279,10 @@ | ||
| 351 | 279 | ); |
| 352 | 280 | return (bool) $row; |
| 353 | 281 | } |
| 354 | 282 | |
| 355 | - /** | |
| 356 | - * @return void | |
| 357 | - */ | |
| 358 | 283 | private function maybe_create_contact_form() { |
| 359 | 284 | $form_exists = FrmForm::get_id_by_key( 'contact-form' ); |
| 360 | - | |
| 361 | 285 | if ( ! $form_exists ) { |
| 362 | 286 | $this->add_default_template(); |
| 363 | 287 | } |
| 364 | 288 | } |
| @@ -366,10 +290,8 @@ | ||
| 366 | 290 | /** |
| 367 | 291 | * Create the default contact form |
| 368 | 292 | * |
| 369 | 293 | * @since 3.06 |
| 370 | - * | |
| 371 | - * @return void | |
| 372 | 294 | */ |
| 373 | 295 | private function add_default_template() { |
| 374 | 296 | if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) { |
| 375 | 297 | // XML import is not enabled on your server. |
| @@ -377,9 +299,10 @@ | ||
| 377 | 299 | } |
| 378 | 300 | |
| 379 | 301 | $set_err = libxml_use_internal_errors( true ); |
| 380 | 302 | $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true ); |
| 381 | - $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml'; | |
| 303 | + | |
| 304 | + $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml'; | |
| 382 | 305 | FrmXMLHelper::import_xml( $file ); |
| 383 | 306 | |
| 384 | 307 | libxml_use_internal_errors( $set_err ); |
| 385 | 308 | FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader ); |
| @@ -386,41 +309,32 @@ | ||
| 386 | 309 | } |
| 387 | 310 | |
| 388 | 311 | /** |
| 389 | 312 | * @param int|string $old_db_version |
| 390 | - * | |
| 391 | - * @return void | |
| 392 | 313 | */ |
| 393 | 314 | private function migrate_data( $old_db_version ) { |
| 394 | 315 | if ( ! $old_db_version ) { |
| 395 | 316 | $old_db_version = get_option( 'frm_db_version' ); |
| 396 | 317 | } |
| 397 | - | |
| 398 | - if ( str_contains( $old_db_version, '-' ) ) { | |
| 318 | + if ( strpos( $old_db_version, '-' ) ) { | |
| 399 | 319 | $last_upgrade = explode( '-', $old_db_version ); |
| 400 | - $old_db_version = intval( end( $last_upgrade ) ); | |
| 320 | + $old_db_version = (int) $last_upgrade[1]; | |
| 401 | 321 | } |
| 402 | 322 | |
| 403 | 323 | if ( ! is_numeric( $old_db_version ) ) { |
| 404 | - // Bail if we don't know the previous version | |
| 324 | + // bail if we don't know the previous version | |
| 405 | 325 | return; |
| 406 | 326 | } |
| 407 | 327 | |
| 408 | - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104, 105 ); | |
| 409 | - | |
| 328 | + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101 ); | |
| 410 | 329 | foreach ( $migrations as $migration ) { |
| 411 | - if ( FrmAppHelper::$db_version < $migration || $old_db_version >= $migration ) { | |
| 412 | - continue; | |
| 330 | + if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) { | |
| 331 | + $function_name = 'migrate_to_' . $migration; | |
| 332 | + $this->$function_name(); | |
| 413 | 333 | } |
| 414 | - | |
| 415 | - $function_name = 'migrate_to_' . $migration; | |
| 416 | - $this->$function_name(); | |
| 417 | 334 | } |
| 418 | 335 | } |
| 419 | 336 | |
| 420 | - /** | |
| 421 | - * @return bool | |
| 422 | - */ | |
| 423 | 337 | public function uninstall() { |
| 424 | 338 | if ( ! current_user_can( 'administrator' ) ) { |
| 425 | 339 | $frm_settings = FrmAppHelper::get_settings(); |
| 426 | 340 | wp_die( esc_html( $frm_settings->admin_permission ) ); |
| @@ -431,9 +345,8 @@ | ||
| 431 | 345 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 432 | 346 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 433 | 347 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 434 | 348 | $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 | |
| 436 | 349 | |
| 437 | 350 | delete_option( 'frm_options' ); |
| 438 | 351 | delete_option( 'frm_db_version' ); |
| 439 | 352 | delete_option( 'frm_install_running' ); |
| @@ -446,9 +359,8 @@ | ||
| 446 | 359 | |
| 447 | 360 | // Delete roles. |
| 448 | 361 | $frm_roles = FrmAppHelper::frm_capabilities(); |
| 449 | 362 | $roles = get_editable_roles(); |
| 450 | - | |
| 451 | 363 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 452 | 364 | foreach ( $roles as $role => $details ) { |
| 453 | 365 | $wp_roles->remove_cap( $role, $frm_role ); |
| 454 | 366 | unset( $role, $details ); |
| @@ -456,16 +368,15 @@ | ||
| 456 | 368 | unset( $frm_role, $frm_role_description ); |
| 457 | 369 | } |
| 458 | 370 | unset( $roles, $frm_roles ); |
| 459 | 371 | |
| 460 | - // Delete actions, views, and styles | |
| 372 | + // delete actions, views, and styles | |
| 461 | 373 | |
| 462 | - // Prevent the post deletion from triggering entries to be deleted | |
| 374 | + // prevent the post deletion from triggering entries to be deleted | |
| 463 | 375 | remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' ); |
| 464 | 376 | remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' ); |
| 465 | 377 | |
| 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 | |
| 467 | - | |
| 378 | + $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' ) ); | |
| 468 | 379 | foreach ( $post_ids as $post_id ) { |
| 469 | 380 | // Delete's each post. |
| 470 | 381 | wp_delete_post( $post_id, true ); |
| 471 | 382 | } |
| @@ -470,15 +381,15 @@ | ||
| 470 | 381 | wp_delete_post( $post_id, true ); |
| 471 | 382 | } |
| 472 | 383 | unset( $post_ids ); |
| 473 | 384 | |
| 474 | - // Delete transients | |
| 385 | + // delete transients | |
| 475 | 386 | delete_transient( 'frmpro_css' ); |
| 476 | 387 | delete_transient( 'frm_options' ); |
| 477 | 388 | delete_transient( 'frmpro_options' ); |
| 478 | 389 | delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME ); |
| 479 | 390 | |
| 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 | |
| 391 | + $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_%' ) ); | |
| 481 | 392 | |
| 482 | 393 | do_action( 'frm_after_uninstall' ); |
| 483 | 394 | |
| 484 | 395 | return true; |
| @@ -484,44 +395,11 @@ | ||
| 484 | 395 | return true; |
| 485 | 396 | } |
| 486 | 397 | |
| 487 | 398 | /** |
| 488 | - * In older versions of Lite, it's possible we've saved the wrong location ID. | |
| 489 | - * So force it to get valid values again. | |
| 490 | - * | |
| 491 | - * @since 6.25 | |
| 492 | - * | |
| 493 | - * @return void | |
| 494 | - */ | |
| 495 | - private function migrate_to_104() { | |
| 496 | - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'test' ) ) { | |
| 497 | - FrmSquareLiteConnectHelper::get_location_id( true, 'test' ); | |
| 498 | - } | |
| 499 | - | |
| 500 | - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'live' ) ) { | |
| 501 | - FrmSquareLiteConnectHelper::get_location_id( true, 'live' ); | |
| 502 | - } | |
| 503 | - } | |
| 504 | - | |
| 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 | - /** | |
| 519 | 399 | * Disables summary email for multisite (not the main site) if recipient setting isn't changed. |
| 520 | 400 | * |
| 521 | 401 | * @since 6.8 |
| 522 | - * | |
| 523 | - * @return void | |
| 524 | 402 | */ |
| 525 | 403 | private function migrate_to_101() { |
| 526 | 404 | if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) { |
| 527 | 405 | return; |
| @@ -527,9 +405,8 @@ | ||
| 527 | 405 | return; |
| 528 | 406 | } |
| 529 | 407 | |
| 530 | 408 | $frm_settings = FrmAppHelper::get_settings(); |
| 531 | - | |
| 532 | 409 | if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) { |
| 533 | 410 | // User changed it. |
| 534 | 411 | return; |
| 535 | 412 | } |
| @@ -541,10 +418,8 @@ | ||
| 541 | 418 | /** |
| 542 | 419 | * Clear frmpro_css transient. |
| 543 | 420 | * |
| 544 | 421 | * @since 4.10.02 |
| 545 | - * | |
| 546 | - * @return void | |
| 547 | 422 | */ |
| 548 | 423 | private function migrate_to_98() { |
| 549 | 424 | delete_transient( 'frmpro_css' ); |
| 550 | 425 | } |
| @@ -552,10 +427,8 @@ | ||
| 552 | 427 | /** |
| 553 | 428 | * Move default_blank and clear_on_focus to placeholder. |
| 554 | 429 | * |
| 555 | 430 | * @since 4.0 |
| 556 | - * | |
| 557 | - * @return void | |
| 558 | 431 | */ |
| 559 | 432 | private function migrate_to_97() { |
| 560 | 433 | $this->migrate_to_placeholder( 'clear_on_focus' ); |
| 561 | 434 | $this->migrate_to_placeholder( 'default_blank' ); |
| @@ -564,12 +437,8 @@ | ||
| 564 | 437 | /** |
| 565 | 438 | * Move clear_on_focus or default_blank to placeholder. |
| 566 | 439 | * |
| 567 | 440 | * @since 4.0 |
| 568 | - * | |
| 569 | - * @param string $type Field option key to migrate. | |
| 570 | - * | |
| 571 | - * @return void | |
| 572 | 441 | */ |
| 573 | 442 | private function migrate_to_placeholder( $type = 'clear_on_focus' ) { |
| 574 | 443 | $query = array( |
| 575 | 444 | 'field_options like' => '"' . $type . '";s:1:"1";', |
| @@ -580,10 +449,9 @@ | ||
| 580 | 449 | foreach ( $fields as $field ) { |
| 581 | 450 | FrmAppHelper::unserialize_or_decode( $field->field_options ); |
| 582 | 451 | FrmAppHelper::unserialize_or_decode( $field->options ); |
| 583 | 452 | $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type ); |
| 584 | - | |
| 585 | - if ( ! $update_values ) { | |
| 453 | + if ( empty( $update_values ) ) { | |
| 586 | 454 | continue; |
| 587 | 455 | } |
| 588 | 456 | |
| 589 | 457 | FrmField::update( $field->id, $update_values ); |
| @@ -594,15 +462,11 @@ | ||
| 594 | 462 | /** |
| 595 | 463 | * Delete unneeded default templates |
| 596 | 464 | * |
| 597 | 465 | * @since 3.06 |
| 598 | - * | |
| 599 | - * @return void | |
| 600 | 466 | */ |
| 601 | 467 | private function migrate_to_90() { |
| 602 | 468 | $form = FrmForm::getOne( 'contact' ); |
| 603 | - | |
| 604 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 605 | 469 | if ( $form && $form->default_template == 1 ) { |
| 606 | 470 | FrmForm::destroy( 'contact' ); |
| 607 | 471 | } |
| 608 | 472 | } |
| @@ -610,15 +474,14 @@ | ||
| 610 | 474 | /** |
| 611 | 475 | * Reverse migration 17 -- Divide by 9 |
| 612 | 476 | * |
| 613 | 477 | * @since 3.0.05 |
| 614 | - * | |
| 615 | - * @return void | |
| 616 | 478 | */ |
| 617 | 479 | private function migrate_to_86() { |
| 480 | + | |
| 618 | 481 | $fields = $this->get_fields_with_size(); |
| 619 | 482 | |
| 620 | - foreach ( $fields as $f ) { | |
| 483 | + foreach ( (array) $fields as $f ) { | |
| 621 | 484 | FrmAppHelper::unserialize_or_decode( $f->field_options ); |
| 622 | 485 | $size = $f->field_options['size']; |
| 623 | 486 | $this->maybe_convert_migrated_size( $size ); |
| 624 | 487 | |
| @@ -630,12 +493,11 @@ | ||
| 630 | 493 | FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
| 631 | 494 | unset( $f ); |
| 632 | 495 | } |
| 633 | 496 | |
| 634 | - // Reverse the extra size changes in widgets | |
| 497 | + // reverse the extra size changes in widgets | |
| 635 | 498 | $widgets = get_option( 'widget_frm_show_form' ); |
| 636 | - | |
| 637 | - if ( ! $widgets ) { | |
| 499 | + if ( empty( $widgets ) ) { | |
| 638 | 500 | return; |
| 639 | 501 | } |
| 640 | 502 | |
| 641 | 503 | $this->revert_widget_field_size(); |
| @@ -640,11 +502,8 @@ | ||
| 640 | 502 | |
| 641 | 503 | $this->revert_widget_field_size(); |
| 642 | 504 | } |
| 643 | 505 | |
| 644 | - /** | |
| 645 | - * @return array | |
| 646 | - */ | |
| 647 | 506 | private function get_fields_with_size() { |
| 648 | 507 | $field_types = array( |
| 649 | 508 | 'textarea', |
| 650 | 509 | 'text', |
| @@ -672,20 +531,16 @@ | ||
| 672 | 531 | /** |
| 673 | 532 | * Reverse the extra size changes in widgets |
| 674 | 533 | * |
| 675 | 534 | * @since 3.0.05 |
| 676 | - * | |
| 677 | - * @return void | |
| 678 | 535 | */ |
| 679 | 536 | private function revert_widget_field_size() { |
| 680 | 537 | $widgets = get_option( 'widget_frm_show_form' ); |
| 681 | - | |
| 682 | - if ( ! $widgets ) { | |
| 538 | + if ( empty( $widgets ) ) { | |
| 683 | 539 | return; |
| 684 | 540 | } |
| 685 | 541 | |
| 686 | 542 | FrmAppHelper::unserialize_or_decode( $widgets ); |
| 687 | - | |
| 688 | 543 | foreach ( $widgets as $k => $widget ) { |
| 689 | 544 | if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) { |
| 690 | 545 | continue; |
| 691 | 546 | } |
| @@ -691,9 +546,8 @@ | ||
| 691 | 546 | } |
| 692 | 547 | |
| 693 | 548 | $this->maybe_convert_migrated_size( $widgets[ $k ]['size'] ); |
| 694 | 549 | } |
| 695 | - | |
| 696 | 550 | update_option( 'widget_frm_show_form', $widgets ); |
| 697 | 551 | } |
| 698 | 552 | |
| 699 | 553 | /** |
| @@ -699,28 +553,23 @@ | ||
| 699 | 553 | /** |
| 700 | 554 | * Divide by 9 to reverse the multiplication |
| 701 | 555 | * |
| 702 | 556 | * @since 3.0.05 |
| 703 | - * | |
| 704 | - * @param string $size Size string to maybe convert, passed by reference. | |
| 705 | - * | |
| 706 | - * @return void | |
| 707 | 557 | */ |
| 708 | 558 | private function maybe_convert_migrated_size( &$size ) { |
| 709 | - $has_px_size = $size && str_contains( $size, 'px' ); | |
| 710 | - | |
| 559 | + $has_px_size = ! empty( $size ) && strpos( $size, 'px' ); | |
| 711 | 560 | if ( ! $has_px_size ) { |
| 712 | 561 | return; |
| 713 | 562 | } |
| 714 | 563 | |
| 715 | 564 | $int_size = str_replace( 'px', '', $size ); |
| 716 | - | |
| 717 | 565 | if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) { |
| 718 | 566 | return; |
| 719 | 567 | } |
| 720 | 568 | |
| 721 | 569 | $pixel_conversion = 9; |
| 722 | - $size = round( (int) $int_size / $pixel_conversion ); | |
| 570 | + | |
| 571 | + $size = round( (int) $int_size / $pixel_conversion ); | |
| 723 | 572 | } |
| 724 | 573 | |
| 725 | 574 | /** |
| 726 | 575 | * Migrate old styling settings. If sites are using the old |
| @@ -726,17 +575,14 @@ | ||
| 726 | 575 | * Migrate old styling settings. If sites are using the old |
| 727 | 576 | * default 400px field width, switch it to 100% |
| 728 | 577 | * |
| 729 | 578 | * @since 2.0.4 |
| 730 | - * | |
| 731 | - * @return void | |
| 732 | 579 | */ |
| 733 | 580 | private function migrate_to_25() { |
| 734 | - // Get the style that was created with the style migration | |
| 581 | + // get the style that was created with the style migration | |
| 735 | 582 | $frm_style = new FrmStyle(); |
| 736 | 583 | $styles = $frm_style->get_all( 'post_date', 'ASC', 1 ); |
| 737 | - | |
| 738 | - if ( ! $styles ) { | |
| 584 | + if ( empty( $styles ) ) { | |
| 739 | 585 | return; |
| 740 | 586 | } |
| 741 | 587 | |
| 742 | 588 | foreach ( $styles as $style ) { |
| @@ -753,16 +599,13 @@ | ||
| 753 | 599 | * Check if the parent_form_id columns exists. |
| 754 | 600 | * If not, try and add it again |
| 755 | 601 | * |
| 756 | 602 | * @since 2.0.2 |
| 757 | - * | |
| 758 | - * @return void | |
| 759 | 603 | */ |
| 760 | 604 | private function migrate_to_23() { |
| 761 | 605 | global $wpdb; |
| 762 | 606 | $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 763 | - | |
| 764 | - if ( ! $exists ) { | |
| 607 | + if ( empty( $exists ) ) { | |
| 765 | 608 | $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 766 | 609 | } |
| 767 | 610 | } |
| 768 | 611 | |
| @@ -767,10 +610,8 @@ | ||
| 767 | 610 | } |
| 768 | 611 | |
| 769 | 612 | /** |
| 770 | 613 | * Change field size from character to pixel -- Multiply by 9 |
| 771 | - * | |
| 772 | - * @return void | |
| 773 | 614 | */ |
| 774 | 615 | private function migrate_to_17() { |
| 775 | 616 | $fields = $this->get_fields_with_size(); |
| 776 | 617 | |
| @@ -775,9 +616,8 @@ | ||
| 775 | 616 | $fields = $this->get_fields_with_size(); |
| 776 | 617 | |
| 777 | 618 | foreach ( $fields as $f ) { |
| 778 | 619 | FrmAppHelper::unserialize_or_decode( $f->field_options ); |
| 779 | - | |
| 780 | 620 | if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) { |
| 781 | 621 | continue; |
| 782 | 622 | } |
| 783 | 623 | |
| @@ -791,20 +631,16 @@ | ||
| 791 | 631 | } |
| 792 | 632 | |
| 793 | 633 | /** |
| 794 | 634 | * Change the characters in widgets to pixels |
| 795 | - * | |
| 796 | - * @return void | |
| 797 | 635 | */ |
| 798 | 636 | private function adjust_widget_size() { |
| 799 | 637 | $widgets = get_option( 'widget_frm_show_form' ); |
| 800 | - | |
| 801 | - if ( ! $widgets ) { | |
| 638 | + if ( empty( $widgets ) ) { | |
| 802 | 639 | return; |
| 803 | 640 | } |
| 804 | 641 | |
| 805 | 642 | FrmAppHelper::unserialize_or_decode( $widgets ); |
| 806 | - | |
| 807 | 643 | foreach ( $widgets as $k => $widget ) { |
| 808 | 644 | if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) { |
| 809 | 645 | continue; |
| 810 | 646 | } |
| @@ -809,17 +645,11 @@ | ||
| 809 | 645 | continue; |
| 810 | 646 | } |
| 811 | 647 | $this->convert_character_to_px( $widgets[ $k ]['size'] ); |
| 812 | 648 | } |
| 813 | - | |
| 814 | 649 | update_option( 'widget_frm_show_form', $widgets ); |
| 815 | 650 | } |
| 816 | 651 | |
| 817 | - /** | |
| 818 | - * @param string $size | |
| 819 | - * | |
| 820 | - * @return void | |
| 821 | - */ | |
| 822 | 652 | private function convert_character_to_px( &$size ) { |
| 823 | 653 | $pixel_conversion = 9; |
| 824 | 654 | |
| 825 | 655 | $size = round( $pixel_conversion * (int) $size ); |
| @@ -862,9 +692,9 @@ | ||
| 862 | 692 | * post_excerpt: message |
| 863 | 693 | */ |
| 864 | 694 | foreach ( $forms as $form ) { |
| 865 | 695 | if ( $form->is_template && $form->default_template ) { |
| 866 | - // Don't migrate the default templates since the email will be added anyway | |
| 696 | + // don't migrate the default templates since the email will be added anyway | |
| 867 | 697 | continue; |
| 868 | 698 | } |
| 869 | 699 | |
| 870 | 700 | // Format form options |
| @@ -878,9 +708,10 @@ | ||
| 878 | 708 | |
| 879 | 709 | private function migrate_to_11() { |
| 880 | 710 | global $wpdb; |
| 881 | 711 | |
| 882 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options' ); | |
| 712 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options' ); | |
| 713 | + | |
| 883 | 714 | $sending = __( 'Sending', 'formidable' ); |
| 884 | 715 | $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; |
| 885 | 716 | $old_default_html = <<<DEFAULT_HTML |
| 886 | 717 | <div class="frm_submit"> |
| @@ -892,21 +723,18 @@ | ||
| 892 | 723 | unset( $sending, $img ); |
| 893 | 724 | |
| 894 | 725 | $new_default_html = FrmFormsHelper::get_default_html( 'submit' ); |
| 895 | 726 | $draft_link = FrmFormsHelper::get_draft_link(); |
| 896 | - | |
| 897 | 727 | foreach ( $forms as $form ) { |
| 898 | 728 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 899 | - | |
| 900 | 729 | if ( empty( $form->options['submit_html'] ) ) { |
| 901 | 730 | continue; |
| 902 | 731 | } |
| 903 | 732 | |
| 904 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 905 | 733 | if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
| 906 | 734 | $form->options['submit_html'] = $new_default_html; |
| 907 | 735 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 908 | - } elseif ( ! str_contains( $form->options['submit_html'], 'save_draft' ) ) { | |
| 736 | + } elseif ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) { | |
| 909 | 737 | $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] ); |
| 910 | 738 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 911 | 739 | } |
| 912 | 740 | unset( $form ); |