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