PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.49
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.49
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / includes / class-activator.php

class-activator.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.49, at includes/class-activator.php

859 lines 30.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Fired during plugin activation.
4 *
5 * This class defines all code necessary to run during the plugin's activation.
6 *
7 * @since 1.0.0
8 * @author GeoDirectory Team <info@wpgeodirectory.com>
9 */
10 class UsersWP_Activator {
11
12 /** @var array DB updates and callbacks that need to be run per version */
13 private static $db_updates = array(
14 '1.2.0.0' => array(
15 'uwp_upgrade_1200',
16 ),
17 '1.2.0.13' => array(
18 'uwp_upgrade_12013',
19 ),
20 '1.2.2.5' => array(
21 'uwp_upgrade_1225',
22 ),
23 '1.2.3' => array(
24 'uwp_upgrade_1230',
25 ),
26 );
27
28
29 /**
30 * Background update class.
31 *
32 * @var object
33 */
34 private static $background_updater;
35
36 /**
37 * This method gets fired during plugin activation.
38 *
39 * @since 1.0.0
40 * @package userswp
41 * @return void
42 */
43 public static function activate( $network_wide = false ) {
44
45 if ( is_multisite() ) {
46 $main_site = get_network()->site_id;
47 if ( $network_wide ) {
48
49 update_network_option( '', 'uwp_is_network_active', 1 );
50 switch_to_blog( $main_site );
51 restore_current_blog();
52
53 if ( defined( 'UWP_ROOT_PAGES' ) ) {
54 if ( UWP_ROOT_PAGES == 'all' ) {
55 $blog_ids = self::get_blog_ids();
56
57 foreach ( $blog_ids as $blog_id ) {
58 switch_to_blog( $blog_id );
59 self::install();
60 }
61 restore_current_blog();
62 } else {
63 $blog_id = UWP_ROOT_PAGES;
64 switch_to_blog( $blog_id );
65 self::install();
66 restore_current_blog();
67 }
68 } else {
69 switch_to_blog( $main_site );
70 self::install();
71 restore_current_blog();
72 }
73 } else {
74 self::install();
75 }
76 } else {
77 self::install();
78 }
79 }
80
81 public static function install() {
82
83 uwp_generate_default_pages();
84 self::add_default_options();
85 uwp_create_tables();
86
87 // run update functions if needed
88 if ( self::needs_db_update() ) {
89 self::update();
90 }
91
92 if ( ! get_option( 'uwp_default_data_installed' ) ) {
93 // new install
94 self::create_default_fields();
95 self::insert_form_extras();
96 update_option( 'uwp_default_data_installed', 1 );
97 update_option( 'uwp_activation_redirect', 1 );
98 } else {
99 // upgrade
100 // if updating from < 1.2.0 then add the try bootstrap notice
101 if ( version_compare( get_option( 'uwp_db_version', null ), '1.2.0', '<' ) ) {
102 update_option( 'uwp_notice_try_bootstrap', true );
103 uwp_update_option( 'design_style', '' );
104 }
105 }
106
107 self::flush_rewrite_rules();
108 update_option( 'uwp_flush_rewrite', 1 );
109
110 // update the version
111 update_option( 'uwp_db_version', USERSWP_VERSION );
112
113 $installed = get_option( 'uwp_installed_on' );
114
115 if ( empty( $installed ) ) {
116 update_option( 'uwp_installed_on', time() );
117 }
118 }
119
120 /**
121 * Get all IDs of blogs that are not activated, not spam, and not deleted
122 *
123 * @global object $wpdb
124 * @return array|false Array of IDs or false if none are found
125 */
126 public static function get_blog_ids() {
127 global $wpdb;
128
129 // Get an array of IDs
130 $sql = "SELECT blog_id FROM $wpdb->blogs
131 WHERE archived = '0' AND spam = '0'
132 AND deleted = '0'";
133
134 return $wpdb->get_col( $sql );
135 }
136
137 /**
138 * Adds default settings during plugin activation.
139 *
140 * @since 1.0.0
141 * @package userswp
142 * @return void
143 */
144 public static function add_default_options() {
145
146 $settings = get_option( 'uwp_settings', array() );
147
148 $options = array(
149 'register_modal' => 1,
150 'uwp_registration_action' => 'auto_approve',
151 'wp_register_redirect' => 1,
152 'login_modal' => 1,
153 'login_redirect_to' => -1,
154 'block_wp_login' => 0,
155 'disable_wp_2fa' => 0,
156 'forgot_modal' => 1,
157 'change_enable_old_password' => 1,
158 'change_disable_password_nag' => 0,
159 'enable_profile_header' => 1,
160 'enable_profile_body' => 1,
161 'profile_avatar_size' => '',
162 'profile_banner_size' => '',
163 'profile_banner_width' => 1000,
164 'profile_no_of_items' => 10,
165 'users_no_of_items' => 10,
166 'uwp_disable_author_link' => 0,
167 'users_default_layout' => '3col',
168 'author_box_enable_disable' => 1,
169 'author_box_display_content' => 'below_content',
170 'author_box_display_post_types' => array( 'post' ),
171 'author_box_content' => '',
172 'author_box_bio_limit' => 200,
173 'registration_success_email_admin' => 1,
174 'registration_success_email_subject_admin' => UsersWP_Defaults::registration_success_email_subject_admin(),
175 'registration_success_email_content_admin' => UsersWP_Defaults::registration_success_email_content_admin(),
176 'registration_activate_email' => 1,
177 'registration_activate_email_subject' => UsersWP_Defaults::registration_activate_email_subject(),
178 'registration_activate_email_content' => UsersWP_Defaults::registration_activate_email_content(),
179 'registration_success_email' => 1,
180 'registration_success_email_subject' => UsersWP_Defaults::registration_success_email_subject(),
181 'registration_success_email_content' => UsersWP_Defaults::registration_success_email_content(),
182 'forgot_password_email' => 1,
183 'forgot_password_email_subject' => UsersWP_Defaults::forgot_password_email_subject(),
184 'forgot_password_email_content' => UsersWP_Defaults::forgot_password_email_content(),
185 'change_password_email' => 1,
186 'change_password_email_subject' => UsersWP_Defaults::change_password_email_subject(),
187 'change_password_email_content' => UsersWP_Defaults::change_password_email_content(),
188 'reset_password_email' => 1,
189 'reset_password_email_subject' => UsersWP_Defaults::reset_password_email_subject(),
190 'reset_password_email_content' => UsersWP_Defaults::reset_password_email_content(),
191 'account_update_email' => 1,
192 'account_update_email_subject' => UsersWP_Defaults::account_update_email_subject(),
193 'account_update_email_content' => UsersWP_Defaults::account_update_email_content(),
194 'account_delete_email' => 1,
195 'account_delete_email_subject' => UsersWP_Defaults::account_delete_email_subject(),
196 'account_delete_email_content' => UsersWP_Defaults::account_delete_email_content(),
197 'account_delete_email_admin' => 1,
198 'account_delete_email_subject_admin' => UsersWP_Defaults::account_delete_email_subject_admin(),
199 'account_delete_email_content_admin' => UsersWP_Defaults::account_delete_email_content_admin(),
200 'wp_new_user_notification_email' => 1,
201 'wp_new_user_notification_email_subject' => UsersWP_Defaults::wp_new_user_notification_email_subject(),
202 'wp_new_user_notification_email_content' => UsersWP_Defaults::wp_new_user_notification_email_content(),
203 'account_new_email_activation_email' => 1,
204 'account_new_email_activation_email_subject' => UsersWP_Defaults::account_new_email_activation_email_subject(),
205 'account_new_email_activation_email_content' => UsersWP_Defaults::account_new_email_activation_email_content(),
206 'wp_new_user_notification_email_admin' => 1,
207 'wp_new_user_notification_email_subject_admin' => UsersWP_Defaults::wp_new_user_notification_email_subject_admin(),
208 'wp_new_user_notification_email_content_admin' => UsersWP_Defaults::wp_new_user_notification_email_content_admin(),
209 'user_post_counts_cpts' => array( 'post' ),
210 'login_user_post_counts_cpts' => array( 'post' ),
211 'multiple_registration_forms' => uwp_get_default_form_data(),
212 'profile_seo_meta_description_length' => 150,
213 );
214
215 foreach ( $options as $option => $value ) {
216 if ( ! isset( $settings[ $option ] ) ) {
217 $settings[ $option ] = $value;
218 }
219 }
220
221 update_option( 'uwp_settings', $settings );
222 }
223
224 public static function init_background_updater() {
225 if ( empty( self::$background_updater ) ) {
226 include_once __DIR__ . '/class-uwp-background-updater.php';
227 self::$background_updater = new UsersWP_Background_Updater();
228 }
229 }
230
231 /**
232 * Syncs WP usermeta with UsersWP usermeta during plugin activation.
233 *
234 * @since 1.0.0
235 * @package userswp
236 * @return void
237 */
238 public static function uwp_update_usermeta( $dispatch = false ) {
239 $update_callback = 'uwp_insert_usermeta';
240 self::init_background_updater();
241
242 uwp_error_log( sprintf( 'Queuing %s - %s', USERSWP_VERSION, $update_callback ) );
243 self::$background_updater->push_to_queue( $update_callback );
244 if ( $dispatch ) {
245 self::$background_updater->save()->dispatch();
246 }
247 }
248
249 /**
250 * Get list of DB update callbacks.
251 *
252 * @since 3.0.0
253 * @return array
254 */
255 public static function get_db_update_callbacks() {
256 return self::$db_updates;
257 }
258
259 /**
260 * Is a DB update needed?
261 *
262 * @since 2.0.0
263 * @return boolean
264 */
265 private static function needs_db_update() {
266 $current_db_version = get_option( 'uwp_db_version', null );
267 $updates = self::get_db_update_callbacks();
268
269 return ! is_null( $current_db_version ) && ! empty( $updates ) && version_compare( $current_db_version, max( array_keys( $updates ) ), '<' );
270 }
271
272 /**
273 * Push all needed DB updates to the queue for processing.
274 *
275 * @since 2.0.0
276 */
277 private static function update() {
278 $current_db_version = get_option( 'uwp_db_version' );
279 $update_queued = false;
280 self::init_background_updater();
281 foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) {
282 if ( version_compare( $current_db_version, $version, '<' ) ) {
283 foreach ( $update_callbacks as $update_callback ) {
284 uwp_error_log( sprintf( 'Queuing %s - %s', $version, $update_callback ) );
285 self::$background_updater->push_to_queue( $update_callback );
286 $update_queued = true;
287 }
288 }
289 }
290
291 if ( $update_queued ) {
292 self::uwp_update_usermeta();// make sure to sync user meta
293 self::$background_updater->save()->dispatch();
294 } else {
295 self::uwp_update_usermeta( true );// make sure to sync user meta
296 }
297 }
298
299 /**
300 * Saves default custom fields in the database.
301 *
302 * @since 1.0.0
303 * @package userswp
304 * @return void
305 */
306 public static function create_default_fields() {
307 $form_builder = new UsersWP_Form_Builder();
308
309 $fields = self::uwp_default_custom_fields();
310
311 $fields = apply_filters( 'uwp_before_default_custom_fields_saved', $fields );
312
313 foreach ( $fields as $field_index => $field ) {
314 $form_builder->admin_form_field_save( $field );
315 }
316 }
317
318 /**
319 * Returns merged default custom fields.
320 *
321 * @since 1.0.0
322 * @package userswp
323 * @return array Merged custom fields.
324 */
325 public static function uwp_default_custom_fields() {
326
327 $login = self::uwp_default_custom_fields_login();
328 $forgot = self::uwp_default_custom_fields_forgot();
329 $avatar = self::uwp_default_custom_fields_avatar();
330 $banner = self::uwp_default_custom_fields_banner();
331 $change = self::uwp_default_custom_fields_change();
332 $reset = self::uwp_default_custom_fields_reset();
333 $account = self::uwp_default_custom_fields_account();
334
335 $fields = array_merge( $login, $forgot, $account, $avatar, $banner, $change, $reset );
336
337 $fields = apply_filters( 'uwp_default_custom_fields', $fields );
338
339 return $fields;
340 }
341
342 /**
343 * Returns Login form default custom fields.
344 *
345 * @since 1.0.0
346 * @package userswp
347 * @return array Login form default custom fields.
348 */
349 public static function uwp_default_custom_fields_login() {
350
351 $fields = array();
352
353 $fields[] = array(
354 'form_type' => 'login',
355 'field_type' => 'text',
356 'data_type' => 'XVARCHAR',
357 'site_title' => __( 'Username', 'userswp' ),
358 'htmlvar_name' => 'username',
359 'default_value' => '',
360 'option_values' => '',
361 'is_default' => '1',
362 'is_active' => '1',
363 'is_required' => '1',
364 );
365
366 $fields[] = array(
367 'form_type' => 'login',
368 'field_type' => 'password',
369 'data_type' => 'XVARCHAR',
370 'site_title' => __( 'Password', 'userswp' ),
371 'htmlvar_name' => 'password',
372 'default_value' => '',
373 'option_values' => '',
374 'is_default' => '1',
375 'is_active' => '1',
376 'is_required' => '1',
377 );
378
379 $fields = apply_filters( 'uwp_default_custom_fields_login', $fields );
380
381 return $fields;
382 }
383
384 /**
385 * Returns Forgot form default custom fields.
386 *
387 * @since 1.0.0
388 * @package userswp
389 * @return array Forgot form default custom fields.
390 */
391 public static function uwp_default_custom_fields_forgot() {
392
393 $fields = array();
394
395 $fields[] = array(
396 'form_type' => 'forgot',
397 'field_type' => 'email',
398 'data_type' => 'XVARCHAR',
399 'site_title' => __( 'Email', 'userswp' ),
400 'htmlvar_name' => 'email',
401 'default_value' => '',
402 'option_values' => '',
403 'is_default' => '1',
404 'is_active' => '1',
405 'is_required' => '1',
406 );
407
408 $fields = apply_filters( 'uwp_default_custom_fields_forgot', $fields );
409
410 return $fields;
411 }
412
413 /**
414 * Returns Avatar form default custom fields.
415 *
416 * @since 1.0.0
417 * @package userswp
418 * @return array Avatar form default custom fields.
419 */
420 public static function uwp_default_custom_fields_avatar() {
421
422 $fields = array();
423
424 $fields[] = array(
425 'form_type' => 'avatar',
426 'field_type' => 'file',
427 'data_type' => 'TEXT',
428 'site_title' => __( 'Avatar', 'userswp' ),
429 'htmlvar_name' => 'avatar',
430 'default_value' => '',
431 'option_values' => '',
432 'is_default' => '1',
433 'is_active' => '1',
434 'is_required' => '1',
435 'extra_fields' => array(
436 'uwp_file_types' => array(
437 'jpg',
438 'jpe',
439 'jpeg',
440 'gif',
441 'png',
442 ),
443 ),
444 );
445
446 $fields = apply_filters( 'uwp_default_custom_fields_avatar', $fields );
447
448 return $fields;
449 }
450
451 /**
452 * Returns Banner form default custom fields.
453 *
454 * @since 1.0.0
455 * @package userswp
456 * @return array Banner form default custom fields.
457 */
458 public static function uwp_default_custom_fields_banner() {
459
460 $fields = array();
461
462 $fields[] = array(
463 'form_type' => 'banner',
464 'field_type' => 'file',
465 'data_type' => 'TEXT',
466 'site_title' => __( 'Banner', 'userswp' ),
467 'htmlvar_name' => 'banner',
468 'default_value' => '',
469 'option_values' => '',
470 'is_default' => '1',
471 'is_active' => '1',
472 'is_required' => '1',
473 'extra_fields' => array(
474 'uwp_file_types' => array(
475 'jpg',
476 'jpe',
477 'jpeg',
478 'gif',
479 'png',
480 ),
481 ),
482 );
483
484 $fields = apply_filters( 'uwp_default_custom_fields_banner', $fields );
485
486 return $fields;
487 }
488
489 /**
490 * Returns Change Password form default custom fields.
491 *
492 * @since 1.0.0
493 * @package userswp
494 * @return array Change Password form default custom fields.
495 */
496 public static function uwp_default_custom_fields_change() {
497
498 $fields = array();
499
500 $fields[] = array(
501 'form_type' => 'change',
502 'field_type' => 'password',
503 'data_type' => 'XVARCHAR',
504 'site_title' => __( 'Old Password', 'userswp' ),
505 'htmlvar_name' => 'old_password',
506 'default_value' => '',
507 'option_values' => '',
508 'is_default' => '1',
509 'is_active' => '1',
510 'is_required' => '1',
511 );
512
513 $fields[] = array(
514 'form_type' => 'change',
515 'field_type' => 'password',
516 'data_type' => 'XVARCHAR',
517 'site_title' => __( 'New Password', 'userswp' ),
518 'htmlvar_name' => 'password',
519 'default_value' => '',
520 'option_values' => '',
521 'is_default' => '1',
522 'is_active' => '1',
523 'is_required' => '1',
524 );
525
526 $fields[] = array(
527 'form_type' => 'change',
528 'field_type' => 'password',
529 'data_type' => 'XVARCHAR',
530 'site_title' => __( 'Confirm Password', 'userswp' ),
531 'htmlvar_name' => 'confirm_password',
532 'default_value' => '',
533 'option_values' => '',
534 'is_default' => '1',
535 'is_active' => '1',
536 'is_required' => '1',
537 );
538
539 $fields = apply_filters( 'uwp_default_custom_fields_change', $fields );
540
541 return $fields;
542 }
543
544 /**
545 * Returns Reset Password form default custom fields.
546 *
547 * @since 1.0.0
548 * @package userswp
549 * @return array Reset Password form default custom fields.
550 */
551 public static function uwp_default_custom_fields_reset() {
552
553 $fields = array();
554
555 $fields[] = array(
556 'form_type' => 'reset',
557 'field_type' => 'password',
558 'data_type' => 'XVARCHAR',
559 'site_title' => __( 'Password', 'userswp' ),
560 'htmlvar_name' => 'password',
561 'default_value' => '',
562 'option_values' => '',
563 'is_default' => '1',
564 'is_active' => '1',
565 'is_required' => '1',
566 );
567
568 $fields[] = array(
569 'form_type' => 'reset',
570 'field_type' => 'password',
571 'data_type' => 'XVARCHAR',
572 'site_title' => __( 'Confirm Password', 'userswp' ),
573 'htmlvar_name' => 'confirm_password',
574 'default_value' => '',
575 'option_values' => '',
576 'is_default' => '1',
577 'is_active' => '1',
578 'is_required' => '1',
579 );
580
581 $fields = apply_filters( 'uwp_default_custom_fields_reset', $fields );
582
583 return $fields;
584 }
585
586 /**
587 * Returns Account form default custom fields.
588 *
589 * @since 1.0.0
590 * @package userswp
591 * @return array Account form default custom fields.
592 */
593 public static function uwp_default_custom_fields_account() {
594
595 $fields = array();
596
597 $fields[] = array(
598 'form_type' => 'account',
599 'field_type' => 'text',
600 'data_type' => 'XVARCHAR',
601 'site_title' => __( 'First Name', 'userswp' ),
602 'htmlvar_name' => 'first_name',
603 'default_value' => '',
604 'option_values' => '',
605 'is_default' => '1',
606 'is_public' => '1',
607 'is_active' => '1',
608 'is_required' => '1',
609 'is_register_field' => '1',
610 'is_search_field' => '1',
611 );
612
613 $fields[] = array(
614 'form_type' => 'account',
615 'field_type' => 'text',
616 'data_type' => 'XVARCHAR',
617 'site_title' => __( 'Last Name', 'userswp' ),
618 'htmlvar_name' => 'last_name',
619 'default_value' => '',
620 'option_values' => '',
621 'is_default' => '1',
622 'is_public' => '1',
623 'is_active' => '1',
624 'is_required' => '1',
625 'is_register_field' => '1',
626 'is_search_field' => '1',
627 );
628
629 $fields[] = array(
630 'form_type' => 'account',
631 'field_type' => 'text',
632 'data_type' => 'XVARCHAR',
633 'site_title' => __( 'Username', 'userswp' ),
634 'htmlvar_name' => 'username',
635 'default_value' => '',
636 'option_values' => '',
637 'is_default' => '1',
638 'is_public' => '1',
639 'is_active' => '1',
640 'is_required' => '1',
641 'is_register_field' => '1',
642 'is_search_field' => '1',
643 'is_register_only_field' => '1',
644 );
645
646 $fields[] = array(
647 'form_type' => 'account',
648 'field_type' => 'text',
649 'data_type' => 'XVARCHAR',
650 'site_title' => __( 'Display Name', 'userswp' ),
651 'htmlvar_name' => 'display_name',
652 'default_value' => '',
653 'option_values' => '',
654 'is_default' => '1',
655 'is_public' => '1',
656 'is_active' => '1',
657 'is_required' => '0',
658 'is_register_field' => '0',
659 'is_search_field' => '1',
660 );
661
662 $fields[] = array(
663 'form_type' => 'account',
664 'field_type' => 'email',
665 'data_type' => 'XVARCHAR',
666 'site_title' => __( 'Email', 'userswp' ),
667 'htmlvar_name' => 'email',
668 'default_value' => '',
669 'option_values' => '',
670 'is_default' => '1',
671 'is_active' => '1',
672 'is_required' => '1',
673 'is_register_field' => '1',
674 'is_search_field' => '1',
675 );
676
677 $fields[] = array(
678 'form_type' => 'account',
679 'field_type' => 'textarea',
680 'data_type' => 'TEXT',
681 'site_title' => __( 'Bio', 'userswp' ),
682 'htmlvar_name' => 'bio',
683 'default_value' => '',
684 'option_values' => '',
685 'is_default' => '0',
686 'is_active' => '1',
687 'is_public' => '1',
688 'is_required' => '1',
689 'is_search_field' => '1',
690 'show_in' => array( '[users]' ),
691 );
692
693 $fields[] = array(
694 'form_type' => 'account',
695 'field_type' => 'password',
696 'data_type' => 'XVARCHAR',
697 'site_title' => __( 'Password', 'userswp' ),
698 'htmlvar_name' => 'password',
699 'default_value' => '',
700 'option_values' => '',
701 'is_default' => '1',
702 'is_active' => '1',
703 'is_required' => '1',
704 'is_register_field' => '1',
705 'is_register_only_field' => '1',
706 'extra' => array(
707 'confirm_password' => '1',
708 ),
709 );
710
711 $fields = apply_filters( 'uwp_default_custom_fields_account', $fields );
712
713 return $fields;
714 }
715
716 /**
717 * Flushes rewrite rules.
718 *
719 * @since 1.0.0
720 * @package userswp
721 * @return void
722 */
723 public static function flush_rewrite_rules() {
724 flush_rewrite_rules();
725 }
726
727 /**
728 * Inserts register form custom fields in form extras table.
729 *
730 * @since 1.0.0
731 * @package userswp
732 * @return void
733 */
734 public static function insert_form_extras( $form_id = 1 ) {
735 global $wpdb;
736 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
737
738 $fields = array();
739
740 $fields[] = array(
741 'form_type' => 'register',
742 'field_type' => 'text',
743 'is_default' => '0',
744 'htmlvar_name' => 'first_name',
745 );
746
747 $fields[] = array(
748 'form_type' => 'register',
749 'field_type' => 'text',
750 'is_default' => '0',
751 'htmlvar_name' => 'last_name',
752 );
753
754 $fields[] = array(
755 'form_type' => 'register',
756 'field_type' => 'text',
757 'is_default' => '1',
758 'htmlvar_name' => 'username',
759 );
760
761 $fields[] = array(
762 'form_type' => 'register',
763 'field_type' => 'email',
764 'is_default' => '1',
765 'htmlvar_name' => 'email',
766 );
767
768 $fields[] = array(
769 'form_type' => 'register',
770 'field_type' => 'password',
771 'is_default' => '0',
772 'htmlvar_name' => 'password',
773 );
774
775 foreach ( $fields as $field ) {
776 $last_order = $wpdb->get_var( 'SELECT MAX(sort_order) as last_order FROM ' . $extras_table_name . ' where form_id = ' . $form_id );
777 $sort_order = (int)$last_order + 1;
778 $wpdb->query(
779 $wpdb->prepare(
780 'insert into ' . $extras_table_name . ' set
781 form_type = %s,
782 field_type = %s,
783 is_default = %s,
784 site_htmlvar_name = %s,
785 sort_order = %s,
786 form_id = %s',
787 array(
788 $field['form_type'],
789 $field['field_type'],
790 $field['is_default'],
791 $field['htmlvar_name'],
792 $sort_order,
793 $form_id,
794 )
795 )
796 );
797 }
798 }
799
800 /**
801 * Performs automatic upgrade
802 *
803 * @since 2.0.0
804 * @package userswp
805 * @return void
806 */
807 public static function automatic_upgrade() {
808 $uwp_db_version = get_option( 'uwp_db_version' );
809
810 if ( $uwp_db_version != USERSWP_VERSION ) {
811 self::activate( is_plugin_active_for_network( 'userswp/userswp.php' ) );
812 $settings = get_option( 'uwp_settings', array() );
813 $needs_update = false;
814 if ( isset( $settings['design_style'] ) && 'bootstrap' == $settings['design_style'] ) {
815 $settings['users_default_layout'] = '3col';
816 $needs_update = true;
817 }
818
819 if ( isset( $settings['uwp_registration_action'] ) && $settings['uwp_registration_action'] == 'force_redirect' ) {
820 $settings['uwp_registration_action'] = 'auto_approve_login';
821 $needs_update = true;
822 }
823
824 $get_register_form = isset( $settings['multiple_registration_forms'] ) ? $settings['multiple_registration_forms'] : false;
825
826 if ( ! empty( $get_register_form ) && is_array( $get_register_form ) ) {
827
828 foreach ( $get_register_form as $key => $register_form ) {
829
830 if ( ! empty( $register_form['id'] ) ) {
831
832 $reg_action = isset( $register_form['reg_action'] ) ? $register_form['reg_action'] : '';
833
834 if ( isset( $reg_action ) && $reg_action == 'force_redirect' ) {
835 $settings['multiple_registration_forms'][ $key ]['reg_action'] = 'auto_approve_login';
836 $needs_update = true;
837 }
838
839 $reg_title = isset( $register_form['title'] ) ? $register_form['title'] : '';
840
841 if ( isset( $reg_title ) && ! empty( $reg_title ) ) {
842 $settings['multiple_registration_forms'][ $key ]['title'] = sanitize_title_with_dashes( $reg_title );
843 $needs_update = true;
844 }
845 }
846 }
847 }
848
849 if ( $needs_update ) {
850 update_option( 'uwp_settings', $settings );
851 }
852
853 // Run this function once.
854 update_option( 'uwp_db_version', USERSWP_VERSION );
855
856 }
857 }
858 }
859