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 +148 -503 6.32 → 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;
@@ -51,34 +33,25 @@
51 33 )
52 34 );
53 35
54 36 if ( $needs_upgrade ) {
55 - $this->maybe_delete_htaccess_file();
56 -
57 - // Update rewrite rules for views and other custom post types
37 + // update rewrite rules for views and other custom post types
58 38 flush_rewrite_rules();
59 39
60 - require_once ABSPATH . 'wp-admin/includes/upgrade.php';
40 + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
61 41
62 42 $old_db_version = get_option( 'frm_db_version' );
63 43
64 44 $this->create_tables();
65 45 $this->migrate_data( $old_db_version );
66 - $this->check_that_tables_exist();
67 46
68 - // SAVE DB VERSION.
47 + /***** SAVE DB VERSION *****/
69 48 update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version );
70 49
71 50 if ( ! $old_db_version ) {
72 51 $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 52 }
80 - }//end if
53 + }
81 54
82 55 do_action( 'frm_after_install' );
83 56
84 57 $frm_vars['doing_upgrade'] = false;
@@ -84,102 +57,29 @@
84 57 $frm_vars['doing_upgrade'] = false;
85 58
86 59 FrmAppHelper::save_combined_js();
87 60
88 - // Update the styling settings
89 - if ( ! function_exists( 'get_filesystem_method' ) ) {
90 - return;
61 + // update the styling settings
62 + if ( function_exists( 'get_filesystem_method' ) ) {
63 + $frm_style = new FrmStyle();
64 + $frm_style->update( 'default' );
91 65 }
92 -
93 - $frm_style = new FrmStyle();
94 - $frm_style->update( 'default' );
95 66 }
96 67
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.
68 + public function collation() {
145 69 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;
70 + if ( ! $wpdb->has_cap( 'collation' ) ) {
71 + return '';
152 72 }
153 73
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 );
74 + return $wpdb->get_charset_collate();
164 75 }
165 76
166 - /**
167 - * @return string
168 - */
169 - public function collation() {
170 - global $wpdb;
171 - return $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : '';
172 - }
77 + private function create_tables() {
78 + $charset_collate = $this->collation();
79 + $sql = array();
173 80
174 - /**
175 - * @return void
176 - */
177 - private function create_tables() {
178 - $charset_collate = $this->collation();
179 - $sql = array();
180 -
181 - /* Create/Upgrade Fields Table */
81 + /* Create/Upgrade Fields Table */
182 82 $sql[] = 'CREATE TABLE ' . $this->fields . ' (
183 83 id BIGINT(20) NOT NULL auto_increment,
184 84 field_key varchar(100) default NULL,
185 85 name text default NULL,
@@ -196,9 +96,9 @@
196 96 KEY form_id (form_id),
197 97 UNIQUE KEY field_key (field_key)
198 98 )';
199 99
200 - /* Create/Upgrade Forms Table */
100 + /* Create/Upgrade Forms Table */
201 101 $sql[] = 'CREATE TABLE ' . $this->forms . ' (
202 102 id int(11) NOT NULL auto_increment,
203 103 form_key varchar(100) default NULL,
204 104 name varchar(255) default NULL,
@@ -214,9 +114,9 @@
214 114 PRIMARY KEY (id),
215 115 UNIQUE KEY form_key (form_key)
216 116 )';
217 117
218 - /* Create/Upgrade Items Table */
118 + /* Create/Upgrade Items Table */
219 119 $sql[] = 'CREATE TABLE ' . $this->entries . ' (
220 120 id BIGINT(20) NOT NULL auto_increment,
221 121 item_key varchar(100) default NULL,
222 122 name varchar(255) default NULL,
@@ -237,9 +137,9 @@
237 137 KEY parent_item_id (parent_item_id),
238 138 UNIQUE KEY item_key (item_key)
239 139 )';
240 140
241 - /* Create/Upgrade Meta Table */
141 + /* Create/Upgrade Meta Table */
242 142 $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
243 143 id BIGINT(20) NOT NULL auto_increment,
244 144 meta_value longtext default NULL,
245 145 field_id BIGINT(20) NOT NULL,
@@ -249,93 +149,21 @@
249 149 KEY field_id (field_id),
250 150 KEY item_id (item_id)
251 151 )';
252 152
253 - foreach ( $sql as $q ) {
153 + foreach ( $sql as $q ) {
254 154 if ( function_exists( 'dbDelta' ) ) {
255 155 dbDelta( $q . $charset_collate . ';' );
256 156 } else {
257 157 global $wpdb;
258 - $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
158 + $wpdb->query( $q . $charset_collate ); // WPCS: unprepared SQL ok.
259 159 }
260 160 unset( $q );
261 - }
161 + }
162 + }
262 163
263 - $this->add_composite_indexes_for_entries();
264 - }
265 -
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 164 private function maybe_create_contact_form() {
336 165 $form_exists = FrmForm::get_id_by_key( 'contact-form' );
337 -
338 166 if ( ! $form_exists ) {
339 167 $this->add_default_template();
340 168 }
341 169 }
@@ -343,73 +171,63 @@
343 171 /**
344 172 * Create the default contact form
345 173 *
346 174 * @since 3.06
347 - *
348 - * @return void
349 175 */
350 176 private function add_default_template() {
351 - if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
177 + if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
352 178 // XML import is not enabled on your server.
353 179 return;
354 180 }
355 181
356 182 $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';
183 + $loader = libxml_disable_entity_loader( true );
184 +
185 + $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml';
359 186 FrmXMLHelper::import_xml( $file );
360 187
361 188 libxml_use_internal_errors( $set_err );
362 - FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
189 + libxml_disable_entity_loader( $loader );
363 190 }
364 191
365 192 /**
366 193 * @param int|string $old_db_version
367 - *
368 - * @return void
369 194 */
370 195 private function migrate_data( $old_db_version ) {
371 196 if ( ! $old_db_version ) {
372 197 $old_db_version = get_option( 'frm_db_version' );
373 198 }
374 -
375 - if ( str_contains( $old_db_version, '-' ) ) {
376 - $last_upgrade = explode( '-', $old_db_version );
377 - $old_db_version = intval( end( $last_upgrade ) );
199 + if ( strpos( $old_db_version, '-' ) ) {
200 + $last_upgrade = explode( '-', $old_db_version );
201 + $old_db_version = (int) $last_upgrade[1];
378 202 }
379 203
380 204 if ( ! is_numeric( $old_db_version ) ) {
381 - // Bail if we don't know the previous version
205 + // bail if we don't know the previous version
382 206 return;
383 207 }
384 208
385 - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104, 105 );
386 -
209 + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90 );
387 210 foreach ( $migrations as $migration ) {
388 - if ( FrmAppHelper::$db_version < $migration || $old_db_version >= $migration ) {
389 - continue;
211 + if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
212 + $function_name = 'migrate_to_' . $migration;
213 + $this->$function_name();
390 214 }
391 -
392 - $function_name = 'migrate_to_' . $migration;
393 - $this->$function_name();
394 215 }
395 216 }
396 217
397 - /**
398 - * @return bool
399 - */
400 - public function uninstall() {
218 + public function uninstall() {
401 219 if ( ! current_user_can( 'administrator' ) ) {
402 - $frm_settings = FrmAppHelper::get_settings();
220 + $frm_settings = FrmAppHelper::get_settings();
403 221 wp_die( esc_html( $frm_settings->admin_permission ) );
404 - }
222 + }
405 223
406 - global $wpdb, $wp_roles;
224 + global $wpdb, $wp_roles;
407 225
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
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.
412 230
413 231 delete_option( 'frm_options' );
414 232 delete_option( 'frm_db_version' );
415 233 delete_option( 'frm_install_running' );
@@ -414,20 +232,15 @@
414 232 delete_option( 'frm_db_version' );
415 233 delete_option( 'frm_install_running' );
416 234 delete_option( 'frm_lite_settings_upgrade' );
417 235 delete_option( 'frm-usage-uuid' );
418 - delete_option( 'frm_inbox' );
419 - delete_option( 'frmpro_css' );
420 - delete_option( FrmOnboardingWizardController::REDIRECT_STATUS_OPTION );
421 - delete_option( FrmEmailSummaryHelper::$option_name );
422 236
423 - // Delete roles.
424 - $frm_roles = FrmAppHelper::frm_capabilities();
425 - $roles = get_editable_roles();
426 -
427 - foreach ( $frm_roles as $frm_role => $frm_role_description ) {
428 - foreach ( $roles as $role => $details ) {
429 - $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 );
430 243 unset( $role, $details );
431 244 }
432 245 unset( $frm_role, $frm_role_description );
433 246 }
@@ -432,16 +245,15 @@
432 245 unset( $frm_role, $frm_role_description );
433 246 }
434 247 unset( $roles, $frm_roles );
435 248
436 - // Delete actions, views, and styles
249 + // delete actions, views, and styles
437 250
438 - // Prevent the post deletion from triggering entries to be deleted
251 + // prevent the post deletion from triggering entries to be deleted
439 252 remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
440 253 remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
441 254
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 -
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' ) );
444 256 foreach ( $post_ids as $post_id ) {
445 257 // Delete's each post.
446 258 wp_delete_post( $post_id, true );
447 259 }
@@ -446,139 +258,26 @@
446 258 wp_delete_post( $post_id, true );
447 259 }
448 260 unset( $post_ids );
449 261
450 - // Delete transients
262 + // delete transients
451 263 delete_transient( 'frmpro_css' );
452 264 delete_transient( 'frm_options' );
453 265 delete_transient( 'frmpro_options' );
454 - delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME );
455 266
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
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_%' ) );
457 268
458 269 do_action( 'frm_after_uninstall' );
270 + return true;
271 + }
459 272
460 - return true;
461 - }
462 -
463 273 /**
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.
274 + * Delete uneeded default templates
466 275 *
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 - * Move default_blank and clear_on_focus to placeholder.
530 - *
531 - * @since 4.0
532 - *
533 - * @return void
534 - */
535 - private function migrate_to_97() {
536 - $this->migrate_to_placeholder( 'clear_on_focus' );
537 - $this->migrate_to_placeholder( 'default_blank' );
538 - }
539 -
540 - /**
541 - * Move clear_on_focus or default_blank to placeholder.
542 - *
543 - * @since 4.0
544 - *
545 - * @param string $type Field option key to migrate.
546 - *
547 - * @return void
548 - */
549 - private function migrate_to_placeholder( $type = 'clear_on_focus' ) {
550 - $query = array(
551 - 'field_options like' => '"' . $type . '";s:1:"1";',
552 - );
553 -
554 - $fields = FrmDb::get_results( $this->fields, $query, 'id, default_value, field_options, options' );
555 -
556 - foreach ( $fields as $field ) {
557 - FrmAppHelper::unserialize_or_decode( $field->field_options );
558 - FrmAppHelper::unserialize_or_decode( $field->options );
559 - $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type );
560 -
561 - if ( ! $update_values ) {
562 - continue;
563 - }
564 -
565 - FrmField::update( $field->id, $update_values );
566 - unset( $field );
567 - }
568 - }
569 -
570 - /**
571 - * Delete unneeded default templates
572 - *
573 276 * @since 3.06
574 - *
575 - * @return void
576 277 */
577 278 private function migrate_to_90() {
578 279 $form = FrmForm::getOne( 'contact' );
579 -
580 - // phpcs:ignore Universal.Operators.StrictComparisons
581 280 if ( $form && $form->default_template == 1 ) {
582 281 FrmForm::destroy( 'contact' );
583 282 }
584 283 }
@@ -586,16 +285,15 @@
586 285 /**
587 286 * Reverse migration 17 -- Divide by 9
588 287 *
589 288 * @since 3.0.05
590 - *
591 - * @return void
592 289 */
593 290 private function migrate_to_86() {
291 +
594 292 $fields = $this->get_fields_with_size();
595 293
596 - foreach ( $fields as $f ) {
597 - FrmAppHelper::unserialize_or_decode( $f->field_options );
294 + foreach ( (array) $fields as $f ) {
295 + $f->field_options = maybe_unserialize( $f->field_options );
598 296 $size = $f->field_options['size'];
599 297 $this->maybe_convert_migrated_size( $size );
600 298
601 299 if ( $size === $f->field_options['size'] ) {
@@ -606,12 +304,11 @@
606 304 FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
607 305 unset( $f );
608 306 }
609 307
610 - // Reverse the extra size changes in widgets
308 + // reverse the extra size changes in widgets
611 309 $widgets = get_option( 'widget_frm_show_form' );
612 -
613 - if ( ! $widgets ) {
310 + if ( empty( $widgets ) ) {
614 311 return;
615 312 }
616 313
617 314 $this->revert_widget_field_size();
@@ -616,30 +313,13 @@
616 313
617 314 $this->revert_widget_field_size();
618 315 }
619 316
620 - /**
621 - * @return array
622 - */
623 317 private function get_fields_with_size() {
624 - $field_types = array(
625 - 'textarea',
626 - 'text',
627 - 'number',
628 - 'email',
629 - 'url',
630 - 'rte',
631 - 'date',
632 - 'phone',
633 - 'password',
634 - 'image',
635 - 'tag',
636 - 'file',
637 - );
638 -
318 + $field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
639 319 $query = array(
640 - 'type' => $field_types,
641 - 'field_options like' => 's:4:"size";',
320 + 'type' => $field_types,
321 + 'field_options like' => 's:4:"size";',
642 322 'field_options not like' => 's:4:"size";s:0:',
643 323 );
644 324
645 325 return FrmDb::get_results( $this->fields, $query, 'id, field_options' );
@@ -648,20 +328,16 @@
648 328 /**
649 329 * Reverse the extra size changes in widgets
650 330 *
651 331 * @since 3.0.05
652 - *
653 - * @return void
654 332 */
655 333 private function revert_widget_field_size() {
656 334 $widgets = get_option( 'widget_frm_show_form' );
657 -
658 - if ( ! $widgets ) {
335 + if ( empty( $widgets ) ) {
659 336 return;
660 337 }
661 338
662 - FrmAppHelper::unserialize_or_decode( $widgets );
663 -
339 + $widgets = maybe_unserialize( $widgets );
664 340 foreach ( $widgets as $k => $widget ) {
665 341 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
666 342 continue;
667 343 }
@@ -667,9 +343,8 @@
667 343 }
668 344
669 345 $this->maybe_convert_migrated_size( $widgets[ $k ]['size'] );
670 346 }
671 -
672 347 update_option( 'widget_frm_show_form', $widgets );
673 348 }
674 349
675 350 /**
@@ -675,28 +350,22 @@
675 350 /**
676 351 * Divide by 9 to reverse the multiplication
677 352 *
678 353 * @since 3.0.05
679 - *
680 - * @param string $size Size string to maybe convert, passed by reference.
681 - *
682 - * @return void
683 354 */
684 355 private function maybe_convert_migrated_size( &$size ) {
685 - $has_px_size = $size && str_contains( $size, 'px' );
686 -
356 + $has_px_size = ! empty( $size ) && strpos( $size, 'px' );
687 357 if ( ! $has_px_size ) {
688 358 return;
689 359 }
690 360
691 361 $int_size = str_replace( 'px', '', $size );
692 -
693 362 if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) {
694 363 return;
695 364 }
696 365
697 366 $pixel_conversion = 9;
698 - $size = round( (int) $int_size / $pixel_conversion );
367 + $size = round( (int) $int_size / $pixel_conversion );
699 368 }
700 369
701 370 /**
702 371 * Migrate old styling settings. If sites are using the old
@@ -702,25 +371,21 @@
702 371 * Migrate old styling settings. If sites are using the old
703 372 * default 400px field width, switch it to 100%
704 373 *
705 374 * @since 2.0.4
706 - *
707 - * @return void
708 375 */
709 376 private function migrate_to_25() {
710 - // Get the style that was created with the style migration
377 + // get the style that was created with the style migration
711 378 $frm_style = new FrmStyle();
712 - $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
713 -
714 - if ( ! $styles ) {
379 + $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
380 + if ( empty( $styles ) ) {
715 381 return;
716 382 }
717 383
718 384 foreach ( $styles as $style ) {
719 - if ( $style->post_content['field_width'] === '400px' ) {
385 + if ( $style->post_content['field_width'] == '400px' ) {
720 386 $style->post_content['field_width'] = '100%';
721 387 $frm_style->save( (array) $style );
722 -
723 388 return;
724 389 }
725 390 }
726 391 }
@@ -729,31 +394,25 @@
729 394 * Check if the parent_form_id columns exists.
730 395 * If not, try and add it again
731 396 *
732 397 * @since 2.0.2
733 - *
734 - * @return void
735 398 */
736 399 private function migrate_to_23() {
737 400 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
401 + $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // WPCS: unprepared SQL ok.
402 + if ( empty( $exists ) ) {
403 + $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // WPCS: unprepared SQL ok.
742 404 }
743 405 }
744 406
745 407 /**
746 408 * Change field size from character to pixel -- Multiply by 9
747 - *
748 - * @return void
749 409 */
750 410 private function migrate_to_17() {
751 411 $fields = $this->get_fields_with_size();
752 412
753 413 foreach ( $fields as $f ) {
754 - FrmAppHelper::unserialize_or_decode( $f->field_options );
755 -
414 + $f->field_options = maybe_unserialize( $f->field_options );
756 415 if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
757 416 continue;
758 417 }
759 418
@@ -767,20 +426,16 @@
767 426 }
768 427
769 428 /**
770 429 * Change the characters in widgets to pixels
771 - *
772 - * @return void
773 430 */
774 431 private function adjust_widget_size() {
775 432 $widgets = get_option( 'widget_frm_show_form' );
776 -
777 - if ( ! $widgets ) {
433 + if ( empty( $widgets ) ) {
778 434 return;
779 435 }
780 436
781 - FrmAppHelper::unserialize_or_decode( $widgets );
782 -
437 + $widgets = maybe_unserialize( $widgets );
783 438 foreach ( $widgets as $k => $widget ) {
784 439 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
785 440 continue;
786 441 }
@@ -785,81 +440,74 @@
785 440 continue;
786 441 }
787 442 $this->convert_character_to_px( $widgets[ $k ]['size'] );
788 443 }
789 -
790 444 update_option( 'widget_frm_show_form', $widgets );
791 445 }
792 446
793 - /**
794 - * @param string $size
795 - *
796 - * @return void
797 - */
798 447 private function convert_character_to_px( &$size ) {
799 448 $pixel_conversion = 9;
800 -
801 - $size = round( $pixel_conversion * (int) $size );
449 + $size = round( $pixel_conversion * (int) $size );
802 450 $size .= 'px';
803 451 }
804 452
805 - /**
806 - * Migrate post and email notification settings into actions
807 - */
808 - private function migrate_to_16() {
809 - $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' );
810 458
811 - /**
812 - * Old email settings format:
813 - * email_to: Email or field id
814 - * also_email_to: array of fields ids
815 - * reply_to: Email, field id, 'custom'
816 - * cust_reply_to: string
817 - * reply_to_name: field id, 'custom'
818 - * cust_reply_to_name: string
819 - * plain_text: 0|1
820 - * email_message: string or ''
821 - * email_subject: string or ''
822 - * inc_user_info: 0|1
823 - * update_email: 0, 1, 2
824 - *
825 - * Old autoresponder settings format:
826 - * auto_responder: 0|1
827 - * ar_email_message: string or ''
828 - * ar_email_to: field id
829 - * ar_plain_text: 0|1
830 - * ar_reply_to_name: string
831 - * ar_reply_to: string
832 - * ar_email_subject: string
833 - * ar_update_email: 0, 1, 2
834 - *
835 - * New email settings:
836 - * post_content: json settings
837 - * post_title: form id
838 - * post_excerpt: message
839 - */
840 - 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 ) {
841 489 if ( $form->is_template && $form->default_template ) {
842 - // Don't migrate the default templates since the email will be added anyway
490 + // don't migrate the default templates since the email will be added anyway
843 491 continue;
844 492 }
845 493
846 494 // Format form options
847 - $form_options = $form->options;
848 - FrmAppHelper::unserialize_or_decode( $form_options );
495 + $form_options = maybe_unserialize( $form->options );
849 496
850 - // Migrate settings to actions
851 - FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
852 - }
853 - }
497 + // Migrate settings to actions
498 + FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
499 + }
500 + }
854 501
855 - private function migrate_to_11() {
856 - global $wpdb;
502 + private function migrate_to_11() {
503 + global $wpdb;
857 504
858 - $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
859 - $sending = __( 'Sending', 'formidable' );
860 - $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
861 - $old_default_html = <<<DEFAULT_HTML
505 + $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
506 +
507 + $sending = __( 'Sending', 'formidable' );
508 + $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
509 + $old_default_html = <<<DEFAULT_HTML
862 510 <div class="frm_submit">
863 511 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
864 512 <input type="submit" value="[button_label]" [button_action] />
865 513 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
@@ -867,25 +515,22 @@
867 515 DEFAULT_HTML;
868 516 unset( $sending, $img );
869 517
870 518 $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
871 - $draft_link = FrmFormsHelper::get_draft_link();
872 -
519 + $draft_link = FrmFormsHelper::get_draft_link();
873 520 foreach ( $forms as $form ) {
874 - 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 + }
875 525
876 - if ( empty( $form->options['submit_html'] ) ) {
877 - continue;
878 - }
879 -
880 - // phpcs:ignore Universal.Operators.StrictComparisons
881 - if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
882 - $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;
883 528 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
884 - } elseif ( ! str_contains( $form->options['submit_html'], 'save_draft' ) ) {
529 + } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
885 530 $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
886 531 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
887 - }
532 + }
888 533 unset( $form );
889 - }
890 - }
534 + }
535 + }
891 536 }