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