PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.29
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.29
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 / upgrade.php

upgrade.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.29, at upgrade.php

447 lines 12.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Upgrade related functions.
4 *
5 * @since 1.0.0
6 * @package UsersWP
7 */
8
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Adds default sorting options in user sorting table
17 */
18 function uwp_upgrade_1230(){
19 $updated = uwp_get_option( "user_sorting_updated" );
20 if ( isset($updated) && $updated > 0 ) {
21 return;
22 }
23
24 global $wpdb;
25 $user_sorting_table_name = uwp_get_table_prefix() . 'uwp_user_sorting';
26 $fields = array();
27
28 $fields['display_name_asc'] = array(
29 'data_type' => '',
30 'field_type' => 'text',
31 'site_title' => __('Display Name (A-Z)', 'userswp'),
32 'htmlvar_name' => 'display_name',
33 'field_icon' => 'fas fa-sort-alpha-up',
34 'sort' => 'asc',
35 'old_value' => 'alpha_asc',
36 );
37
38 $fields['display_name_desc'] = array(
39 'data_type' => '',
40 'field_type' => 'text',
41 'site_title' => __('Display Name (Z-A)', 'userswp'),
42 'htmlvar_name' => 'display_name',
43 'field_icon' => 'fas fa-sort-alpha-up',
44 'sort' => 'desc',
45 'old_value' => 'alpha_desc',
46 );
47
48 $fields['newer'] = array(
49 'data_type' => '',
50 'field_type' => 'newer',
51 'site_title' => __('Newer', 'userswp'),
52 'htmlvar_name' => 'newer',
53 'field_icon' => 'fas fa-calendar',
54 'sort' => 'asc',
55 'old_value' => 'newer',
56 );
57
58 $fields['older'] = array(
59 'data_type' => '',
60 'field_type' => 'older',
61 'site_title' => __('Older', 'userswp'),
62 'htmlvar_name' => 'older',
63 'field_icon' => 'fas fa-calendar',
64 'sort' => 'desc',
65 'old_value' => 'older',
66 );
67
68 $fields['first_name_asc'] = array(
69 'data_type' => '',
70 'field_type' => 'text',
71 'site_title' => __('First Name (A-Z)', 'userswp'),
72 'htmlvar_name' => 'first_name',
73 'field_icon' => 'fas fa-fa-sort-alpha-up',
74 'sort' => 'asc',
75 'old_value' => 'fname_asc',
76 );
77
78 $fields['first_name_desc'] = array(
79 'data_type' => '',
80 'field_type' => 'text',
81 'site_title' => __('First Name (Z-A)', 'userswp'),
82 'htmlvar_name' => 'first_name',
83 'field_icon' => 'fas fa-fa-sort-alpha-up',
84 'sort' => 'desc',
85 'old_value' => 'fname_desc',
86 );
87
88 $fields['last_name_asc'] = array(
89 'data_type' => '',
90 'field_type' => 'text',
91 'site_title' => __('Last Name (A-Z)', 'userswp'),
92 'htmlvar_name' => 'last_name',
93 'field_icon' => 'fas fa-fa-sort-alpha-up',
94 'sort' => 'asc',
95 'old_value' => 'lname_asc',
96 );
97
98 $fields['last_name_desc'] = array(
99 'data_type' => '',
100 'field_type' => 'text',
101 'site_title' => __('Last Name (Z-A)', 'userswp'),
102 'htmlvar_name' => 'last_name',
103 'field_icon' => 'fas fa-fa-sort-alpha-up',
104 'sort' => 'desc',
105 'old_value' => 'lname_desc',
106 );
107
108 $sort_order = 1;
109 $default_option = uwp_get_option('users_default_order_by', 'alpha_asc');
110
111 foreach ($fields as $field) {
112 if(isset($default_option) && $default_option == $field['old_value']){
113 $is_default = 1;
114 } else {
115 $is_default = 0;
116 }
117 $wpdb->query(
118 $wpdb->prepare(
119 "insert into " . $user_sorting_table_name . " set
120 field_type = %s,
121 site_title = %s,
122 htmlvar_name = %s,
123 field_icon = %s,
124 sort_order = %s,
125 is_default = %d,
126 sort = %s,
127 is_active = %d",
128 array(
129 $field['field_type'],
130 $field['site_title'],
131 $field['htmlvar_name'],
132 $field['field_icon'],
133 $sort_order,
134 $is_default,
135 $field['sort'],
136 1,
137 )
138 )
139 );
140 $sort_order++;
141 }
142
143 // set as updated
144 uwp_update_option( "user_sorting_updated", "1230" );
145 }
146
147 /**
148 * Change account fields to not have uwp_account_ prefix.
149 */
150 function uwp_upgrade_1200() {
151
152 // Change the users item page template content and backup the old content
153 $page_id = uwp_get_page_id( 'user_list_item_page' );
154 $updated = uwp_get_option( "user_list_page_updated" );
155 if ( $page_id && ! $updated ) {
156 $backup_content = get_post_meta( $page_id, 'uwp_1100_content' );
157 if ( ! $backup_content ) {
158 $content = get_post_field( 'post_content', $page_id );
159 if ( $content ) {
160 update_post_meta( $page_id, 'uwp_1100_content', $content );
161 wp_update_post( array( 'ID' => $page_id, 'post_content' => '[uwp_users_item]' ) );
162 uwp_update_option( "user_list_page_updated", "1100" );
163 }
164 }
165 }
166
167 // Convert tabs
168 uwp_upgrade_convert_tabs();
169
170 }
171
172 /**
173 * Convert v1.0 tabs to v1.2.
174 */
175 function uwp_upgrade_convert_tabs() {
176 $old_tabs = uwp_get_option( 'enable_profile_tabs' );
177
178 $updated = uwp_get_option( "user_profile_tabs_updated" );
179 $new_tabs = array();
180 if ( $old_tabs && ! $updated ) {
181
182 foreach ( $old_tabs as $tab ) {
183 $tab_data = array();
184 if ( $tab == 'posts' ) {
185 $tab_data = array(
186 'tab_type' => 'standard',
187 'tab_name' => __( 'Posts', 'userswp' ),
188 'tab_icon' => 'fas fa-info-circle',
189 'tab_key' => 'posts',
190 'tab_content' => ''
191 );
192 } elseif ( $tab == 'more_info' ) {
193 $tab_data = array(
194 'tab_type' => 'standard',
195 'tab_name' => __( 'More Info', 'userswp' ),
196 'tab_icon' => 'fas fa-info-circle',
197 'tab_key' => 'more_info',
198 'tab_content' => ''
199 );
200 } elseif ( $tab == 'comments' ) {
201 $tab_data = array(
202 'tab_type' => 'standard',
203 'tab_name' => __( 'Comments', 'userswp' ),
204 'tab_icon' => 'fas fa-comments',
205 'tab_key' => 'comments',
206 'tab_content' => ''
207 );
208 } elseif ( $tab == 'listings' ) {
209 $tab_data = array(
210 'tab_type' => 'standard',
211 'tab_name' => __( 'Listings', 'userswp' ),
212 'tab_icon' => 'fas fa-globe-americas',
213 'tab_key' => 'listings',
214 'tab_content' => ''
215 );
216 } elseif ( $tab == 'reviews' ) {
217 $tab_data = array(
218 'tab_type' => 'standard',
219 'tab_name' => __( 'Reviews', 'userswp' ),
220 'tab_icon' => 'fas fa-star',
221 'tab_key' => 'reviews',
222 'tab_content' => ''
223 );
224 } elseif ( $tab == 'favorites' ) {
225 $tab_data = array(
226 'tab_type' => 'standard',
227 'tab_name' => __( 'Favorites', 'userswp' ),
228 'tab_icon' => 'fas fa-heart',
229 'tab_key' => 'favorites',
230 'tab_content' => ''
231 );
232 } elseif ( $tab == 'activity' ) {
233 $tab_data = array(
234 'tab_type' => 'shortcode',
235 'tab_name' => __( 'Activity', 'userswp' ),
236 'tab_icon' => 'fas fa-cubes',
237 'tab_key' => 'activity',
238 'tab_content' => '[uwp_activity]'
239 );
240 } elseif ( $tab == 'downloads' ) {
241 $tab_data = array(
242 'tab_type' => 'standard',
243 'tab_name' => __( 'Downloads', 'userswp' ),
244 'tab_icon' => 'fas fa-download',
245 'tab_key' => 'downloads',
246 'tab_content' => '[uwp_edd_downloads]'
247 );
248 } elseif ( $tab == 'purchases' ) {
249 $tab_data = array(
250 'tab_type' => 'standard',
251 'tab_name' => __( 'Purchases', 'userswp' ),
252 'tab_icon' => 'fas fa-receipt',
253 'tab_key' => 'purchases',
254 'tab_content' => '[uwp_edd_purchases]'
255 );
256 } elseif ( $tab == 'followers' ) {
257 $tab_data = array(
258 'tab_type' => 'standard',
259 'tab_name' => __( 'Followers', 'userswp' ),
260 'tab_icon' => 'fas fa-chevron-circle-left',
261 'tab_key' => 'followers',
262 'tab_content' => '[uwp_followers]'
263 );
264 } elseif ( $tab == 'followers' ) {
265 $tab_data = array(
266 'tab_type' => 'standard',
267 'tab_name' => __( 'Following', 'userswp' ),
268 'tab_icon' => 'fas fa-chevron-circle-right',
269 'tab_key' => 'following',
270 'tab_content' => '[uwp_following]'
271 );
272 } elseif ( $tab == 'friends' ) {
273 $tab_data = array(
274 'tab_type' => 'standard',
275 'tab_name' => __( 'Friends', 'userswp' ),
276 'tab_icon' => 'fas fa-chevron-circle-right',
277 'tab_key' => 'friends',
278 'tab_content' => '[uwp_friends]'
279 );
280 } elseif ( $tab == 'mycred' ) {
281 $tab_data = array(
282 'tab_type' => 'standard',
283 'tab_name' => __( 'MyCred', 'userswp' ),
284 'tab_icon' => 'fas fa-star',
285 'tab_key' => 'mycred',
286 'tab_content' => '[uwp_mycred]'
287 );
288 } elseif ( $tab == 'products' ) {
289 $tab_data = array(
290 'tab_type' => 'standard',
291 'tab_name' => __( 'Products', 'userswp' ),
292 'tab_icon' => 'fas fa-info-circle',
293 'tab_key' => 'products',
294 'tab_content' => ''
295 );
296 } elseif ( $tab == 'orders' ) {
297 $tab_data = array(
298 'tab_type' => 'standard',
299 'tab_name' => __( 'Orders', 'userswp' ),
300 'tab_icon' => 'fas fa-info-circle',
301 'tab_key' => 'orders',
302 'tab_content' => ''
303 );
304 } elseif ( $tab == 'jobs' ) {
305 $tab_data = array(
306 'tab_type' => 'standard',
307 'tab_name' => __( 'Jobs', 'userswp' ),
308 'tab_icon' => 'fas fa-briefcase',
309 'tab_key' => 'jobs',
310 'tab_content' => ''
311 );
312 } elseif ( $tab == 'forums' ) {
313 $tab_data = array(
314 'tab_type' => 'standard',
315 'tab_name' => __( 'Topics', 'userswp' ),
316 'tab_icon' => 'fas fa-info-circle',
317 'tab_key' => 'topics',
318 'tab_content' => ''
319 );
320 uwp_profile_add_tabs( $tab_data ); // we are adding two here
321
322 $tab_data = array(
323 'tab_type' => 'standard',
324 'tab_name' => __( 'Replies', 'userswp' ),
325 'tab_icon' => 'fas fa-reply-all',
326 'tab_key' => 'replies',
327 'tab_content' => ''
328 );
329 }
330
331
332 if ( ! empty( $tab_data ) ) {
333 uwp_profile_add_tabs( $tab_data );
334 }
335 }
336
337 // set as updated
338 uwp_update_option( "user_profile_tabs_updated", "1200" );
339 }
340
341 }
342
343 /**
344 * Change country htmlvar name to uwp_country to prevent conflicts with location manager plugin.
345 */
346 function uwp_upgrade_12013() {
347 global $wpdb;
348
349 $default_field = 'country';
350 $replace_field = 'uwp_country';
351 $fields_table = $wpdb->prefix . 'uwp_form_fields';
352
353 $fields_results = $wpdb->get_results($wpdb->prepare("SELECT * FROM `$fields_table` WHERE `htmlvar_name` = '%s'",$default_field));
354 if( !empty($fields_results) && count($fields_results) > 0 ) {
355 $wpdb->update( $fields_table,
356 array( 'htmlvar_name' => $replace_field ),
357 array( 'htmlvar_name' => $default_field )
358 );
359 }
360
361 $uwp_usermeta_table = $wpdb->prefix . 'uwp_usermeta';
362
363 $usermeta_columns = $wpdb->get_col("SHOW COLUMNS FROM `$uwp_usermeta_table` LIKE '$default_field'");
364
365 if( !empty( $usermeta_columns ) && count($usermeta_columns) > 0 ) {
366 $wpdb->query("ALTER TABLE $uwp_usermeta_table CHANGE COLUMN $default_field $replace_field varchar(500) NOT NULL");
367 }
368 }
369
370 /**
371 * Add TOS and GDPR field in form builder if set in registration form setting.
372 */
373 function uwp_upgrade_1225() {
374 global $wpdb;
375 $fields = array();
376
377 $reg_tos = uwp_get_option( 'register_gdpr_page', false );
378 if ( isset( $reg_tos ) && $reg_tos > 0 ) {
379 $fields[] = array(
380 'form_type' => 'account',
381 'field_type' => 'checkbox',
382 'data_type' => 'TINYINT',
383 'site_title' => __( 'GDPR Policy', 'userswp' ),
384 'htmlvar_name' => 'register_gdpr',
385 'is_public' => '1',
386 'is_active' => '1',
387 'is_required' => '1',
388 'required_msg' => __( 'You must read and accept our GDPR policy.', 'userswp' ),
389 'is_register_field' => '1',
390 'is_register_only_field' => '1',
391 );
392 }
393
394 $reg_gdpr = uwp_get_option( 'register_terms_page', false );
395 if ( isset( $reg_gdpr ) && $reg_gdpr > 0 ) {
396 $fields[] = array(
397 'form_type' => 'account',
398 'field_type' => 'checkbox',
399 'data_type' => 'TINYINT',
400 'site_title' => __( 'Terms & Conditions', 'userswp' ),
401 'htmlvar_name' => 'register_tos',
402 'is_public' => '1',
403 'is_active' => '1',
404 'is_required' => '1',
405 'required_msg' => __( 'You must read and accept our terms and conditions.', 'userswp' ),
406 'is_register_field' => '1',
407 'is_register_only_field' => '1',
408 );
409 }
410
411 if($fields && count($fields) > 0){
412 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
413 $form_type = 'register';
414 $form_builder = new UsersWP_Form_Builder();
415
416 foreach ($fields as $field){
417 $site_htmlvar_name = $field['htmlvar_name'];
418 $field_type = $field['field_type'];
419
420 $last_order = $wpdb->get_var( "SELECT MAX(sort_order) as last_order FROM " . $extras_table_name );
421 $sort_order = (int) $last_order + 1;
422
423 $form_builder->admin_form_field_save( $field );
424
425 $check_html_variable = $wpdb->get_var($wpdb->prepare("select site_htmlvar_name from " . $extras_table_name . " where site_htmlvar_name = %s and form_type = %s ",
426 array($site_htmlvar_name, $form_type)));
427
428 if (!$check_html_variable) {
429 $wpdb->query(
430 $wpdb->prepare(
431 "insert into " . $extras_table_name . " set
432 form_type = %s,
433 field_type = %s,
434 site_htmlvar_name = %s,
435 sort_order = %s",
436 array(
437 $form_type,
438 $field_type,
439 $site_htmlvar_name,
440 $sort_order
441 )
442 )
443 );
444 }
445 }
446 }
447 }