PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.19
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.19
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
formidable / classes / models / FrmMigrate.php

FrmMigrate.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.19, at classes/models/FrmMigrate.php

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