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 +61 -374 6.345.0 View file →
@@ -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,34 +32,25 @@
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 - require_once ABSPATH . 'wp-admin/includes/upgrade.php';
39 + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
67 40
68 41 $old_db_version = get_option( 'frm_db_version' );
69 42
70 43 $this->create_tables();
71 44 $this->migrate_data( $old_db_version );
72 - $this->check_that_tables_exist();
73 45
74 - // SAVE DB VERSION.
46 + /***** SAVE DB VERSION *****/
75 47 update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version );
76 48
77 49 if ( ! $old_db_version ) {
78 50 $this->maybe_create_contact_form();
79 -
80 - if ( false === get_option( 'frm_first_activation' ) ) {
81 - update_option( 'frm_first_activation', time(), false );
82 - }
83 -
84 - $this->update_settings_for_new_install();
85 51 }
86 - }//end if
52 + }
87 53
88 54 do_action( 'frm_after_install' );
89 55
90 56 $frm_vars['doing_upgrade'] = false;
@@ -90,97 +56,24 @@
90 56 $frm_vars['doing_upgrade'] = false;
91 57
92 58 FrmAppHelper::save_combined_js();
93 59
94 - // Update the styling settings
95 - if ( ! function_exists( 'get_filesystem_method' ) ) {
96 - return;
60 + // update the styling settings
61 + if ( function_exists( 'get_filesystem_method' ) ) {
62 + $frm_style = new FrmStyle();
63 + $frm_style->update( 'default' );
97 64 }
98 -
99 - $frm_style = new FrmStyle();
100 - $frm_style->update( 'default' );
101 65 }
102 66
103 - /**
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 - * Updates some settings for new installs.
128 - *
129 - * @since 6.23
130 - *
131 - * @return void
132 - */
133 - private function update_settings_for_new_install() {
134 - $settings = FrmAppHelper::get_settings();
135 -
136 - $settings->denylist_check = 1;
137 - $settings->installed_after_welcome_tour_update = 1;
138 - $settings->store();
139 - }
140 -
141 - /**
142 - * If we fail to create the database tables, add an inbox notice.
143 - * This informs the user that they need to correct the issue and try again.
144 - *
145 - * @since 6.19
146 - *
147 - * @return void
148 - */
149 - private function check_that_tables_exist() {
150 - // Check the DB that the table $this->forms exists.
67 + public function collation() {
151 68 global $wpdb;
152 - $exists = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $this->forms ) );
153 -
154 - if ( $exists ) {
155 - $inbox = new FrmInbox();
156 - $inbox->dismiss( 'failed-to-create-tables' );
157 - return;
69 + if ( ! $wpdb->has_cap( 'collation' ) ) {
70 + return '';
158 71 }
159 72
160 - $message = array(
161 - 'key' => 'failed-to-create-tables',
162 - '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
164 - 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>',
165 - 'type' => 'error',
166 - );
167 -
168 - $inbox = new FrmInbox();
169 - $inbox->add_message( $message );
73 + return $wpdb->get_charset_collate();
170 74 }
171 75
172 - /**
173 - * @return string
174 - */
175 - public function collation() {
176 - global $wpdb;
177 - return $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : '';
178 - }
179 -
180 - /**
181 - * @return void
182 - */
183 76 private function create_tables() {
184 77 $charset_collate = $this->collation();
185 78 $sql = array();
186 79
@@ -255,110 +148,21 @@
255 148 KEY field_id (field_id),
256 149 KEY item_id (item_id)
257 150 )';
258 151
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 152 foreach ( $sql as $q ) {
277 153 if ( function_exists( 'dbDelta' ) ) {
278 154 dbDelta( $q . $charset_collate . ';' );
279 155 } else {
280 156 global $wpdb;
281 - $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
157 + $wpdb->query( $q . $charset_collate ); // WPCS: unprepared SQL ok.
282 158 }
283 159 unset( $q );
284 160 }
285 -
286 - $this->add_composite_indexes_for_entries();
287 161 }
288 162
289 - /**
290 - * These indexes help optimize database queries for entries.
291 - *
292 - * @since 6.6
293 - * @since 6.16.3 idx_form_id_is_draft was also added to frm_items.
294 - * @since 6.17 idx_form_id_type was also added to frm_fields.
295 - *
296 - * @return void
297 - */
298 - private function add_composite_indexes_for_entries() {
299 - global $wpdb;
300 -
301 - $table_name = "{$wpdb->prefix}frm_items";
302 - $index_name = 'idx_is_draft_created_at';
303 -
304 - if ( ! self::index_exists( $table_name, $index_name ) ) {
305 - $wpdb->query( "CREATE INDEX idx_is_draft_created_at ON `{$wpdb->prefix}frm_items` (is_draft, created_at)" );
306 - }
307 -
308 - $table_name = "{$wpdb->prefix}frm_item_metas";
309 - $index_name = 'idx_field_id_item_id';
310 -
311 - if ( ! self::index_exists( $table_name, $index_name ) ) {
312 - $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" );
313 - }
314 -
315 - $table_name = "{$wpdb->prefix}frm_items";
316 - $index_name = 'idx_form_id_is_draft';
317 -
318 - if ( ! self::index_exists( $table_name, $index_name ) ) {
319 - $wpdb->query( "CREATE INDEX idx_form_id_is_draft ON `{$wpdb->prefix}frm_items` (form_id, is_draft)" );
320 - }
321 -
322 - $table_name = "{$wpdb->prefix}frm_fields";
323 - $index_name = 'idx_form_id_type';
324 -
325 - if ( ! self::index_exists( $table_name, $index_name ) ) {
326 - $wpdb->query( "CREATE INDEX idx_form_id_type ON `{$wpdb->prefix}frm_fields` (form_id, type(30))" );
327 - }
328 - }
329 -
330 - /**
331 - * Check that an index exists in a database table before trying to add it (which results in an error).
332 - *
333 - * @since 6.6
334 - *
335 - * @param string $table_name
336 - * @param string $index_name
337 - *
338 - * @return bool
339 - */
340 - private static function index_exists( $table_name, $index_name ) {
341 - global $wpdb;
342 - $row = $wpdb->get_row(
343 - $wpdb->prepare(
344 - 'SELECT 1 FROM information_schema.statistics
345 - WHERE table_schema = database()
346 - AND table_name = %s
347 - AND index_name = %s
348 - LIMIT 1',
349 - array( $table_name, $index_name )
350 - )
351 - );
352 - return (bool) $row;
353 - }
354 -
355 - /**
356 - * @return void
357 - */
358 163 private function maybe_create_contact_form() {
359 164 $form_exists = FrmForm::get_id_by_key( 'contact-form' );
360 -
361 165 if ( ! $form_exists ) {
362 166 $this->add_default_template();
363 167 }
364 168 }
@@ -366,10 +170,8 @@
366 170 /**
367 171 * Create the default contact form
368 172 *
369 173 * @since 3.06
370 - *
371 - * @return void
372 174 */
373 175 private function add_default_template() {
374 176 if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
375 177 // XML import is not enabled on your server.
@@ -377,9 +179,10 @@
377 179 }
378 180
379 181 $set_err = libxml_use_internal_errors( true );
380 182 $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
381 - $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml';
183 +
184 + $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml';
382 185 FrmXMLHelper::import_xml( $file );
383 186
384 187 libxml_use_internal_errors( $set_err );
385 188 FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
@@ -386,41 +189,32 @@
386 189 }
387 190
388 191 /**
389 192 * @param int|string $old_db_version
390 - *
391 - * @return void
392 193 */
393 194 private function migrate_data( $old_db_version ) {
394 195 if ( ! $old_db_version ) {
395 196 $old_db_version = get_option( 'frm_db_version' );
396 197 }
397 -
398 - if ( str_contains( $old_db_version, '-' ) ) {
198 + if ( strpos( $old_db_version, '-' ) ) {
399 199 $last_upgrade = explode( '-', $old_db_version );
400 - $old_db_version = intval( end( $last_upgrade ) );
200 + $old_db_version = (int) $last_upgrade[1];
401 201 }
402 202
403 203 if ( ! is_numeric( $old_db_version ) ) {
404 - // Bail if we don't know the previous version
204 + // bail if we don't know the previous version
405 205 return;
406 206 }
407 207
408 - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104, 105 );
409 -
208 + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98 );
410 209 foreach ( $migrations as $migration ) {
411 - if ( FrmAppHelper::$db_version < $migration || $old_db_version >= $migration ) {
412 - continue;
210 + if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
211 + $function_name = 'migrate_to_' . $migration;
212 + $this->$function_name();
413 213 }
414 -
415 - $function_name = 'migrate_to_' . $migration;
416 - $this->$function_name();
417 214 }
418 215 }
419 216
420 - /**
421 - * @return bool
422 - */
423 217 public function uninstall() {
424 218 if ( ! current_user_can( 'administrator' ) ) {
425 219 $frm_settings = FrmAppHelper::get_settings();
426 220 wp_die( esc_html( $frm_settings->admin_permission ) );
@@ -427,13 +221,12 @@
427 221 }
428 222
429 223 global $wpdb, $wp_roles;
430 224
431 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
432 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
433 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
434 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
435 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->gated_tokens ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
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.
436 229
437 230 delete_option( 'frm_options' );
438 231 delete_option( 'frm_db_version' );
439 232 delete_option( 'frm_install_running' );
@@ -440,15 +233,13 @@
440 233 delete_option( 'frm_lite_settings_upgrade' );
441 234 delete_option( 'frm-usage-uuid' );
442 235 delete_option( 'frm_inbox' );
443 236 delete_option( 'frmpro_css' );
444 - delete_option( FrmOnboardingWizardController::REDIRECT_STATUS_OPTION );
445 - delete_option( FrmEmailSummaryHelper::$option_name );
237 + delete_option( 'frm_welcome_redirect' );
446 238
447 239 // Delete roles.
448 240 $frm_roles = FrmAppHelper::frm_capabilities();
449 241 $roles = get_editable_roles();
450 -
451 242 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
452 243 foreach ( $roles as $role => $details ) {
453 244 $wp_roles->remove_cap( $role, $frm_role );
454 245 unset( $role, $details );
@@ -456,16 +247,15 @@
456 247 unset( $frm_role, $frm_role_description );
457 248 }
458 249 unset( $roles, $frm_roles );
459 250
460 - // Delete actions, views, and styles
251 + // delete actions, views, and styles
461 252
462 - // Prevent the post deletion from triggering entries to be deleted
253 + // prevent the post deletion from triggering entries to be deleted
463 254 remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
464 255 remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
465 256
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 -
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' ) );
468 258 foreach ( $post_ids as $post_id ) {
469 259 // Delete's each post.
470 260 wp_delete_post( $post_id, true );
471 261 }
@@ -470,15 +260,15 @@
470 260 wp_delete_post( $post_id, true );
471 261 }
472 262 unset( $post_ids );
473 263
474 - // Delete transients
264 + // delete transients
475 265 delete_transient( 'frmpro_css' );
476 266 delete_transient( 'frm_options' );
477 267 delete_transient( 'frmpro_options' );
478 - delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME );
268 + delete_transient( 'frm_activation_redirect' );
479 269
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
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_%' ) );
481 271
482 272 do_action( 'frm_after_uninstall' );
483 273
484 274 return true;
@@ -484,67 +274,11 @@
484 274 return true;
485 275 }
486 276
487 277 /**
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 - * Disables summary email for multisite (not the main site) if recipient setting isn't changed.
520 - *
521 - * @since 6.8
522 - *
523 - * @return void
524 - */
525 - private function migrate_to_101() {
526 - if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) {
527 - return;
528 - }
529 -
530 - $frm_settings = FrmAppHelper::get_settings();
531 -
532 - if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) {
533 - // User changed it.
534 - return;
535 - }
536 -
537 - $frm_settings->summary_emails = 0;
538 - $frm_settings->store();
539 - }
540 -
541 - /**
542 278 * Clear frmpro_css transient.
543 279 *
544 280 * @since 4.10.02
545 - *
546 - * @return void
547 281 */
548 282 private function migrate_to_98() {
549 283 delete_transient( 'frmpro_css' );
550 284 }
@@ -552,10 +286,8 @@
552 286 /**
553 287 * Move default_blank and clear_on_focus to placeholder.
554 288 *
555 289 * @since 4.0
556 - *
557 - * @return void
558 290 */
559 291 private function migrate_to_97() {
560 292 $this->migrate_to_placeholder( 'clear_on_focus' );
561 293 $this->migrate_to_placeholder( 'default_blank' );
@@ -564,12 +296,8 @@
564 296 /**
565 297 * Move clear_on_focus or default_blank to placeholder.
566 298 *
567 299 * @since 4.0
568 - *
569 - * @param string $type Field option key to migrate.
570 - *
571 - * @return void
572 300 */
573 301 private function migrate_to_placeholder( $type = 'clear_on_focus' ) {
574 302 $query = array(
575 303 'field_options like' => '"' . $type . '";s:1:"1";',
@@ -580,10 +308,9 @@
580 308 foreach ( $fields as $field ) {
581 309 FrmAppHelper::unserialize_or_decode( $field->field_options );
582 310 FrmAppHelper::unserialize_or_decode( $field->options );
583 311 $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type );
584 -
585 - if ( ! $update_values ) {
312 + if ( empty( $update_values ) ) {
586 313 continue;
587 314 }
588 315
589 316 FrmField::update( $field->id, $update_values );
@@ -591,18 +318,14 @@
591 318 }
592 319 }
593 320
594 321 /**
595 - * Delete unneeded default templates
322 + * Delete uneeded default templates
596 323 *
597 324 * @since 3.06
598 - *
599 - * @return void
600 325 */
601 326 private function migrate_to_90() {
602 327 $form = FrmForm::getOne( 'contact' );
603 -
604 - // phpcs:ignore Universal.Operators.StrictComparisons
605 328 if ( $form && $form->default_template == 1 ) {
606 329 FrmForm::destroy( 'contact' );
607 330 }
608 331 }
@@ -610,17 +333,16 @@
610 333 /**
611 334 * Reverse migration 17 -- Divide by 9
612 335 *
613 336 * @since 3.0.05
614 - *
615 - * @return void
616 337 */
617 338 private function migrate_to_86() {
339 +
618 340 $fields = $this->get_fields_with_size();
619 341
620 - foreach ( $fields as $f ) {
342 + foreach ( (array) $fields as $f ) {
621 343 FrmAppHelper::unserialize_or_decode( $f->field_options );
622 - $size = $f->field_options['size'];
344 + $size = $f->field_options['size'];
623 345 $this->maybe_convert_migrated_size( $size );
624 346
625 347 if ( $size === $f->field_options['size'] ) {
626 348 continue;
@@ -630,12 +352,11 @@
630 352 FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
631 353 unset( $f );
632 354 }
633 355
634 - // Reverse the extra size changes in widgets
356 + // reverse the extra size changes in widgets
635 357 $widgets = get_option( 'widget_frm_show_form' );
636 -
637 - if ( ! $widgets ) {
358 + if ( empty( $widgets ) ) {
638 359 return;
639 360 }
640 361
641 362 $this->revert_widget_field_size();
@@ -640,11 +361,8 @@
640 361
641 362 $this->revert_widget_field_size();
642 363 }
643 364
644 - /**
645 - * @return array
646 - */
647 365 private function get_fields_with_size() {
648 366 $field_types = array(
649 367 'textarea',
650 368 'text',
@@ -672,20 +390,16 @@
672 390 /**
673 391 * Reverse the extra size changes in widgets
674 392 *
675 393 * @since 3.0.05
676 - *
677 - * @return void
678 394 */
679 395 private function revert_widget_field_size() {
680 396 $widgets = get_option( 'widget_frm_show_form' );
681 -
682 - if ( ! $widgets ) {
397 + if ( empty( $widgets ) ) {
683 398 return;
684 399 }
685 400
686 401 FrmAppHelper::unserialize_or_decode( $widgets );
687 -
688 402 foreach ( $widgets as $k => $widget ) {
689 403 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
690 404 continue;
691 405 }
@@ -691,9 +405,8 @@
691 405 }
692 406
693 407 $this->maybe_convert_migrated_size( $widgets[ $k ]['size'] );
694 408 }
695 -
696 409 update_option( 'widget_frm_show_form', $widgets );
697 410 }
698 411
699 412 /**
@@ -699,28 +412,23 @@
699 412 /**
700 413 * Divide by 9 to reverse the multiplication
701 414 *
702 415 * @since 3.0.05
703 - *
704 - * @param string $size Size string to maybe convert, passed by reference.
705 - *
706 - * @return void
707 416 */
708 417 private function maybe_convert_migrated_size( &$size ) {
709 - $has_px_size = $size && str_contains( $size, 'px' );
710 -
418 + $has_px_size = ! empty( $size ) && strpos( $size, 'px' );
711 419 if ( ! $has_px_size ) {
712 420 return;
713 421 }
714 422
715 423 $int_size = str_replace( 'px', '', $size );
716 -
717 424 if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) {
718 425 return;
719 426 }
720 427
721 428 $pixel_conversion = 9;
722 - $size = round( (int) $int_size / $pixel_conversion );
429 +
430 + $size = round( (int) $int_size / $pixel_conversion );
723 431 }
724 432
725 433 /**
726 434 * Migrate old styling settings. If sites are using the old
@@ -726,22 +434,19 @@
726 434 * Migrate old styling settings. If sites are using the old
727 435 * default 400px field width, switch it to 100%
728 436 *
729 437 * @since 2.0.4
730 - *
731 - * @return void
732 438 */
733 439 private function migrate_to_25() {
734 - // Get the style that was created with the style migration
440 + // get the style that was created with the style migration
735 441 $frm_style = new FrmStyle();
736 442 $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
737 -
738 - if ( ! $styles ) {
443 + if ( empty( $styles ) ) {
739 444 return;
740 445 }
741 446
742 447 foreach ( $styles as $style ) {
743 - if ( $style->post_content['field_width'] === '400px' ) {
448 + if ( $style->post_content['field_width'] == '400px' ) {
744 449 $style->post_content['field_width'] = '100%';
745 450 $frm_style->save( (array) $style );
746 451
747 452 return;
@@ -753,24 +458,19 @@
753 458 * Check if the parent_form_id columns exists.
754 459 * If not, try and add it again
755 460 *
756 461 * @since 2.0.2
757 - *
758 - * @return void
759 462 */
760 463 private function migrate_to_23() {
761 464 global $wpdb;
762 - $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
763 -
764 - if ( ! $exists ) {
765 - $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.
766 468 }
767 469 }
768 470
769 471 /**
770 472 * Change field size from character to pixel -- Multiply by 9
771 - *
772 - * @return void
773 473 */
774 474 private function migrate_to_17() {
775 475 $fields = $this->get_fields_with_size();
776 476
@@ -775,9 +475,8 @@
775 475 $fields = $this->get_fields_with_size();
776 476
777 477 foreach ( $fields as $f ) {
778 478 FrmAppHelper::unserialize_or_decode( $f->field_options );
779 -
780 479 if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
781 480 continue;
782 481 }
783 482
@@ -791,20 +490,16 @@
791 490 }
792 491
793 492 /**
794 493 * Change the characters in widgets to pixels
795 - *
796 - * @return void
797 494 */
798 495 private function adjust_widget_size() {
799 496 $widgets = get_option( 'widget_frm_show_form' );
800 -
801 - if ( ! $widgets ) {
497 + if ( empty( $widgets ) ) {
802 498 return;
803 499 }
804 500
805 501 FrmAppHelper::unserialize_or_decode( $widgets );
806 -
807 502 foreach ( $widgets as $k => $widget ) {
808 503 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
809 504 continue;
810 505 }
@@ -809,21 +504,15 @@
809 504 continue;
810 505 }
811 506 $this->convert_character_to_px( $widgets[ $k ]['size'] );
812 507 }
813 -
814 508 update_option( 'widget_frm_show_form', $widgets );
815 509 }
816 510
817 - /**
818 - * @param string $size
819 - *
820 - * @return void
821 - */
822 511 private function convert_character_to_px( &$size ) {
823 512 $pixel_conversion = 9;
824 513
825 - $size = round( $pixel_conversion * (int) $size );
514 + $size = round( $pixel_conversion * (int) $size );
826 515 $size .= 'px';
827 516 }
828 517
829 518 /**
@@ -862,9 +551,9 @@
862 551 * post_excerpt: message
863 552 */
864 553 foreach ( $forms as $form ) {
865 554 if ( $form->is_template && $form->default_template ) {
866 - // Don't migrate the default templates since the email will be added anyway
555 + // don't migrate the default templates since the email will be added anyway
867 556 continue;
868 557 }
869 558
870 559 // Format form options
@@ -878,9 +567,10 @@
878 567
879 568 private function migrate_to_11() {
880 569 global $wpdb;
881 570
882 - $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
571 + $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
572 +
883 573 $sending = __( 'Sending', 'formidable' );
884 574 $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
885 575 $old_default_html = <<<DEFAULT_HTML
886 576 <div class="frm_submit">
@@ -892,21 +582,18 @@
892 582 unset( $sending, $img );
893 583
894 584 $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
895 585 $draft_link = FrmFormsHelper::get_draft_link();
896 -
897 586 foreach ( $forms as $form ) {
898 587 FrmAppHelper::unserialize_or_decode( $form->options );
899 -
900 - if ( empty( $form->options['submit_html'] ) ) {
588 + if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) {
901 589 continue;
902 590 }
903 591
904 - // phpcs:ignore Universal.Operators.StrictComparisons
905 592 if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
906 593 $form->options['submit_html'] = $new_default_html;
907 594 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
908 - } elseif ( ! str_contains( $form->options['submit_html'], 'save_draft' ) ) {
595 + } elseif ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
909 596 $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
910 597 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
911 598 }
912 599 unset( $form );