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