PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.73
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.73
1.2.74 1.2.73 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 All 174 releases
← All changes | includes/class-activator.php +463 -415 1.0.221.2.73 View file →
@@ -8,8 +8,25 @@
8 8 * @author GeoDirectory Team <info@wpgeodirectory.com>
9 9 */
10 10 class UsersWP_Activator {
11 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 +
12 29 /**
13 30 * Background update class.
14 31 *
15 32 * @var object
@@ -22,23 +39,22 @@
22 39 * @since 1.0.0
23 40 * @package userswp
24 41 * @return void
25 42 */
26 - public static function activate($network_wide = false) {
43 + public static function activate( $network_wide = false ) {
27 44
28 - if (is_multisite()) {
45 + if ( is_multisite() ) {
29 46 $main_site = get_network()->site_id;
30 - if($network_wide){
47 + if ( $network_wide ) {
31 48
49 + update_network_option( '', 'uwp_is_network_active', 1 );
32 50 switch_to_blog( $main_site );
33 - self::uwp101_create_tables();
34 - self::uwp_update_usermeta();
35 51 restore_current_blog();
36 -
37 - if (defined('UWP_ROOT_PAGES')) {
38 - if (UWP_ROOT_PAGES == 'all') {
39 - $blog_ids = self::uwp_get_blog_ids();
40 52
53 + if ( defined( 'UWP_ROOT_PAGES' ) ) {
54 + if ( UWP_ROOT_PAGES == 'all' ) {
55 + $blog_ids = self::get_blog_ids();
56 +
41 57 foreach ( $blog_ids as $blog_id ) {
42 58 switch_to_blog( $blog_id );
43 59 self::install();
44 60 }
@@ -53,38 +69,53 @@
53 69 switch_to_blog( $main_site );
54 70 self::install();
55 71 restore_current_blog();
56 72 }
57 -
58 - } else {
59 - self::uwp101_create_tables();
73 +} else {
60 74 self::install();
61 - self::uwp_update_usermeta();
62 75 }
63 76 } else {
64 - self::uwp101_create_tables();
65 77 self::install();
66 - self::uwp_update_usermeta();
67 78 }
79 + }
68 80
69 - }
81 + public static function install() {
70 82
71 - public static function install(){
83 + uwp_generate_default_pages();
84 + self::add_default_options();
85 + uwp_create_tables();
72 86
73 - self::generate_pages();
74 - self::uwp_create_tables();
87 + // run update functions if needed
88 + if ( self::needs_db_update() ) {
89 + self::update();
90 + }
75 91
76 - if (!get_option('uwp_default_data_installed')) {
77 - self::add_default_options();
78 - self::uwp_create_default_fields();
79 - self::uwp_insert_form_extras();
80 - update_option('uwp_default_data_installed', 1);
81 - update_option('uwp_activation_redirect', 1);
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 + }
82 105 }
83 106
84 - self::uwp_flush_rewrite_rules();
85 - update_option('uwp_flush_rewrite', 1);
107 + self::flush_rewrite_rules();
108 + update_option( 'uwp_flush_rewrite', 1 );
86 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 + }
87 118 }
88 119
89 120 /**
90 121 * Get all IDs of blogs that are not activated, not spam, and not deleted
@@ -91,9 +122,9 @@
91 122 *
92 123 * @global object $wpdb
93 124 * @return array|false Array of IDs or false if none are found
94 125 */
95 - public static function uwp_get_blog_ids() {
126 + public static function get_blog_ids() {
96 127 global $wpdb;
97 128
98 129 // Get an array of IDs
99 130 $sql = "SELECT blog_id FROM $wpdb->blogs
@@ -103,19 +134,8 @@
103 134 return $wpdb->get_col( $sql );
104 135 }
105 136
106 137 /**
107 - * Generates the default pages during plugin activation.
108 - *
109 - * @since 1.0.0
110 - * @package userswp
111 - * @return void
112 - */
113 - public static function generate_pages() {
114 - uwp_generate_default_pages();
115 - }
116 -
117 - /**
118 138 * Adds default settings during plugin activation.
119 139 *
120 140 * @since 1.0.0
121 141 * @package userswp
@@ -122,178 +142,159 @@
122 142 * @return void
123 143 */
124 144 public static function add_default_options() {
125 145
126 - $settings = get_option( 'uwp_settings', array());
146 + $settings = get_option( 'uwp_settings', array() );
127 147
128 - //general
129 - if (!isset($settings['profile_no_of_items'])) {
130 - $settings['profile_no_of_items'] = '10';
131 - }
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 + );
132 214
133 - //login
134 - if (!isset($settings['login_redirect_to'])) {
135 - $settings['login_redirect_to'] = -1;
136 - }
137 -
138 - //profile
139 - if (!isset($settings['enable_profile_header'])) {
140 - $settings['enable_profile_header'] = '1';
141 - }
142 - if (!isset($settings['enable_profile_body'])) {
143 - $settings['enable_profile_body'] = '1';
144 - }
145 - if (!isset($settings['enable_profile_posts_tab'])) {
146 - $settings['enable_profile_posts_tab'] = '1';
147 - }
148 - if (!isset($settings['enable_profile_comments_tab'])) {
149 - $settings['enable_profile_comments_tab'] = '1';
150 - }
151 -
152 - if (isset($settings['enable_profile_tabs']) && is_array($settings['enable_profile_tabs'])) {
153 - if (!isset($settings['enable_profile_tabs']['more_info'])) {
154 - $settings['enable_profile_tabs'][] = 'more_info';
215 + foreach ( $options as $option => $value ) {
216 + if ( ! isset( $settings[ $option ] ) ) {
217 + $settings[ $option ] = $value;
155 218 }
156 - if (!isset($settings['enable_profile_tabs']['posts'])) {
157 - $settings['enable_profile_tabs'][] = 'posts';
158 - }
159 - if (!isset($settings['enable_profile_tabs']['comments'])) {
160 - $settings['enable_profile_tabs'][] = 'comments';
161 - }
162 - } else {
163 - $settings['enable_profile_tabs'] = array('more_info', 'posts', 'comments');
164 219 }
165 220
221 + update_option( 'uwp_settings', $settings );
222 + }
166 223
167 - //notifications
168 -
169 - // admin
170 - $registration_success_email_subject_admin = __( 'New account registration', 'userswp' );
171 - $registration_success_email_content_admin = __("A user has been registered recently on your website. [#extras#]", "userswp");
172 -
173 - if (!isset($settings['registration_success_email_subject_admin'])) {
174 - $settings['registration_success_email_subject_admin'] = $registration_success_email_subject_admin;
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();
175 228 }
176 - if (!isset($settings['registration_success_email_content_admin'])) {
177 - $settings['registration_success_email_content_admin'] = $registration_success_email_content_admin;
178 - }
179 -
180 -
181 - // User
182 -
183 - // Register
184 - $registration_success_email_subject = __('Your Log In Details', 'userswp');
185 - $registration_success_email_content = __("<p>Dear [#user_name#],</p><p>You can log in with the following information:</p>[#login_details#]<p>You can login here: [#login_url#]</p><p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp');
186 -
187 - if (!isset($settings['registration_success_email_subject'])) {
188 - $settings['registration_success_email_subject'] = $registration_success_email_subject;
189 - }
190 - if (!isset($settings['registration_success_email_content'])) {
191 - $settings['registration_success_email_content'] = $registration_success_email_content;
192 - }
193 -
194 - // Activate
195 - $registration_activate_email_subject = __('Please activate your account', 'userswp');
196 - $registration_activate_email_content = __("<p>Dear [#user_name#],</p><p>Thank you for signing up with [#site_name#]</p>[#login_details#]<p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp');
197 -
198 - if (!isset($settings['registration_activate_email_subject'])) {
199 - $settings['registration_activate_email_subject'] = $registration_activate_email_subject;
200 - }
201 - if (!isset($settings['registration_activate_email_content'])) {
202 - $settings['registration_activate_email_content'] = $registration_activate_email_content;
203 - }
204 -
205 - // Forgot
206 - $forgot_password_email_subject = __('[#site_name#] - Your new password', 'userswp');
207 - $forgot_password_email_content = __("<p>Dear [#user_name#],</p>[#login_details#]<p>You can login here: [#login_url#]</p><p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp');
208 -
209 - if (!isset($settings['forgot_password_email_subject'])) {
210 - $settings['forgot_password_email_subject'] = $forgot_password_email_subject;
211 - }
212 - if (!isset($settings['forgot_password_email_content'])) {
213 - $settings['forgot_password_email_content'] = $forgot_password_email_content;
214 - }
215 -
216 - // Change
217 - $change_password_email_subject = __('[#site_name#] - Password has been changed', 'userswp');
218 - $change_password_email_content = __("<p>Dear [#user_name#],</p><p>Your password has been changed successfully.</p><p>You can login here: [#login_url#]</p><p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp');
219 -
220 - if (!isset($settings['change_password_email_subject'])) {
221 - $settings['change_password_email_subject'] = $change_password_email_subject;
222 - }
223 - if (!isset($settings['change_password_email_content'])) {
224 - $settings['change_password_email_content'] = $change_password_email_content;
225 - }
226 -
227 - // Reset
228 - $reset_password_email_subject = __('[#site_name#] - Password has been reset', 'userswp');
229 - $reset_password_email_content = __("<p>Dear [#user_name#],</p><p>Your password has been reset</p><p>You can login here: [#login_url#]</p><p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp');
230 -
231 - if (!isset($settings['reset_password_email_subject'])) {
232 - $settings['reset_password_email_subject'] = $reset_password_email_subject;
233 - }
234 - if (!isset($settings['reset_password_email_content'])) {
235 - $settings['reset_password_email_content'] = $reset_password_email_content;
236 - }
237 -
238 - // Update
239 - $account_update_email_subject = __('[#site_name#] - Account has been updated', 'userswp');
240 - $account_update_email_content = __("<p>Dear [#user_name#],</p><p>Your account has been updated successfully</p><p>Thank you,<br /><br />[#site_name_url#].</p>" ,'userswp');
241 -
242 - if (!isset($settings['account_update_email_subject'])) {
243 - $settings['account_update_email_subject'] = $account_update_email_subject;
244 - }
245 - if (!isset($settings['account_update_email_content'])) {
246 - $settings['account_update_email_content'] = $account_update_email_content;
247 - }
248 -
249 - update_option( 'uwp_settings', $settings );
250 -
251 229 }
252 230
253 231 /**
254 - * Creates tables during plugin activation.
232 + * Syncs WP usermeta with UsersWP usermeta during plugin activation.
255 233 *
256 234 * @since 1.0.0
257 235 * @package userswp
258 236 * @return void
259 237 */
260 - public static function uwp_create_tables()
261 - {
262 - uwp_create_tables();
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 + }
263 247 }
264 248
265 249 /**
266 - * Creates the new tables added in version 1.0.1 during plugin activation.
250 + * Get list of DB update callbacks.
267 251 *
268 - * @since 1.0.0
269 - * @package userswp
270 - * @return void
252 + * @since 3.0.0
253 + * @return array
271 254 */
272 - public static function uwp101_create_tables() {
273 - uwp101_create_tables();
255 + public static function get_db_update_callbacks() {
256 + return self::$db_updates;
274 257 }
275 258
276 - public static function init_background_updater(){
277 - include_once dirname( __FILE__ ) . '/class-uwp-background-updater.php';
278 - self::$background_updater = new UsersWP_Background_Updater();
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 ) ), '<' );
279 270 }
280 271
281 272 /**
282 - * Syncs WP usermeta with UsersWP usermeta during plugin activation.
273 + * Push all needed DB updates to the queue for processing.
283 274 *
284 - * @since 1.0.0
285 - * @package userswp
286 - * @return void
275 + * @since 2.0.0
287 276 */
288 - public static function uwp_update_usermeta()
289 - {
290 - $update_callback = 'uwp_insert_usermeta';
277 + private static function update() {
278 + $current_db_version = get_option( 'uwp_db_version' );
279 + $update_queued = false;
291 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 + }
292 290
293 - uwp_error_log( sprintf( 'Queuing %s - %s', USERSWP_VERSION, $update_callback ) );
294 - self::$background_updater->push_to_queue( $update_callback );
295 - self::$background_updater->save()->dispatch();
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 + }
296 297 }
297 298
298 299 /**
299 300 * Saves default custom fields in the database.
@@ -301,18 +302,17 @@
301 302 * @since 1.0.0
302 303 * @package userswp
303 304 * @return void
304 305 */
305 - public static function uwp_create_default_fields()
306 - {
306 + public static function create_default_fields() {
307 307 $form_builder = new UsersWP_Form_Builder();
308 308
309 309 $fields = self::uwp_default_custom_fields();
310 310
311 - $fields = apply_filters('uwp_before_default_custom_fields_saved', $fields);
311 + $fields = apply_filters( 'uwp_before_default_custom_fields_saved', $fields );
312 312
313 - foreach ($fields as $field_index => $field) {
314 - $form_builder->uwp_admin_form_field_save($field);
313 + foreach ( $fields as $field_index => $field ) {
314 + $form_builder->admin_form_field_save( $field );
315 315 }
316 316 }
317 317
318 318 /**
@@ -321,9 +321,9 @@
321 321 * @since 1.0.0
322 322 * @package userswp
323 323 * @return array Merged custom fields.
324 324 */
325 - public static function uwp_default_custom_fields(){
325 + public static function uwp_default_custom_fields() {
326 326
327 327 $login = self::uwp_default_custom_fields_login();
328 328 $forgot = self::uwp_default_custom_fields_forgot();
329 329 $avatar = self::uwp_default_custom_fields_avatar();
@@ -331,14 +331,13 @@
331 331 $change = self::uwp_default_custom_fields_change();
332 332 $reset = self::uwp_default_custom_fields_reset();
333 333 $account = self::uwp_default_custom_fields_account();
334 334
335 - $fields = array_merge($login, $forgot, $account, $avatar, $banner, $change, $reset);
335 + $fields = array_merge( $login, $forgot, $account, $avatar, $banner, $change, $reset );
336 336
337 - $fields = apply_filters('uwp_default_custom_fields', $fields);
337 + $fields = apply_filters( 'uwp_default_custom_fields', $fields );
338 338
339 339 return $fields;
340 -
341 340 }
342 341
343 342 /**
344 343 * Returns Login form default custom fields.
@@ -346,39 +345,39 @@
346 345 * @since 1.0.0
347 346 * @package userswp
348 347 * @return array Login form default custom fields.
349 348 */
350 - public static function uwp_default_custom_fields_login(){
349 + public static function uwp_default_custom_fields_login() {
351 350
352 351 $fields = array();
353 352
354 353 $fields[] = array(
355 - 'form_type' => 'login',
356 - 'field_type' => 'text',
357 - 'data_type' => 'XVARCHAR',
358 - 'site_title' => __('Username', 'userswp'),
359 - 'htmlvar_name' => 'username',
354 + 'form_type' => 'login',
355 + 'field_type' => 'text',
356 + 'data_type' => 'XVARCHAR',
357 + 'site_title' => __( 'Username', 'userswp' ),
358 + 'htmlvar_name' => 'username',
360 359 'default_value' => '',
361 360 'option_values' => '',
362 - 'is_default' => '1',
363 - 'is_active' => '1',
364 - 'is_required' => '1'
361 + 'is_default' => '1',
362 + 'is_active' => '1',
363 + 'is_required' => '1',
365 364 );
366 365
367 366 $fields[] = array(
368 - 'form_type' => 'login',
369 - 'field_type' => 'password',
370 - 'data_type' => 'XVARCHAR',
371 - 'site_title' => __('Password', 'userswp'),
372 - 'htmlvar_name' => 'password',
367 + 'form_type' => 'login',
368 + 'field_type' => 'password',
369 + 'data_type' => 'XVARCHAR',
370 + 'site_title' => __( 'Password', 'userswp' ),
371 + 'htmlvar_name' => 'password',
373 372 'default_value' => '',
374 373 'option_values' => '',
375 - 'is_default' => '1',
376 - 'is_active' => '1',
377 - 'is_required' => '1'
374 + 'is_default' => '1',
375 + 'is_active' => '1',
376 + 'is_required' => '1',
378 377 );
379 378
380 - $fields = apply_filters('uwp_default_custom_fields_login', $fields);
379 + $fields = apply_filters( 'uwp_default_custom_fields_login', $fields );
381 380
382 381 return $fields;
383 382 }
384 383
@@ -388,26 +387,26 @@
388 387 * @since 1.0.0
389 388 * @package userswp
390 389 * @return array Forgot form default custom fields.
391 390 */
392 - public static function uwp_default_custom_fields_forgot(){
391 + public static function uwp_default_custom_fields_forgot() {
393 392
394 393 $fields = array();
395 394
396 395 $fields[] = array(
397 - 'form_type' => 'forgot',
398 - 'field_type' => 'email',
399 - 'data_type' => 'XVARCHAR',
400 - 'site_title' => __('Email', 'userswp'),
401 - 'htmlvar_name' => 'email',
396 + 'form_type' => 'forgot',
397 + 'field_type' => 'email',
398 + 'data_type' => 'XVARCHAR',
399 + 'site_title' => __( 'Email', 'userswp' ),
400 + 'htmlvar_name' => 'email',
402 401 'default_value' => '',
403 402 'option_values' => '',
404 - 'is_default' => '1',
405 - 'is_active' => '1',
406 - 'is_required' => '1'
403 + 'is_default' => '1',
404 + 'is_active' => '1',
405 + 'is_required' => '1',
407 406 );
408 407
409 - $fields = apply_filters('uwp_default_custom_fields_forgot', $fields);
408 + $fields = apply_filters( 'uwp_default_custom_fields_forgot', $fields );
410 409
411 410 return $fields;
412 411 }
413 412
@@ -417,35 +416,35 @@
417 416 * @since 1.0.0
418 417 * @package userswp
419 418 * @return array Avatar form default custom fields.
420 419 */
421 - public static function uwp_default_custom_fields_avatar(){
420 + public static function uwp_default_custom_fields_avatar() {
422 421
423 422 $fields = array();
424 423
425 424 $fields[] = array(
426 - 'form_type' => 'avatar',
427 - 'field_type' => 'file',
428 - 'data_type' => 'TEXT',
429 - 'site_title' => __('Avatar', 'userswp'),
430 - 'htmlvar_name' => 'file',
425 + 'form_type' => 'avatar',
426 + 'field_type' => 'file',
427 + 'data_type' => 'TEXT',
428 + 'site_title' => __( 'Avatar', 'userswp' ),
429 + 'htmlvar_name' => 'avatar',
431 430 'default_value' => '',
432 431 'option_values' => '',
433 - 'is_default' => '1',
434 - 'is_active' => '1',
435 - 'is_required' => '1',
436 - 'extra_fields' => array(
437 - 'uwp_file_types' => array(
432 + 'is_default' => '1',
433 + 'is_active' => '1',
434 + 'is_required' => '1',
435 + 'extra_fields' => array(
436 + 'uwp_file_types' => array(
438 437 'jpg',
439 438 'jpe',
440 439 'jpeg',
441 440 'gif',
442 - 'png'
441 + 'png',
443 442 ),
444 - )
443 + ),
445 444 );
446 445
447 - $fields = apply_filters('uwp_default_custom_fields_avatar', $fields);
446 + $fields = apply_filters( 'uwp_default_custom_fields_avatar', $fields );
448 447
449 448 return $fields;
450 449 }
451 450
@@ -455,35 +454,35 @@
455 454 * @since 1.0.0
456 455 * @package userswp
457 456 * @return array Banner form default custom fields.
458 457 */
459 - public static function uwp_default_custom_fields_banner(){
458 + public static function uwp_default_custom_fields_banner() {
460 459
461 460 $fields = array();
462 461
463 462 $fields[] = array(
464 - 'form_type' => 'banner',
465 - 'field_type' => 'file',
466 - 'data_type' => 'TEXT',
467 - 'site_title' => __('Banner', 'userswp'),
468 - 'htmlvar_name' => 'file',
463 + 'form_type' => 'banner',
464 + 'field_type' => 'file',
465 + 'data_type' => 'TEXT',
466 + 'site_title' => __( 'Banner', 'userswp' ),
467 + 'htmlvar_name' => 'banner',
469 468 'default_value' => '',
470 469 'option_values' => '',
471 - 'is_default' => '1',
472 - 'is_active' => '1',
473 - 'is_required' => '1',
474 - 'extra_fields' => array(
475 - 'uwp_file_types' => array(
470 + 'is_default' => '1',
471 + 'is_active' => '1',
472 + 'is_required' => '1',
473 + 'extra_fields' => array(
474 + 'uwp_file_types' => array(
476 475 'jpg',
477 476 'jpe',
478 477 'jpeg',
479 478 'gif',
480 - 'png'
479 + 'png',
481 480 ),
482 - )
481 + ),
483 482 );
484 483
485 - $fields = apply_filters('uwp_default_custom_fields_banner', $fields);
484 + $fields = apply_filters( 'uwp_default_custom_fields_banner', $fields );
486 485
487 486 return $fields;
488 487 }
489 488
@@ -493,52 +492,52 @@
493 492 * @since 1.0.0
494 493 * @package userswp
495 494 * @return array Change Password form default custom fields.
496 495 */
497 - public static function uwp_default_custom_fields_change(){
496 + public static function uwp_default_custom_fields_change() {
498 497
499 498 $fields = array();
500 499
501 500 $fields[] = array(
502 - 'form_type' => 'change',
503 - 'field_type' => 'password',
504 - 'data_type' => 'XVARCHAR',
505 - 'site_title' => __('Old Password', 'userswp'),
506 - 'htmlvar_name' => 'old_password',
501 + 'form_type' => 'change',
502 + 'field_type' => 'password',
503 + 'data_type' => 'XVARCHAR',
504 + 'site_title' => __( 'Old Password', 'userswp' ),
505 + 'htmlvar_name' => 'old_password',
507 506 'default_value' => '',
508 507 'option_values' => '',
509 - 'is_default' => '1',
510 - 'is_active' => '1',
511 - 'is_required' => '1'
508 + 'is_default' => '1',
509 + 'is_active' => '1',
510 + 'is_required' => '1',
512 511 );
513 512
514 513 $fields[] = array(
515 - 'form_type' => 'change',
516 - 'field_type' => 'password',
517 - 'data_type' => 'XVARCHAR',
518 - 'site_title' => __('New Password', 'userswp'),
519 - 'htmlvar_name' => 'password',
514 + 'form_type' => 'change',
515 + 'field_type' => 'password',
516 + 'data_type' => 'XVARCHAR',
517 + 'site_title' => __( 'New Password', 'userswp' ),
518 + 'htmlvar_name' => 'password',
520 519 'default_value' => '',
521 520 'option_values' => '',
522 - 'is_default' => '1',
523 - 'is_active' => '1',
524 - 'is_required' => '1'
521 + 'is_default' => '1',
522 + 'is_active' => '1',
523 + 'is_required' => '1',
525 524 );
526 525
527 526 $fields[] = array(
528 - 'form_type' => 'change',
529 - 'field_type' => 'password',
530 - 'data_type' => 'XVARCHAR',
531 - 'site_title' => __('Confirm Password', 'userswp'),
532 - 'htmlvar_name' => 'confirm_password',
527 + 'form_type' => 'change',
528 + 'field_type' => 'password',
529 + 'data_type' => 'XVARCHAR',
530 + 'site_title' => __( 'Confirm Password', 'userswp' ),
531 + 'htmlvar_name' => 'confirm_password',
533 532 'default_value' => '',
534 533 'option_values' => '',
535 - 'is_default' => '1',
536 - 'is_active' => '1',
537 - 'is_required' => '1'
534 + 'is_default' => '1',
535 + 'is_active' => '1',
536 + 'is_required' => '1',
538 537 );
539 538
540 - $fields = apply_filters('uwp_default_custom_fields_change', $fields);
539 + $fields = apply_filters( 'uwp_default_custom_fields_change', $fields );
541 540
542 541 return $fields;
543 542 }
544 543
@@ -548,39 +547,39 @@
548 547 * @since 1.0.0
549 548 * @package userswp
550 549 * @return array Reset Password form default custom fields.
551 550 */
552 - public static function uwp_default_custom_fields_reset(){
551 + public static function uwp_default_custom_fields_reset() {
553 552
554 553 $fields = array();
555 554
556 555 $fields[] = array(
557 - 'form_type' => 'reset',
558 - 'field_type' => 'password',
559 - 'data_type' => 'XVARCHAR',
560 - 'site_title' => __('Password', 'userswp'),
561 - 'htmlvar_name' => 'password',
556 + 'form_type' => 'reset',
557 + 'field_type' => 'password',
558 + 'data_type' => 'XVARCHAR',
559 + 'site_title' => __( 'Password', 'userswp' ),
560 + 'htmlvar_name' => 'password',
562 561 'default_value' => '',
563 562 'option_values' => '',
564 - 'is_default' => '1',
565 - 'is_active' => '1',
566 - 'is_required' => '1'
563 + 'is_default' => '1',
564 + 'is_active' => '1',
565 + 'is_required' => '1',
567 566 );
568 567
569 568 $fields[] = array(
570 - 'form_type' => 'reset',
571 - 'field_type' => 'password',
572 - 'data_type' => 'XVARCHAR',
573 - 'site_title' => __('Confirm Password', 'userswp'),
574 - 'htmlvar_name' => 'confirm_password',
569 + 'form_type' => 'reset',
570 + 'field_type' => 'password',
571 + 'data_type' => 'XVARCHAR',
572 + 'site_title' => __( 'Confirm Password', 'userswp' ),
573 + 'htmlvar_name' => 'confirm_password',
575 574 'default_value' => '',
576 575 'option_values' => '',
577 - 'is_default' => '1',
578 - 'is_active' => '1',
579 - 'is_required' => '1'
576 + 'is_default' => '1',
577 + 'is_active' => '1',
578 + 'is_required' => '1',
580 579 );
581 580
582 - $fields = apply_filters('uwp_default_custom_fields_reset', $fields);
581 + $fields = apply_filters( 'uwp_default_custom_fields_reset', $fields );
583 582
584 583 return $fields;
585 584 }
586 585
@@ -590,132 +589,128 @@
590 589 * @since 1.0.0
591 590 * @package userswp
592 591 * @return array Account form default custom fields.
593 592 */
594 - public static function uwp_default_custom_fields_account(){
593 + public static function uwp_default_custom_fields_account() {
595 594
596 595 $fields = array();
597 596
598 597 $fields[] = array(
599 - 'form_type' => 'account',
600 - 'field_type' => 'text',
601 - 'data_type' => 'XVARCHAR',
602 - 'site_title' => __('First Name', 'userswp'),
603 - 'htmlvar_name' => 'first_name',
604 - 'default_value' => '',
605 - 'option_values' => '',
606 - 'is_default' => '1',
607 - 'is_public' => '1',
608 - 'is_active' => '1',
609 - 'is_required' => '1',
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',
610 609 'is_register_field' => '1',
611 - 'is_search_field' => '1',
612 - 'css_class' => 'uwp-half uwp-half-left',
610 + 'is_search_field' => '1',
613 611 );
614 612
615 613 $fields[] = array(
616 - 'form_type' => 'account',
617 - 'field_type' => 'text',
618 - 'data_type' => 'XVARCHAR',
619 - 'site_title' => __('Last Name', 'userswp'),
620 - 'htmlvar_name' => 'last_name',
621 - 'default_value' => '',
622 - 'option_values' => '',
623 - 'is_default' => '1',
624 - 'is_public' => '1',
625 - 'is_active' => '1',
626 - 'is_required' => '1',
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',
627 625 'is_register_field' => '1',
628 - 'is_search_field' => '1',
629 - 'css_class' => 'uwp-half uwp-half-right',
626 + 'is_search_field' => '1',
630 627 );
631 628
632 629 $fields[] = array(
633 - 'form_type' => 'account',
634 - 'field_type' => 'text',
635 - 'data_type' => 'XVARCHAR',
636 - 'site_title' => __('Username', 'userswp'),
637 - 'htmlvar_name' => 'username',
638 - 'default_value' => '',
639 - 'option_values' => '',
640 - 'is_default' => '1',
641 - 'is_public' => '1',
642 - 'is_active' => '1',
643 - 'is_required' => '1',
644 - 'is_register_field' => '1',
645 - 'is_search_field' => '1',
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',
646 643 'is_register_only_field' => '1',
647 644 );
648 645
649 646 $fields[] = array(
650 - 'form_type' => 'account',
651 - 'field_type' => 'text',
652 - 'data_type' => 'XVARCHAR',
653 - 'site_title' => __('Display Name', 'userswp'),
654 - 'htmlvar_name' => 'display_name',
655 - 'default_value' => '',
656 - 'option_values' => '',
657 - 'is_default' => '1',
658 - 'is_public' => '1',
659 - 'is_active' => '1',
660 - 'is_required' => '0',
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',
661 658 'is_register_field' => '0',
662 - 'is_search_field' => '1',
659 + 'is_search_field' => '1',
663 660 );
664 661
665 662 $fields[] = array(
666 - 'form_type' => 'account',
667 - 'field_type' => 'email',
668 - 'data_type' => 'XVARCHAR',
669 - 'site_title' => __('Email', 'userswp'),
670 - 'htmlvar_name' => 'email',
671 - 'default_value' => '',
672 - 'option_values' => '',
673 - 'is_default' => '1',
674 - 'is_active' => '1',
675 - 'is_required' => '1',
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',
676 673 'is_register_field' => '1',
677 - 'is_search_field' => '1',
674 + 'is_search_field' => '1',
678 675 );
679 676
680 -
681 677 $fields[] = array(
682 - 'form_type' => 'account',
683 - 'field_type' => 'textarea',
684 - 'data_type' => 'TEXT',
685 - 'site_title' => __('Bio', 'userswp'),
686 - 'htmlvar_name' => 'bio',
687 - 'default_value' => '',
688 - 'option_values' => '',
689 - 'is_default' => '1',
690 - 'is_active' => '1',
691 - 'is_public' => '1',
692 - 'is_required' => '1',
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',
693 689 'is_search_field' => '1',
694 - 'show_in' => array('[profile_side]', '[users]')
690 + 'show_in' => array( '[users]' ),
695 691 );
696 692
697 693 $fields[] = array(
698 - 'form_type' => 'account',
699 - 'field_type' => 'password',
700 - 'data_type' => 'XVARCHAR',
701 - 'site_title' => __('Password', 'userswp'),
702 - 'htmlvar_name' => 'password',
703 - 'default_value' => '',
704 - 'option_values' => '',
705 - 'is_default' => '1',
706 - 'is_active' => '1',
707 - 'is_required' => '1',
708 - 'is_register_field' => '1',
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',
709 705 'is_register_only_field' => '1',
710 - 'extra' => array(
711 - 'confirm_password' => '1'
712 - )
706 + 'extra' => array(
707 + 'confirm_password' => '1',
708 + ),
713 709 );
714 710
711 + $fields = apply_filters( 'uwp_default_custom_fields_account', $fields );
715 712
716 - $fields = apply_filters('uwp_default_custom_fields_account', $fields);
717 -
718 713 return $fields;
719 714 }
720 715
721 716 /**
@@ -724,9 +719,9 @@
724 719 * @since 1.0.0
725 720 * @package userswp
726 721 * @return void
727 722 */
728 - public static function uwp_flush_rewrite_rules() {
723 + public static function flush_rewrite_rules() {
729 724 flush_rewrite_rules();
730 725 }
731 726
732 727 /**
@@ -735,9 +730,9 @@
735 730 * @since 1.0.0
736 731 * @package userswp
737 732 * @return void
738 733 */
739 - public static function uwp_insert_form_extras() {
734 + public static function insert_form_extras( $form_id = 1 ) {
740 735 global $wpdb;
741 736 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
742 737
743 738 $fields = array();
@@ -742,61 +737,61 @@
742 737
743 738 $fields = array();
744 739
745 740 $fields[] = array(
746 - 'form_type' => 'register',
747 - 'field_type' => 'text',
748 - 'is_default' => '1',
749 - 'htmlvar_name' => 'uwp_account_first_name'
741 + 'form_type' => 'register',
742 + 'field_type' => 'text',
743 + 'is_default' => '0',
744 + 'htmlvar_name' => 'first_name',
750 745 );
751 746
752 747 $fields[] = array(
753 - 'form_type' => 'register',
754 - 'field_type' => 'text',
755 - 'is_default' => '1',
756 - 'htmlvar_name' => 'uwp_account_last_name'
748 + 'form_type' => 'register',
749 + 'field_type' => 'text',
750 + 'is_default' => '0',
751 + 'htmlvar_name' => 'last_name',
757 752 );
758 753
759 754 $fields[] = array(
760 - 'form_type' => 'register',
761 - 'field_type' => 'text',
762 - 'is_default' => '1',
763 - 'htmlvar_name' => 'uwp_account_username'
755 + 'form_type' => 'register',
756 + 'field_type' => 'text',
757 + 'is_default' => '1',
758 + 'htmlvar_name' => 'username',
764 759 );
765 760
766 761 $fields[] = array(
767 - 'form_type' => 'register',
768 - 'field_type' => 'email',
769 - 'is_default' => '1',
770 - 'htmlvar_name' => 'uwp_account_email'
762 + 'form_type' => 'register',
763 + 'field_type' => 'email',
764 + 'is_default' => '1',
765 + 'htmlvar_name' => 'email',
771 766 );
772 767
773 768 $fields[] = array(
774 - 'form_type' => 'register',
775 - 'field_type' => 'password',
776 - 'is_default' => '1',
777 - 'htmlvar_name' => 'uwp_account_password'
769 + 'form_type' => 'register',
770 + 'field_type' => 'password',
771 + 'is_default' => '0',
772 + 'htmlvar_name' => 'password',
778 773 );
779 774
780 -
781 - foreach ($fields as $field) {
782 - $last_order = $wpdb->get_var("SELECT MAX(sort_order) as last_order FROM " . $extras_table_name);
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 );
783 777 $sort_order = (int)$last_order + 1;
784 778 $wpdb->query(
785 779 $wpdb->prepare(
786 -
787 - "insert into " . $extras_table_name . " set
780 + 'insert into ' . $extras_table_name . ' set
788 781 form_type = %s,
789 782 field_type = %s,
790 783 is_default = %s,
791 784 site_htmlvar_name = %s,
792 - sort_order = %s",
785 + sort_order = %s,
786 + form_id = %s',
793 787 array(
794 788 $field['form_type'],
795 789 $field['field_type'],
796 790 $field['is_default'],
797 791 $field['htmlvar_name'],
798 - $sort_order
792 + $sort_order,
793 + $form_id,
799 794 )
800 795 )
801 796 );
802 797 }
@@ -801,13 +796,66 @@
801 796 );
802 797 }
803 798 }
804 799
805 - public static function uwp_automatic_upgrade(){
806 - $uwp_db_version = get_option('uwp_db_version');
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' );
807 809
808 810 if ( $uwp_db_version != USERSWP_VERSION ) {
809 - self::activate(is_plugin_active_for_network( 'userswp/userswp.php' ));
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 + $clean_title = sanitize_text_field( $reg_title );
843 + if ( $clean_title !== $reg_title ) {
844 + $settings['multiple_registration_forms'][ $key ]['title'] = $clean_title;
845 + $needs_update = true;
846 + }
847 + }
848 + }
849 + }
850 + }
851 +
852 + if ( $needs_update ) {
853 + update_option( 'uwp_settings', $settings );
854 + }
855 +
856 + // Run this function once.
857 + update_option( 'uwp_db_version', USERSWP_VERSION );
858 +
810 859 }
811 860 }
812 -
813 -}
861 +}