PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
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 +113 -428 6.26 → 3.06.06 View file →
@@ -1,42 +1,24 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 class FrmMigrate {
7 -
8 - /**
9 - * @var string
10 - */
11 4 public $fields;
12 -
13 - /**
14 - * @var string
15 - */
16 5 public $forms;
17 -
18 - /**
19 - * @var string
20 - */
21 6 public $entries;
22 -
23 - /**
24 - * @var string
25 - */
26 7 public $entry_metas;
27 8
28 9 public function __construct() {
10 + if ( ! defined( 'ABSPATH' ) ) {
11 + die( 'You are not allowed to call this page directly.' );
12 + }
13 +
29 14 global $wpdb;
30 - $this->fields = $wpdb->prefix . 'frm_fields';
31 - $this->forms = $wpdb->prefix . 'frm_forms';
32 - $this->entries = $wpdb->prefix . 'frm_items';
33 - $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
15 + $this->fields = $wpdb->prefix . 'frm_fields';
16 + $this->forms = $wpdb->prefix . 'frm_forms';
17 + $this->entries = $wpdb->prefix . 'frm_items';
18 + $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
34 19 }
35 20
36 - /**
37 - * @return void
38 - */
39 21 public function upgrade() {
40 22 do_action( 'frm_before_install' );
41 23
42 24 global $wpdb, $frm_vars;
@@ -54,29 +36,22 @@
54 36 if ( $needs_upgrade ) {
55 37 // update rewrite rules for views and other custom post types
56 38 flush_rewrite_rules();
57 39
58 - require_once ABSPATH . 'wp-admin/includes/upgrade.php';
40 + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
59 41
60 42 $old_db_version = get_option( 'frm_db_version' );
61 43
62 44 $this->create_tables();
63 45 $this->migrate_data( $old_db_version );
64 - $this->check_that_tables_exist();
65 46
66 - // SAVE DB VERSION.
47 + /***** SAVE DB VERSION *****/
67 48 update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version );
68 49
69 50 if ( ! $old_db_version ) {
70 51 $this->maybe_create_contact_form();
71 -
72 - if ( false === get_option( 'frm_first_activation' ) ) {
73 - update_option( 'frm_first_activation', time(), false );
74 - }
75 -
76 - $this->update_settings_for_new_install();
77 52 }
78 - }//end if
53 + }
79 54
80 55 do_action( 'frm_after_install' );
81 56
82 57 $frm_vars['doing_upgrade'] = false;
@@ -89,60 +64,10 @@
89 64 $frm_style->update( 'default' );
90 65 }
91 66 }
92 67
93 - /**
94 - * Updates some settings for new installs.
95 - *
96 - * @since 6.23
97 - *
98 - * @return void
99 - */
100 - private function update_settings_for_new_install() {
101 - $settings = FrmAppHelper::get_settings();
102 -
103 - $settings->denylist_check = 1;
104 - $settings->installed_after_welcome_tour_update = 1;
105 - $settings->store();
106 - }
107 -
108 - /**
109 - * If we fail to create the database tables, add an inbox notice.
110 - * This informs the user that they need to correct the issue and try again.
111 - *
112 - * @since 6.19
113 - *
114 - * @return void
115 - */
116 - private function check_that_tables_exist() {
117 - // Check the DB that the table $this->forms exists.
118 - global $wpdb;
119 - $exists = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $this->forms ) );
120 -
121 - if ( $exists ) {
122 - $inbox = new FrmInbox();
123 - $inbox->dismiss( 'failed-to-create-tables' );
124 - return;
125 - }
126 -
127 - $message = array(
128 - 'key' => 'failed-to-create-tables',
129 - 'subject' => 'Something went wrong setting up the database',
130 - '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.',
131 - 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>',
132 - 'type' => 'error',
133 - );
134 -
135 - $inbox = new FrmInbox();
136 - $inbox->add_message( $message );
137 - }
138 -
139 - /**
140 - * @return string
141 - */
142 68 public function collation() {
143 69 global $wpdb;
144 -
145 70 if ( ! $wpdb->has_cap( 'collation' ) ) {
146 71 return '';
147 72 }
148 73
@@ -148,16 +73,13 @@
148 73
149 74 return $wpdb->get_charset_collate();
150 75 }
151 76
152 - /**
153 - * @return void
154 - */
155 - private function create_tables() {
156 - $charset_collate = $this->collation();
157 - $sql = array();
77 + private function create_tables() {
78 + $charset_collate = $this->collation();
79 + $sql = array();
158 80
159 - /* Create/Upgrade Fields Table */
81 + /* Create/Upgrade Fields Table */
160 82 $sql[] = 'CREATE TABLE ' . $this->fields . ' (
161 83 id BIGINT(20) NOT NULL auto_increment,
162 84 field_key varchar(100) default NULL,
163 85 name text default NULL,
@@ -174,9 +96,9 @@
174 96 KEY form_id (form_id),
175 97 UNIQUE KEY field_key (field_key)
176 98 )';
177 99
178 - /* Create/Upgrade Forms Table */
100 + /* Create/Upgrade Forms Table */
179 101 $sql[] = 'CREATE TABLE ' . $this->forms . ' (
180 102 id int(11) NOT NULL auto_increment,
181 103 form_key varchar(100) default NULL,
182 104 name varchar(255) default NULL,
@@ -192,9 +114,9 @@
192 114 PRIMARY KEY (id),
193 115 UNIQUE KEY form_key (form_key)
194 116 )';
195 117
196 - /* Create/Upgrade Items Table */
118 + /* Create/Upgrade Items Table */
197 119 $sql[] = 'CREATE TABLE ' . $this->entries . ' (
198 120 id BIGINT(20) NOT NULL auto_increment,
199 121 item_key varchar(100) default NULL,
200 122 name varchar(255) default NULL,
@@ -215,9 +137,9 @@
215 137 KEY parent_item_id (parent_item_id),
216 138 UNIQUE KEY item_key (item_key)
217 139 )';
218 140
219 - /* Create/Upgrade Meta Table */
141 + /* Create/Upgrade Meta Table */
220 142 $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
221 143 id BIGINT(20) NOT NULL auto_increment,
222 144 meta_value longtext default NULL,
223 145 field_id BIGINT(20) NOT NULL,
@@ -227,93 +149,21 @@
227 149 KEY field_id (field_id),
228 150 KEY item_id (item_id)
229 151 )';
230 152
231 - foreach ( $sql as $q ) {
153 + foreach ( $sql as $q ) {
232 154 if ( function_exists( 'dbDelta' ) ) {
233 155 dbDelta( $q . $charset_collate . ';' );
234 156 } else {
235 157 global $wpdb;
236 - $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
158 + $wpdb->query( $q . $charset_collate ); // WPCS: unprepared SQL ok.
237 159 }
238 160 unset( $q );
239 - }
161 + }
162 + }
240 163
241 - $this->add_composite_indexes_for_entries();
242 - }
243 -
244 - /**
245 - * These indexes help optimize database queries for entries.
246 - *
247 - * @since 6.6
248 - * @since 6.16.3 idx_form_id_is_draft was also added to frm_items.
249 - * @since 6.17 idx_form_id_type was also added to frm_fields.
250 - *
251 - * @return void
252 - */
253 - private function add_composite_indexes_for_entries() {
254 - global $wpdb;
255 -
256 - $table_name = "{$wpdb->prefix}frm_items";
257 - $index_name = 'idx_is_draft_created_at';
258 -
259 - if ( ! self::index_exists( $table_name, $index_name ) ) {
260 - $wpdb->query( "CREATE INDEX idx_is_draft_created_at ON `{$wpdb->prefix}frm_items` (is_draft, created_at)" );
261 - }
262 -
263 - $table_name = "{$wpdb->prefix}frm_item_metas";
264 - $index_name = 'idx_field_id_item_id';
265 -
266 - if ( ! self::index_exists( $table_name, $index_name ) ) {
267 - $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" );
268 - }
269 -
270 - $table_name = "{$wpdb->prefix}frm_items";
271 - $index_name = 'idx_form_id_is_draft';
272 -
273 - if ( ! self::index_exists( $table_name, $index_name ) ) {
274 - $wpdb->query( "CREATE INDEX idx_form_id_is_draft ON `{$wpdb->prefix}frm_items` (form_id, is_draft)" );
275 - }
276 -
277 - $table_name = "{$wpdb->prefix}frm_fields";
278 - $index_name = 'idx_form_id_type';
279 -
280 - if ( ! self::index_exists( $table_name, $index_name ) ) {
281 - $wpdb->query( "CREATE INDEX idx_form_id_type ON `{$wpdb->prefix}frm_fields` (form_id, type(30))" );
282 - }
283 - }
284 -
285 - /**
286 - * Check that an index exists in a database table before trying to add it (which results in an error).
287 - *
288 - * @since 6.6
289 - *
290 - * @param string $table_name
291 - * @param string $index_name
292 - *
293 - * @return bool
294 - */
295 - private static function index_exists( $table_name, $index_name ) {
296 - global $wpdb;
297 - $row = $wpdb->get_row(
298 - $wpdb->prepare(
299 - 'SELECT 1 FROM information_schema.statistics
300 - WHERE table_schema = database()
301 - AND table_name = %s
302 - AND index_name = %s
303 - LIMIT 1',
304 - array( $table_name, $index_name )
305 - )
306 - );
307 - return (bool) $row;
308 - }
309 -
310 - /**
311 - * @return void
312 - */
313 164 private function maybe_create_contact_form() {
314 165 $form_exists = FrmForm::get_id_by_key( 'contact-form' );
315 -
316 166 if ( ! $form_exists ) {
317 167 $this->add_default_template();
318 168 }
319 169 }
@@ -321,39 +171,34 @@
321 171 /**
322 172 * Create the default contact form
323 173 *
324 174 * @since 3.06
325 - *
326 - * @return void
327 175 */
328 176 private function add_default_template() {
329 - if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
177 + if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
330 178 // XML import is not enabled on your server.
331 179 return;
332 180 }
333 181
334 182 $set_err = libxml_use_internal_errors( true );
335 - $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
183 + $loader = libxml_disable_entity_loader( true );
336 184
337 185 $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml';
338 186 FrmXMLHelper::import_xml( $file );
339 187
340 188 libxml_use_internal_errors( $set_err );
341 - FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
189 + libxml_disable_entity_loader( $loader );
342 190 }
343 191
344 192 /**
345 193 * @param int|string $old_db_version
346 - *
347 - * @return void
348 194 */
349 195 private function migrate_data( $old_db_version ) {
350 196 if ( ! $old_db_version ) {
351 197 $old_db_version = get_option( 'frm_db_version' );
352 198 }
353 -
354 199 if ( strpos( $old_db_version, '-' ) ) {
355 - $last_upgrade = explode( '-', $old_db_version );
200 + $last_upgrade = explode( '-', $old_db_version );
356 201 $old_db_version = (int) $last_upgrade[1];
357 202 }
358 203
359 204 if ( ! is_numeric( $old_db_version ) ) {
@@ -360,10 +205,9 @@
360 205 // bail if we don't know the previous version
361 206 return;
362 207 }
363 208
364 - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 );
365 -
209 + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90 );
366 210 foreach ( $migrations as $migration ) {
367 211 if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
368 212 $function_name = 'migrate_to_' . $migration;
369 213 $this->$function_name();
@@ -370,20 +214,20 @@
370 214 }
371 215 }
372 216 }
373 217
374 - public function uninstall() {
218 + public function uninstall() {
375 219 if ( ! current_user_can( 'administrator' ) ) {
376 - $frm_settings = FrmAppHelper::get_settings();
220 + $frm_settings = FrmAppHelper::get_settings();
377 221 wp_die( esc_html( $frm_settings->admin_permission ) );
378 - }
222 + }
379 223
380 - global $wpdb, $wp_roles;
224 + global $wpdb, $wp_roles;
381 225
382 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
383 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
384 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
385 - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
226 + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // WPCS: unprepared SQL ok.
227 + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // WPCS: unprepared SQL ok.
228 + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // WPCS: unprepared SQL ok.
229 + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); // WPCS: unprepared SQL ok.
386 230
387 231 delete_option( 'frm_options' );
388 232 delete_option( 'frm_db_version' );
389 233 delete_option( 'frm_install_running' );
@@ -388,20 +232,15 @@
388 232 delete_option( 'frm_db_version' );
389 233 delete_option( 'frm_install_running' );
390 234 delete_option( 'frm_lite_settings_upgrade' );
391 235 delete_option( 'frm-usage-uuid' );
392 - delete_option( 'frm_inbox' );
393 - delete_option( 'frmpro_css' );
394 - delete_option( FrmOnboardingWizardController::REDIRECT_STATUS_OPTION );
395 - delete_option( FrmEmailSummaryHelper::$option_name );
396 236
397 - // Delete roles.
398 - $frm_roles = FrmAppHelper::frm_capabilities();
399 - $roles = get_editable_roles();
400 -
401 - foreach ( $frm_roles as $frm_role => $frm_role_description ) {
402 - foreach ( $roles as $role => $details ) {
403 - $wp_roles->remove_cap( $role, $frm_role );
237 + //delete roles
238 + $frm_roles = FrmAppHelper::frm_capabilities();
239 + $roles = get_editable_roles();
240 + foreach ( $frm_roles as $frm_role => $frm_role_description ) {
241 + foreach ( $roles as $role => $details ) {
242 + $wp_roles->remove_cap( $role, $frm_role );
404 243 unset( $role, $details );
405 244 }
406 245 unset( $frm_role, $frm_role_description );
407 246 }
@@ -413,9 +252,8 @@
413 252 remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
414 253 remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
415 254
416 255 $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' ) );
417 -
418 256 foreach ( $post_ids as $post_id ) {
419 257 // Delete's each post.
420 258 wp_delete_post( $post_id, true );
421 259 }
@@ -424,121 +262,22 @@
424 262 // delete transients
425 263 delete_transient( 'frmpro_css' );
426 264 delete_transient( 'frm_options' );
427 265 delete_transient( 'frmpro_options' );
428 - delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME );
429 266
430 267 $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_%' ) );
431 268
432 269 do_action( 'frm_after_uninstall' );
270 + return true;
271 + }
433 272
434 - return true;
435 - }
436 -
437 273 /**
438 - * In older versions of Lite, it's possible we've saved the wrong location ID.
439 - * So force it to get valid values again.
274 + * Delete uneeded default templates
440 275 *
441 - * @since 6.25
442 - *
443 - * @return void
444 - */
445 - private function migrate_to_104() {
446 - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'test' ) ) {
447 - FrmSquareLiteConnectHelper::get_location_id( true, 'test' );
448 - }
449 -
450 - if ( FrmSquareLiteConnectHelper::get_merchant_id( 'live' ) ) {
451 - FrmSquareLiteConnectHelper::get_location_id( true, 'live' );
452 - }
453 - }
454 -
455 - /**
456 - * Disables summary email for multisite (not the main site) if recipient setting isn't changed.
457 - *
458 - * @since 6.8
459 - *
460 - * @return void
461 - */
462 - private function migrate_to_101() {
463 - if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) {
464 - return;
465 - }
466 -
467 - $frm_settings = FrmAppHelper::get_settings();
468 -
469 - if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) {
470 - // User changed it.
471 - return;
472 - }
473 -
474 - $frm_settings->summary_emails = 0;
475 - $frm_settings->store();
476 - }
477 -
478 - /**
479 - * Clear frmpro_css transient.
480 - *
481 - * @since 4.10.02
482 - *
483 - * @return void
484 - */
485 - private function migrate_to_98() {
486 - delete_transient( 'frmpro_css' );
487 - }
488 -
489 - /**
490 - * Move default_blank and clear_on_focus to placeholder.
491 - *
492 - * @since 4.0
493 - *
494 - * @return void
495 - */
496 - private function migrate_to_97() {
497 - $this->migrate_to_placeholder( 'clear_on_focus' );
498 - $this->migrate_to_placeholder( 'default_blank' );
499 - }
500 -
501 - /**
502 - * Move clear_on_focus or default_blank to placeholder.
503 - *
504 - * @since 4.0
505 - *
506 - * @param string $type Field option key to migrate.
507 - *
508 - * @return void
509 - */
510 - private function migrate_to_placeholder( $type = 'clear_on_focus' ) {
511 - $query = array(
512 - 'field_options like' => '"' . $type . '";s:1:"1";',
513 - );
514 -
515 - $fields = FrmDb::get_results( $this->fields, $query, 'id, default_value, field_options, options' );
516 -
517 - foreach ( $fields as $field ) {
518 - FrmAppHelper::unserialize_or_decode( $field->field_options );
519 - FrmAppHelper::unserialize_or_decode( $field->options );
520 - $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type );
521 -
522 - if ( empty( $update_values ) ) {
523 - continue;
524 - }
525 -
526 - FrmField::update( $field->id, $update_values );
527 - unset( $field );
528 - }
529 - }
530 -
531 - /**
532 - * Delete unneeded default templates
533 - *
534 276 * @since 3.06
535 - *
536 - * @return void
537 277 */
538 278 private function migrate_to_90() {
539 279 $form = FrmForm::getOne( 'contact' );
540 -
541 280 if ( $form && $form->default_template == 1 ) {
542 281 FrmForm::destroy( 'contact' );
543 282 }
544 283 }
@@ -546,17 +285,15 @@
546 285 /**
547 286 * Reverse migration 17 -- Divide by 9
548 287 *
549 288 * @since 3.0.05
550 - *
551 - * @return void
552 289 */
553 290 private function migrate_to_86() {
554 291
555 292 $fields = $this->get_fields_with_size();
556 293
557 - foreach ( $fields as $f ) {
558 - FrmAppHelper::unserialize_or_decode( $f->field_options );
294 + foreach ( (array) $fields as $f ) {
295 + $f->field_options = maybe_unserialize( $f->field_options );
559 296 $size = $f->field_options['size'];
560 297 $this->maybe_convert_migrated_size( $size );
561 298
562 299 if ( $size === $f->field_options['size'] ) {
@@ -569,9 +306,8 @@
569 306 }
570 307
571 308 // reverse the extra size changes in widgets
572 309 $widgets = get_option( 'widget_frm_show_form' );
573 -
574 310 if ( empty( $widgets ) ) {
575 311 return;
576 312 }
577 313
@@ -577,30 +313,13 @@
577 313
578 314 $this->revert_widget_field_size();
579 315 }
580 316
581 - /**
582 - * @return array
583 - */
584 317 private function get_fields_with_size() {
585 - $field_types = array(
586 - 'textarea',
587 - 'text',
588 - 'number',
589 - 'email',
590 - 'url',
591 - 'rte',
592 - 'date',
593 - 'phone',
594 - 'password',
595 - 'image',
596 - 'tag',
597 - 'file',
598 - );
599 -
318 + $field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
600 319 $query = array(
601 - 'type' => $field_types,
602 - 'field_options like' => 's:4:"size";',
320 + 'type' => $field_types,
321 + 'field_options like' => 's:4:"size";',
603 322 'field_options not like' => 's:4:"size";s:0:',
604 323 );
605 324
606 325 return FrmDb::get_results( $this->fields, $query, 'id, field_options' );
@@ -609,20 +328,16 @@
609 328 /**
610 329 * Reverse the extra size changes in widgets
611 330 *
612 331 * @since 3.0.05
613 - *
614 - * @return void
615 332 */
616 333 private function revert_widget_field_size() {
617 334 $widgets = get_option( 'widget_frm_show_form' );
618 -
619 335 if ( empty( $widgets ) ) {
620 336 return;
621 337 }
622 338
623 - FrmAppHelper::unserialize_or_decode( $widgets );
624 -
339 + $widgets = maybe_unserialize( $widgets );
625 340 foreach ( $widgets as $k => $widget ) {
626 341 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
627 342 continue;
628 343 }
@@ -635,28 +350,21 @@
635 350 /**
636 351 * Divide by 9 to reverse the multiplication
637 352 *
638 353 * @since 3.0.05
639 - *
640 - * @param string $size Size string to maybe convert, passed by reference.
641 - *
642 - * @return void
643 354 */
644 355 private function maybe_convert_migrated_size( &$size ) {
645 356 $has_px_size = ! empty( $size ) && strpos( $size, 'px' );
646 -
647 357 if ( ! $has_px_size ) {
648 358 return;
649 359 }
650 360
651 361 $int_size = str_replace( 'px', '', $size );
652 -
653 362 if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) {
654 363 return;
655 364 }
656 365
657 366 $pixel_conversion = 9;
658 -
659 367 $size = round( (int) $int_size / $pixel_conversion );
660 368 }
661 369
662 370 /**
@@ -663,25 +371,21 @@
663 371 * Migrate old styling settings. If sites are using the old
664 372 * default 400px field width, switch it to 100%
665 373 *
666 374 * @since 2.0.4
667 - *
668 - * @return void
669 375 */
670 376 private function migrate_to_25() {
671 377 // get the style that was created with the style migration
672 378 $frm_style = new FrmStyle();
673 - $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
674 -
379 + $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
675 380 if ( empty( $styles ) ) {
676 381 return;
677 382 }
678 383
679 384 foreach ( $styles as $style ) {
680 - if ( $style->post_content['field_width'] === '400px' ) {
385 + if ( $style->post_content['field_width'] == '400px' ) {
681 386 $style->post_content['field_width'] = '100%';
682 387 $frm_style->save( (array) $style );
683 -
684 388 return;
685 389 }
686 390 }
687 391 }
@@ -690,31 +394,25 @@
690 394 * Check if the parent_form_id columns exists.
691 395 * If not, try and add it again
692 396 *
693 397 * @since 2.0.2
694 - *
695 - * @return void
696 398 */
697 399 private function migrate_to_23() {
698 400 global $wpdb;
699 - $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
700 -
401 + $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // WPCS: unprepared SQL ok.
701 402 if ( empty( $exists ) ) {
702 - $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
403 + $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // WPCS: unprepared SQL ok.
703 404 }
704 405 }
705 406
706 407 /**
707 408 * Change field size from character to pixel -- Multiply by 9
708 - *
709 - * @return void
710 409 */
711 410 private function migrate_to_17() {
712 411 $fields = $this->get_fields_with_size();
713 412
714 413 foreach ( $fields as $f ) {
715 - FrmAppHelper::unserialize_or_decode( $f->field_options );
716 -
414 + $f->field_options = maybe_unserialize( $f->field_options );
717 415 if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
718 416 continue;
719 417 }
720 418
@@ -728,20 +426,16 @@
728 426 }
729 427
730 428 /**
731 429 * Change the characters in widgets to pixels
732 - *
733 - * @return void
734 430 */
735 431 private function adjust_widget_size() {
736 432 $widgets = get_option( 'widget_frm_show_form' );
737 -
738 433 if ( empty( $widgets ) ) {
739 434 return;
740 435 }
741 436
742 - FrmAppHelper::unserialize_or_decode( $widgets );
743 -
437 + $widgets = maybe_unserialize( $widgets );
744 438 foreach ( $widgets as $k => $widget ) {
745 439 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
746 440 continue;
747 441 }
@@ -749,56 +443,50 @@
749 443 }
750 444 update_option( 'widget_frm_show_form', $widgets );
751 445 }
752 446
753 - /**
754 - * @param string $size
755 - *
756 - * @return void
757 - */
758 447 private function convert_character_to_px( &$size ) {
759 448 $pixel_conversion = 9;
760 -
761 - $size = round( $pixel_conversion * (int) $size );
449 + $size = round( $pixel_conversion * (int) $size );
762 450 $size .= 'px';
763 451 }
764 452
765 - /**
766 - * Migrate post and email notification settings into actions
767 - */
768 - private function migrate_to_16() {
769 - $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
453 + /**
454 + * Migrate post and email notification settings into actions
455 + */
456 + private function migrate_to_16() {
457 + $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
770 458
771 - /**
772 - * Old email settings format:
773 - * email_to: Email or field id
774 - * also_email_to: array of fields ids
775 - * reply_to: Email, field id, 'custom'
776 - * cust_reply_to: string
777 - * reply_to_name: field id, 'custom'
778 - * cust_reply_to_name: string
779 - * plain_text: 0|1
780 - * email_message: string or ''
781 - * email_subject: string or ''
782 - * inc_user_info: 0|1
783 - * update_email: 0, 1, 2
784 - *
785 - * Old autoresponder settings format:
786 - * auto_responder: 0|1
787 - * ar_email_message: string or ''
788 - * ar_email_to: field id
789 - * ar_plain_text: 0|1
790 - * ar_reply_to_name: string
791 - * ar_reply_to: string
792 - * ar_email_subject: string
793 - * ar_update_email: 0, 1, 2
794 - *
795 - * New email settings:
796 - * post_content: json settings
797 - * post_title: form id
798 - * post_excerpt: message
799 - */
800 - foreach ( $forms as $form ) {
459 + /**
460 + * Old email settings format:
461 + * email_to: Email or field id
462 + * also_email_to: array of fields ids
463 + * reply_to: Email, field id, 'custom'
464 + * cust_reply_to: string
465 + * reply_to_name: field id, 'custom'
466 + * cust_reply_to_name: string
467 + * plain_text: 0|1
468 + * email_message: string or ''
469 + * email_subject: string or ''
470 + * inc_user_info: 0|1
471 + * update_email: 0, 1, 2
472 + *
473 + * Old autoresponder settings format:
474 + * auto_responder: 0|1
475 + * ar_email_message: string or ''
476 + * ar_email_to: field id
477 + * ar_plain_text: 0|1
478 + * ar_reply_to_name: string
479 + * ar_reply_to: string
480 + * ar_email_subject: string
481 + * ar_update_email: 0, 1, 2
482 + *
483 + * New email settings:
484 + * post_content: json settings
485 + * post_title: form id
486 + * post_excerpt: message
487 + */
488 + foreach ( $forms as $form ) {
801 489 if ( $form->is_template && $form->default_template ) {
802 490 // don't migrate the default templates since the email will be added anyway
803 491 continue;
804 492 }
@@ -803,24 +491,23 @@
803 491 continue;
804 492 }
805 493
806 494 // Format form options
807 - $form_options = $form->options;
808 - FrmAppHelper::unserialize_or_decode( $form_options );
495 + $form_options = maybe_unserialize( $form->options );
809 496
810 - // Migrate settings to actions
811 - FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
812 - }
813 - }
497 + // Migrate settings to actions
498 + FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
499 + }
500 + }
814 501
815 - private function migrate_to_11() {
816 - global $wpdb;
502 + private function migrate_to_11() {
503 + global $wpdb;
817 504
818 505 $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
819 506
820 - $sending = __( 'Sending', 'formidable' );
821 - $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
822 - $old_default_html = <<<DEFAULT_HTML
507 + $sending = __( 'Sending', 'formidable' );
508 + $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
509 + $old_default_html = <<<DEFAULT_HTML
823 510 <div class="frm_submit">
824 511 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
825 512 <input type="submit" value="[button_label]" [button_action] />
826 513 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
@@ -828,24 +515,22 @@
828 515 DEFAULT_HTML;
829 516 unset( $sending, $img );
830 517
831 518 $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
832 - $draft_link = FrmFormsHelper::get_draft_link();
833 -
519 + $draft_link = FrmFormsHelper::get_draft_link();
834 520 foreach ( $forms as $form ) {
835 - FrmAppHelper::unserialize_or_decode( $form->options );
521 + $form->options = maybe_unserialize( $form->options );
522 + if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) {
523 + continue;
524 + }
836 525
837 - if ( empty( $form->options['submit_html'] ) ) {
838 - continue;
839 - }
840 -
841 - if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
842 - $form->options['submit_html'] = $new_default_html;
526 + if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
527 + $form->options['submit_html'] = $new_default_html;
843 528 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
844 - } elseif ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
529 + } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
845 530 $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
846 531 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
847 - }
532 + }
848 533 unset( $form );
849 - }
850 - }
534 + }
535 + }
851 536 }