PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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 +82 -10 6.36.13 View file →
@@ -35,9 +35,9 @@
35 35 if ( $needs_upgrade ) {
36 36 // update rewrite rules for views and other custom post types
37 37 flush_rewrite_rules();
38 38
39 - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
39 + require_once ABSPATH . 'wp-admin/includes/upgrade.php';
40 40
41 41 $old_db_version = get_option( 'frm_db_version' );
42 42
43 43 $this->create_tables();
@@ -42,9 +42,9 @@
42 42
43 43 $this->create_tables();
44 44 $this->migrate_data( $old_db_version );
45 45
46 - /***** SAVE DB VERSION *****/
46 + // SAVE DB VERSION.
47 47 update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version );
48 48
49 49 if ( ! $old_db_version ) {
50 50 $this->maybe_create_contact_form();
@@ -157,10 +157,61 @@
157 157 $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
158 158 }
159 159 unset( $q );
160 160 }
161 +
162 + $this->add_composite_indexes_for_entries();
161 163 }
162 164
165 + /**
166 + * These indexes help optimize database queries for entries.
167 + *
168 + * @since 6.6
169 + *
170 + * @return void
171 + */
172 + private function add_composite_indexes_for_entries() {
173 + global $wpdb;
174 +
175 + $table_name = "{$wpdb->prefix}frm_items";
176 + $index_name = 'idx_is_draft_created_at';
177 +
178 + if ( ! self::index_exists( $table_name, $index_name ) ) {
179 + $wpdb->query( "CREATE INDEX idx_is_draft_created_at ON `{$wpdb->prefix}frm_items` (is_draft, created_at)" );
180 + }
181 +
182 + $table_name = "{$wpdb->prefix}frm_item_metas";
183 + $index_name = 'idx_field_id_item_id';
184 +
185 + if ( ! self::index_exists( $table_name, $index_name ) ) {
186 + $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" );
187 + }
188 + }
189 +
190 + /**
191 + * Check that an index exists in a database table before trying to add it (which results in an error).
192 + *
193 + * @since 6.6
194 + *
195 + * @param string $table_name
196 + * @param string $index_name
197 + * @return bool
198 + */
199 + private static function index_exists( $table_name, $index_name ) {
200 + global $wpdb;
201 + $row = $wpdb->get_row(
202 + $wpdb->prepare(
203 + 'SELECT 1 FROM information_schema.statistics
204 + WHERE table_schema = database()
205 + AND table_name = %s
206 + AND index_name = %s
207 + LIMIT 1',
208 + array( $table_name, $index_name )
209 + )
210 + );
211 + return (bool) $row;
212 + }
213 +
163 214 private function maybe_create_contact_form() {
164 215 $form_exists = FrmForm::get_id_by_key( 'contact-form' );
165 216 if ( ! $form_exists ) {
166 217 $this->add_default_template();
@@ -204,9 +255,9 @@
204 255 // bail if we don't know the previous version
205 256 return;
206 257 }
207 258
208 - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98 );
259 + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101 );
209 260 foreach ( $migrations as $migration ) {
210 261 if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
211 262 $function_name = 'migrate_to_' . $migration;
212 263 $this->$function_name();
@@ -233,9 +284,10 @@
233 284 delete_option( 'frm_lite_settings_upgrade' );
234 285 delete_option( 'frm-usage-uuid' );
235 286 delete_option( 'frm_inbox' );
236 287 delete_option( 'frmpro_css' );
237 - delete_option( 'frm_welcome_redirect' );
288 + delete_option( FrmOnboardingWizardController::REDIRECT_STATUS_OPTION );
289 + delete_option( FrmEmailSummaryHelper::$option_name );
238 290
239 291 // Delete roles.
240 292 $frm_roles = FrmAppHelper::frm_capabilities();
241 293 $roles = get_editable_roles();
@@ -264,9 +316,9 @@
264 316 // delete transients
265 317 delete_transient( 'frmpro_css' );
266 318 delete_transient( 'frm_options' );
267 319 delete_transient( 'frmpro_options' );
268 - delete_transient( 'frm_activation_redirect' );
320 + delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME );
269 321
270 322 $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_%' ) );
271 323
272 324 do_action( 'frm_after_uninstall' );
@@ -274,8 +326,28 @@
274 326 return true;
275 327 }
276 328
277 329 /**
330 + * Disables summary email for multisite (not the main site) if recipient setting isn't changed.
331 + *
332 + * @since 6.8
333 + */
334 + private function migrate_to_101() {
335 + if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) {
336 + return;
337 + }
338 +
339 + $frm_settings = FrmAppHelper::get_settings();
340 + if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) {
341 + // User changed it.
342 + return;
343 + }
344 +
345 + $frm_settings->summary_emails = 0;
346 + $frm_settings->store();
347 + }
348 +
349 + /**
278 350 * Clear frmpro_css transient.
279 351 *
280 352 * @since 4.10.02
281 353 */
@@ -318,9 +390,9 @@
318 390 }
319 391 }
320 392
321 393 /**
322 - * Delete uneeded default templates
394 + * Delete unneeded default templates
323 395 *
324 396 * @since 3.06
325 397 */
326 398 private function migrate_to_90() {
@@ -340,9 +412,9 @@
340 412 $fields = $this->get_fields_with_size();
341 413
342 414 foreach ( (array) $fields as $f ) {
343 415 FrmAppHelper::unserialize_or_decode( $f->field_options );
344 - $size = $f->field_options['size'];
416 + $size = $f->field_options['size'];
345 417 $this->maybe_convert_migrated_size( $size );
346 418
347 419 if ( $size === $f->field_options['size'] ) {
348 420 continue;
@@ -444,9 +516,9 @@
444 516 return;
445 517 }
446 518
447 519 foreach ( $styles as $style ) {
448 - if ( $style->post_content['field_width'] == '400px' ) {
520 + if ( $style->post_content['field_width'] === '400px' ) {
449 521 $style->post_content['field_width'] = '100%';
450 522 $frm_style->save( (array) $style );
451 523
452 524 return;
@@ -510,9 +582,9 @@
510 582
511 583 private function convert_character_to_px( &$size ) {
512 584 $pixel_conversion = 9;
513 585
514 - $size = round( $pixel_conversion * (int) $size );
586 + $size = round( $pixel_conversion * (int) $size );
515 587 $size .= 'px';
516 588 }
517 589
518 590 /**
@@ -584,9 +656,9 @@
584 656 $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
585 657 $draft_link = FrmFormsHelper::get_draft_link();
586 658 foreach ( $forms as $form ) {
587 659 FrmAppHelper::unserialize_or_decode( $form->options );
588 - if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) {
660 + if ( empty( $form->options['submit_html'] ) ) {
589 661 continue;
590 662 }
591 663
592 664 if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {