| @@ -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; |
| @@ -51,11 +32,9 @@ | ||
| 51 | 32 | ) |
| 52 | 33 | ); |
| 53 | 34 | |
| 54 | 35 | if ( $needs_upgrade ) { |
| 55 | - $this->maybe_delete_htaccess_file(); | |
| 56 | - | |
| 57 | - // Update rewrite rules for views and other custom post types | |
| 36 | + // update rewrite rules for views and other custom post types | |
| 58 | 37 | flush_rewrite_rules(); |
| 59 | 38 | |
| 60 | 39 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 61 | 40 | |
| @@ -73,10 +52,8 @@ | ||
| 73 | 52 | |
| 74 | 53 | if ( false === get_option( 'frm_first_activation' ) ) { |
| 75 | 54 | update_option( 'frm_first_activation', time(), false ); |
| 76 | 55 | } |
| 77 | - | |
| 78 | - $this->update_settings_for_new_install(); | |
| 79 | 56 | } |
| 80 | 57 | }//end if |
| 81 | 58 | |
| 82 | 59 | do_action( 'frm_after_install' ); |
| @@ -84,56 +61,16 @@ | ||
| 84 | 61 | $frm_vars['doing_upgrade'] = false; |
| 85 | 62 | |
| 86 | 63 | FrmAppHelper::save_combined_js(); |
| 87 | 64 | |
| 88 | - // Update the styling settings | |
| 89 | - if ( ! function_exists( 'get_filesystem_method' ) ) { | |
| 90 | - return; | |
| 65 | + // update the styling settings | |
| 66 | + if ( function_exists( 'get_filesystem_method' ) ) { | |
| 67 | + $frm_style = new FrmStyle(); | |
| 68 | + $frm_style->update( 'default' ); | |
| 91 | 69 | } |
| 92 | - | |
| 93 | - $frm_style = new FrmStyle(); | |
| 94 | - $frm_style->update( 'default' ); | |
| 95 | 70 | } |
| 96 | 71 | |
| 97 | 72 | /** |
| 98 | - * Check if the .htaccess file should be deleted based on server response. | |
| 99 | - * If a server has AllowOverride FileInfo but not AllowOverride AuthConfig, JS and CSS files | |
| 100 | - * will result in a 500 error. | |
| 101 | - * | |
| 102 | - * @since 6.27 | |
| 103 | - * | |
| 104 | - * @return void | |
| 105 | - */ | |
| 106 | - private function maybe_delete_htaccess_file() { | |
| 107 | - $css_file_request = wp_remote_get( FrmAppHelper::plugin_url() . '/css/frm_fonts.css' ); | |
| 108 | - | |
| 109 | - if ( 200 === wp_remote_retrieve_response_code( $css_file_request ) ) { | |
| 110 | - return; | |
| 111 | - } | |
| 112 | - | |
| 113 | - $htaccess_path = FrmAppHelper::plugin_path() . '/.htaccess'; | |
| 114 | - | |
| 115 | - if ( file_exists( $htaccess_path ) ) { | |
| 116 | - wp_delete_file( $htaccess_path ); | |
| 117 | - } | |
| 118 | - } | |
| 119 | - | |
| 120 | - /** | |
| 121 | - * Updates some settings for new installs. | |
| 122 | - * | |
| 123 | - * @since 6.23 | |
| 124 | - * | |
| 125 | - * @return void | |
| 126 | - */ | |
| 127 | - private function update_settings_for_new_install() { | |
| 128 | - $settings = FrmAppHelper::get_settings(); | |
| 129 | - | |
| 130 | - $settings->denylist_check = 1; | |
| 131 | - $settings->installed_after_welcome_tour_update = 1; | |
| 132 | - $settings->store(); | |
| 133 | - } | |
| 134 | - | |
| 135 | - /** | |
| 136 | 73 | * If we fail to create the database tables, add an inbox notice. |
| 137 | 74 | * This informs the user that they need to correct the issue and try again. |
| 138 | 75 | * |
| 139 | 76 | * @since 6.19 |
| @@ -153,9 +90,9 @@ | ||
| 153 | 90 | |
| 154 | 91 | $message = array( |
| 155 | 92 | 'key' => 'failed-to-create-tables', |
| 156 | 93 | 'subject' => 'Something went wrong setting up the database', |
| 157 | - '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 | |
| 94 | + '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.', | |
| 158 | 95 | 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>', |
| 159 | 96 | 'type' => 'error', |
| 160 | 97 | ); |
| 161 | 98 | |
| @@ -167,14 +104,15 @@ | ||
| 167 | 104 | * @return string |
| 168 | 105 | */ |
| 169 | 106 | public function collation() { |
| 170 | 107 | global $wpdb; |
| 171 | - return $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : ''; | |
| 108 | + if ( ! $wpdb->has_cap( 'collation' ) ) { | |
| 109 | + return ''; | |
| 110 | + } | |
| 111 | + | |
| 112 | + return $wpdb->get_charset_collate(); | |
| 172 | 113 | } |
| 173 | 114 | |
| 174 | - /** | |
| 175 | - * @return void | |
| 176 | - */ | |
| 177 | 115 | private function create_tables() { |
| 178 | 116 | $charset_collate = $this->collation(); |
| 179 | 117 | $sql = array(); |
| 180 | 118 | |
| @@ -310,9 +248,8 @@ | ||
| 310 | 248 | * @since 6.6 |
| 311 | 249 | * |
| 312 | 250 | * @param string $table_name |
| 313 | 251 | * @param string $index_name |
| 314 | - * | |
| 315 | 252 | * @return bool |
| 316 | 253 | */ |
| 317 | 254 | private static function index_exists( $table_name, $index_name ) { |
| 318 | 255 | global $wpdb; |
| @@ -328,14 +265,10 @@ | ||
| 328 | 265 | ); |
| 329 | 266 | return (bool) $row; |
| 330 | 267 | } |
| 331 | 268 | |
| 332 | - /** | |
| 333 | - * @return void | |
| 334 | - */ | |
| 335 | 269 | private function maybe_create_contact_form() { |
| 336 | 270 | $form_exists = FrmForm::get_id_by_key( 'contact-form' ); |
| 337 | - | |
| 338 | 271 | if ( ! $form_exists ) { |
| 339 | 272 | $this->add_default_template(); |
| 340 | 273 | } |
| 341 | 274 | } |
| @@ -343,10 +276,8 @@ | ||
| 343 | 276 | /** |
| 344 | 277 | * Create the default contact form |
| 345 | 278 | * |
| 346 | 279 | * @since 3.06 |
| 347 | - * | |
| 348 | - * @return void | |
| 349 | 280 | */ |
| 350 | 281 | private function add_default_template() { |
| 351 | 282 | if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) { |
| 352 | 283 | // XML import is not enabled on your server. |
| @@ -354,9 +285,10 @@ | ||
| 354 | 285 | } |
| 355 | 286 | |
| 356 | 287 | $set_err = libxml_use_internal_errors( true ); |
| 357 | 288 | $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true ); |
| 358 | - $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml'; | |
| 289 | + | |
| 290 | + $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml'; | |
| 359 | 291 | FrmXMLHelper::import_xml( $file ); |
| 360 | 292 | |
| 361 | 293 | libxml_use_internal_errors( $set_err ); |
| 362 | 294 | FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader ); |
| @@ -363,28 +295,24 @@ | ||
| 363 | 295 | } |
| 364 | 296 | |
| 365 | 297 | /** |
| 366 | 298 | * @param int|string $old_db_version |
| 367 | - * | |
| 368 | - * @return void | |
| 369 | 299 | */ |
| 370 | 300 | private function migrate_data( $old_db_version ) { |
| 371 | 301 | if ( ! $old_db_version ) { |
| 372 | 302 | $old_db_version = get_option( 'frm_db_version' ); |
| 373 | 303 | } |
| 374 | - | |
| 375 | - if ( str_contains( $old_db_version, '-' ) ) { | |
| 304 | + if ( strpos( $old_db_version, '-' ) ) { | |
| 376 | 305 | $last_upgrade = explode( '-', $old_db_version ); |
| 377 | 306 | $old_db_version = (int) $last_upgrade[1]; |
| 378 | 307 | } |
| 379 | 308 | |
| 380 | 309 | if ( ! is_numeric( $old_db_version ) ) { |
| 381 | - // Bail if we don't know the previous version | |
| 310 | + // bail if we don't know the previous version | |
| 382 | 311 | return; |
| 383 | 312 | } |
| 384 | 313 | |
| 385 | - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 ); | |
| 386 | - | |
| 314 | + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101 ); | |
| 387 | 315 | foreach ( $migrations as $migration ) { |
| 388 | 316 | if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) { |
| 389 | 317 | $function_name = 'migrate_to_' . $migration; |
| 390 | 318 | $this->$function_name(); |
| @@ -391,11 +319,8 @@ | ||
| 391 | 319 | } |
| 392 | 320 | } |
| 393 | 321 | } |
| 394 | 322 | |
| 395 | - /** | |
| 396 | - * @return bool | |
| 397 | - */ | |
| 398 | 323 | public function uninstall() { |
| 399 | 324 | if ( ! current_user_can( 'administrator' ) ) { |
| 400 | 325 | $frm_settings = FrmAppHelper::get_settings(); |
| 401 | 326 | wp_die( esc_html( $frm_settings->admin_permission ) ); |
| @@ -420,9 +345,8 @@ | ||
| 420 | 345 | |
| 421 | 346 | // Delete roles. |
| 422 | 347 | $frm_roles = FrmAppHelper::frm_capabilities(); |
| 423 | 348 | $roles = get_editable_roles(); |
| 424 | - | |
| 425 | 349 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
| 426 | 350 | foreach ( $roles as $role => $details ) { |
| 427 | 351 | $wp_roles->remove_cap( $role, $frm_role ); |
| 428 | 352 | unset( $role, $details ); |
| @@ -430,16 +354,15 @@ | ||
| 430 | 354 | unset( $frm_role, $frm_role_description ); |
| 431 | 355 | } |
| 432 | 356 | unset( $roles, $frm_roles ); |
| 433 | 357 | |
| 434 | - // Delete actions, views, and styles | |
| 358 | + // delete actions, views, and styles | |
| 435 | 359 | |
| 436 | - // Prevent the post deletion from triggering entries to be deleted | |
| 360 | + // prevent the post deletion from triggering entries to be deleted | |
| 437 | 361 | remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' ); |
| 438 | 362 | remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' ); |
| 439 | 363 | |
| 440 | - $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 | |
| 441 | - | |
| 364 | + $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' ) ); | |
| 442 | 365 | foreach ( $post_ids as $post_id ) { |
| 443 | 366 | // Delete's each post. |
| 444 | 367 | wp_delete_post( $post_id, true ); |
| 445 | 368 | } |
| @@ -444,15 +367,15 @@ | ||
| 444 | 367 | wp_delete_post( $post_id, true ); |
| 445 | 368 | } |
| 446 | 369 | unset( $post_ids ); |
| 447 | 370 | |
| 448 | - // Delete transients | |
| 371 | + // delete transients | |
| 449 | 372 | delete_transient( 'frmpro_css' ); |
| 450 | 373 | delete_transient( 'frm_options' ); |
| 451 | 374 | delete_transient( 'frmpro_options' ); |
| 452 | 375 | delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME ); |
| 453 | 376 | |
| 454 | - $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 | |
| 377 | + $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_%' ) ); | |
| 455 | 378 | |
| 456 | 379 | do_action( 'frm_after_uninstall' ); |
| 457 | 380 | |
| 458 | 381 | return true; |
| @@ -458,31 +381,11 @@ | ||
| 458 | 381 | return true; |
| 459 | 382 | } |
| 460 | 383 | |
| 461 | 384 | /** |
| 462 | - * In older versions of Lite, it's possible we've saved the wrong location ID. | |
| 463 | - * So force it to get valid values again. | |
| 464 | - * | |
| 465 | - * @since 6.25 | |
| 466 | - * | |
| 467 | - * @return void | |
| 468 | - */ | |
| 469 | - private function migrate_to_104() { | |
| 470 | - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'test' ) ) { | |
| 471 | - FrmSquareLiteConnectHelper::get_location_id( true, 'test' ); | |
| 472 | - } | |
| 473 | - | |
| 474 | - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'live' ) ) { | |
| 475 | - FrmSquareLiteConnectHelper::get_location_id( true, 'live' ); | |
| 476 | - } | |
| 477 | - } | |
| 478 | - | |
| 479 | - /** | |
| 480 | 385 | * Disables summary email for multisite (not the main site) if recipient setting isn't changed. |
| 481 | 386 | * |
| 482 | 387 | * @since 6.8 |
| 483 | - * | |
| 484 | - * @return void | |
| 485 | 388 | */ |
| 486 | 389 | private function migrate_to_101() { |
| 487 | 390 | if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) { |
| 488 | 391 | return; |
| @@ -488,9 +391,8 @@ | ||
| 488 | 391 | return; |
| 489 | 392 | } |
| 490 | 393 | |
| 491 | 394 | $frm_settings = FrmAppHelper::get_settings(); |
| 492 | - | |
| 493 | 395 | if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) { |
| 494 | 396 | // User changed it. |
| 495 | 397 | return; |
| 496 | 398 | } |
| @@ -502,10 +404,8 @@ | ||
| 502 | 404 | /** |
| 503 | 405 | * Clear frmpro_css transient. |
| 504 | 406 | * |
| 505 | 407 | * @since 4.10.02 |
| 506 | - * | |
| 507 | - * @return void | |
| 508 | 408 | */ |
| 509 | 409 | private function migrate_to_98() { |
| 510 | 410 | delete_transient( 'frmpro_css' ); |
| 511 | 411 | } |
| @@ -513,10 +413,8 @@ | ||
| 513 | 413 | /** |
| 514 | 414 | * Move default_blank and clear_on_focus to placeholder. |
| 515 | 415 | * |
| 516 | 416 | * @since 4.0 |
| 517 | - * | |
| 518 | - * @return void | |
| 519 | 417 | */ |
| 520 | 418 | private function migrate_to_97() { |
| 521 | 419 | $this->migrate_to_placeholder( 'clear_on_focus' ); |
| 522 | 420 | $this->migrate_to_placeholder( 'default_blank' ); |
| @@ -525,12 +423,8 @@ | ||
| 525 | 423 | /** |
| 526 | 424 | * Move clear_on_focus or default_blank to placeholder. |
| 527 | 425 | * |
| 528 | 426 | * @since 4.0 |
| 529 | - * | |
| 530 | - * @param string $type Field option key to migrate. | |
| 531 | - * | |
| 532 | - * @return void | |
| 533 | 427 | */ |
| 534 | 428 | private function migrate_to_placeholder( $type = 'clear_on_focus' ) { |
| 535 | 429 | $query = array( |
| 536 | 430 | 'field_options like' => '"' . $type . '";s:1:"1";', |
| @@ -541,10 +435,9 @@ | ||
| 541 | 435 | foreach ( $fields as $field ) { |
| 542 | 436 | FrmAppHelper::unserialize_or_decode( $field->field_options ); |
| 543 | 437 | FrmAppHelper::unserialize_or_decode( $field->options ); |
| 544 | 438 | $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type ); |
| 545 | - | |
| 546 | - if ( ! $update_values ) { | |
| 439 | + if ( empty( $update_values ) ) { | |
| 547 | 440 | continue; |
| 548 | 441 | } |
| 549 | 442 | |
| 550 | 443 | FrmField::update( $field->id, $update_values ); |
| @@ -555,15 +448,11 @@ | ||
| 555 | 448 | /** |
| 556 | 449 | * Delete unneeded default templates |
| 557 | 450 | * |
| 558 | 451 | * @since 3.06 |
| 559 | - * | |
| 560 | - * @return void | |
| 561 | 452 | */ |
| 562 | 453 | private function migrate_to_90() { |
| 563 | 454 | $form = FrmForm::getOne( 'contact' ); |
| 564 | - | |
| 565 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 566 | 455 | if ( $form && $form->default_template == 1 ) { |
| 567 | 456 | FrmForm::destroy( 'contact' ); |
| 568 | 457 | } |
| 569 | 458 | } |
| @@ -571,15 +460,14 @@ | ||
| 571 | 460 | /** |
| 572 | 461 | * Reverse migration 17 -- Divide by 9 |
| 573 | 462 | * |
| 574 | 463 | * @since 3.0.05 |
| 575 | - * | |
| 576 | - * @return void | |
| 577 | 464 | */ |
| 578 | 465 | private function migrate_to_86() { |
| 466 | + | |
| 579 | 467 | $fields = $this->get_fields_with_size(); |
| 580 | 468 | |
| 581 | - foreach ( $fields as $f ) { | |
| 469 | + foreach ( (array) $fields as $f ) { | |
| 582 | 470 | FrmAppHelper::unserialize_or_decode( $f->field_options ); |
| 583 | 471 | $size = $f->field_options['size']; |
| 584 | 472 | $this->maybe_convert_migrated_size( $size ); |
| 585 | 473 | |
| @@ -591,12 +479,11 @@ | ||
| 591 | 479 | FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
| 592 | 480 | unset( $f ); |
| 593 | 481 | } |
| 594 | 482 | |
| 595 | - // Reverse the extra size changes in widgets | |
| 483 | + // reverse the extra size changes in widgets | |
| 596 | 484 | $widgets = get_option( 'widget_frm_show_form' ); |
| 597 | - | |
| 598 | - if ( ! $widgets ) { | |
| 485 | + if ( empty( $widgets ) ) { | |
| 599 | 486 | return; |
| 600 | 487 | } |
| 601 | 488 | |
| 602 | 489 | $this->revert_widget_field_size(); |
| @@ -601,11 +488,8 @@ | ||
| 601 | 488 | |
| 602 | 489 | $this->revert_widget_field_size(); |
| 603 | 490 | } |
| 604 | 491 | |
| 605 | - /** | |
| 606 | - * @return array | |
| 607 | - */ | |
| 608 | 492 | private function get_fields_with_size() { |
| 609 | 493 | $field_types = array( |
| 610 | 494 | 'textarea', |
| 611 | 495 | 'text', |
| @@ -633,20 +517,16 @@ | ||
| 633 | 517 | /** |
| 634 | 518 | * Reverse the extra size changes in widgets |
| 635 | 519 | * |
| 636 | 520 | * @since 3.0.05 |
| 637 | - * | |
| 638 | - * @return void | |
| 639 | 521 | */ |
| 640 | 522 | private function revert_widget_field_size() { |
| 641 | 523 | $widgets = get_option( 'widget_frm_show_form' ); |
| 642 | - | |
| 643 | - if ( ! $widgets ) { | |
| 524 | + if ( empty( $widgets ) ) { | |
| 644 | 525 | return; |
| 645 | 526 | } |
| 646 | 527 | |
| 647 | 528 | FrmAppHelper::unserialize_or_decode( $widgets ); |
| 648 | - | |
| 649 | 529 | foreach ( $widgets as $k => $widget ) { |
| 650 | 530 | if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) { |
| 651 | 531 | continue; |
| 652 | 532 | } |
| @@ -652,9 +532,8 @@ | ||
| 652 | 532 | } |
| 653 | 533 | |
| 654 | 534 | $this->maybe_convert_migrated_size( $widgets[ $k ]['size'] ); |
| 655 | 535 | } |
| 656 | - | |
| 657 | 536 | update_option( 'widget_frm_show_form', $widgets ); |
| 658 | 537 | } |
| 659 | 538 | |
| 660 | 539 | /** |
| @@ -660,28 +539,23 @@ | ||
| 660 | 539 | /** |
| 661 | 540 | * Divide by 9 to reverse the multiplication |
| 662 | 541 | * |
| 663 | 542 | * @since 3.0.05 |
| 664 | - * | |
| 665 | - * @param string $size Size string to maybe convert, passed by reference. | |
| 666 | - * | |
| 667 | - * @return void | |
| 668 | 543 | */ |
| 669 | 544 | private function maybe_convert_migrated_size( &$size ) { |
| 670 | - $has_px_size = $size && str_contains( $size, 'px' ); | |
| 671 | - | |
| 545 | + $has_px_size = ! empty( $size ) && strpos( $size, 'px' ); | |
| 672 | 546 | if ( ! $has_px_size ) { |
| 673 | 547 | return; |
| 674 | 548 | } |
| 675 | 549 | |
| 676 | 550 | $int_size = str_replace( 'px', '', $size ); |
| 677 | - | |
| 678 | 551 | if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) { |
| 679 | 552 | return; |
| 680 | 553 | } |
| 681 | 554 | |
| 682 | 555 | $pixel_conversion = 9; |
| 683 | - $size = round( (int) $int_size / $pixel_conversion ); | |
| 556 | + | |
| 557 | + $size = round( (int) $int_size / $pixel_conversion ); | |
| 684 | 558 | } |
| 685 | 559 | |
| 686 | 560 | /** |
| 687 | 561 | * Migrate old styling settings. If sites are using the old |
| @@ -687,17 +561,14 @@ | ||
| 687 | 561 | * Migrate old styling settings. If sites are using the old |
| 688 | 562 | * default 400px field width, switch it to 100% |
| 689 | 563 | * |
| 690 | 564 | * @since 2.0.4 |
| 691 | - * | |
| 692 | - * @return void | |
| 693 | 565 | */ |
| 694 | 566 | private function migrate_to_25() { |
| 695 | - // Get the style that was created with the style migration | |
| 567 | + // get the style that was created with the style migration | |
| 696 | 568 | $frm_style = new FrmStyle(); |
| 697 | 569 | $styles = $frm_style->get_all( 'post_date', 'ASC', 1 ); |
| 698 | - | |
| 699 | - if ( ! $styles ) { | |
| 570 | + if ( empty( $styles ) ) { | |
| 700 | 571 | return; |
| 701 | 572 | } |
| 702 | 573 | |
| 703 | 574 | foreach ( $styles as $style ) { |
| @@ -714,16 +585,13 @@ | ||
| 714 | 585 | * Check if the parent_form_id columns exists. |
| 715 | 586 | * If not, try and add it again |
| 716 | 587 | * |
| 717 | 588 | * @since 2.0.2 |
| 718 | - * | |
| 719 | - * @return void | |
| 720 | 589 | */ |
| 721 | 590 | private function migrate_to_23() { |
| 722 | 591 | global $wpdb; |
| 723 | 592 | $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 724 | - | |
| 725 | - if ( ! $exists ) { | |
| 593 | + if ( empty( $exists ) ) { | |
| 726 | 594 | $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 727 | 595 | } |
| 728 | 596 | } |
| 729 | 597 | |
| @@ -728,10 +596,8 @@ | ||
| 728 | 596 | } |
| 729 | 597 | |
| 730 | 598 | /** |
| 731 | 599 | * Change field size from character to pixel -- Multiply by 9 |
| 732 | - * | |
| 733 | - * @return void | |
| 734 | 600 | */ |
| 735 | 601 | private function migrate_to_17() { |
| 736 | 602 | $fields = $this->get_fields_with_size(); |
| 737 | 603 | |
| @@ -736,9 +602,8 @@ | ||
| 736 | 602 | $fields = $this->get_fields_with_size(); |
| 737 | 603 | |
| 738 | 604 | foreach ( $fields as $f ) { |
| 739 | 605 | FrmAppHelper::unserialize_or_decode( $f->field_options ); |
| 740 | - | |
| 741 | 606 | if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) { |
| 742 | 607 | continue; |
| 743 | 608 | } |
| 744 | 609 | |
| @@ -752,20 +617,16 @@ | ||
| 752 | 617 | } |
| 753 | 618 | |
| 754 | 619 | /** |
| 755 | 620 | * Change the characters in widgets to pixels |
| 756 | - * | |
| 757 | - * @return void | |
| 758 | 621 | */ |
| 759 | 622 | private function adjust_widget_size() { |
| 760 | 623 | $widgets = get_option( 'widget_frm_show_form' ); |
| 761 | - | |
| 762 | - if ( ! $widgets ) { | |
| 624 | + if ( empty( $widgets ) ) { | |
| 763 | 625 | return; |
| 764 | 626 | } |
| 765 | 627 | |
| 766 | 628 | FrmAppHelper::unserialize_or_decode( $widgets ); |
| 767 | - | |
| 768 | 629 | foreach ( $widgets as $k => $widget ) { |
| 769 | 630 | if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) { |
| 770 | 631 | continue; |
| 771 | 632 | } |
| @@ -770,17 +631,11 @@ | ||
| 770 | 631 | continue; |
| 771 | 632 | } |
| 772 | 633 | $this->convert_character_to_px( $widgets[ $k ]['size'] ); |
| 773 | 634 | } |
| 774 | - | |
| 775 | 635 | update_option( 'widget_frm_show_form', $widgets ); |
| 776 | 636 | } |
| 777 | 637 | |
| 778 | - /** | |
| 779 | - * @param string $size | |
| 780 | - * | |
| 781 | - * @return void | |
| 782 | - */ | |
| 783 | 638 | private function convert_character_to_px( &$size ) { |
| 784 | 639 | $pixel_conversion = 9; |
| 785 | 640 | |
| 786 | 641 | $size = round( $pixel_conversion * (int) $size ); |
| @@ -823,9 +678,9 @@ | ||
| 823 | 678 | * post_excerpt: message |
| 824 | 679 | */ |
| 825 | 680 | foreach ( $forms as $form ) { |
| 826 | 681 | if ( $form->is_template && $form->default_template ) { |
| 827 | - // Don't migrate the default templates since the email will be added anyway | |
| 682 | + // don't migrate the default templates since the email will be added anyway | |
| 828 | 683 | continue; |
| 829 | 684 | } |
| 830 | 685 | |
| 831 | 686 | // Format form options |
| @@ -839,9 +694,10 @@ | ||
| 839 | 694 | |
| 840 | 695 | private function migrate_to_11() { |
| 841 | 696 | global $wpdb; |
| 842 | 697 | |
| 843 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options' ); | |
| 698 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options' ); | |
| 699 | + | |
| 844 | 700 | $sending = __( 'Sending', 'formidable' ); |
| 845 | 701 | $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; |
| 846 | 702 | $old_default_html = <<<DEFAULT_HTML |
| 847 | 703 | <div class="frm_submit"> |
| @@ -853,21 +709,18 @@ | ||
| 853 | 709 | unset( $sending, $img ); |
| 854 | 710 | |
| 855 | 711 | $new_default_html = FrmFormsHelper::get_default_html( 'submit' ); |
| 856 | 712 | $draft_link = FrmFormsHelper::get_draft_link(); |
| 857 | - | |
| 858 | 713 | foreach ( $forms as $form ) { |
| 859 | 714 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 860 | - | |
| 861 | 715 | if ( empty( $form->options['submit_html'] ) ) { |
| 862 | 716 | continue; |
| 863 | 717 | } |
| 864 | 718 | |
| 865 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 866 | 719 | if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
| 867 | 720 | $form->options['submit_html'] = $new_default_html; |
| 868 | 721 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 869 | - } elseif ( ! str_contains( $form->options['submit_html'], 'save_draft' ) ) { | |
| 722 | + } elseif ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) { | |
| 870 | 723 | $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] ); |
| 871 | 724 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 872 | 725 | } |
| 873 | 726 | unset( $form ); |