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

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

2,755 lines 104.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Form related functions
4 *
5 * This class defines all code necessary to handle UsersWP forms like login. register etc.
6 *
7 * @since 1.0.0
8 * @author GeoDirectory Team <info@wpgeodirectory.com>
9 */
10 class UsersWP_Forms {
11
12 protected $generated_password;
13
14 /**
15 * Initialize UsersWP notices.
16 *
17 * @since 1.0.0
18 * @package userswp
19 *
20 * @return void
21 */
22 public function init_notices() {
23 global $uwp_notices;
24 $uwp_notices = array();
25 }
26
27 /**
28 * Handles all UsersWP forms.
29 *
30 * @since 1.0.0
31 * @package userswp
32 *
33 * @return void
34 */
35 public function handler()
36 {
37 global $uwp_notices;
38
39 ob_start();
40
41 $errors = null;
42 $message = null;
43 $redirect = false;
44 $processed = false;
45 $type = null;
46
47 $login_page_url = wp_login_url();
48
49 if (isset($_POST['uwp_register_nonce'])) {
50 $auto_login = uwp_get_option('uwp_registration_action', false);
51 $errors = $this->process_register($_POST, $_FILES);
52 if (!is_wp_error($errors)) {
53 $message = $errors;
54 }
55 $force_redirect = apply_filters('uwp_registration_force_redirect', false, $_POST, $_FILES);
56 if ($auto_login == 'auto_approve_login' || $force_redirect) {
57 $reg_redirect_page_id = uwp_get_option('register_redirect_to', '');
58 if(isset( $_REQUEST['redirect_to'] )){
59 $reg_redirect_to = esc_url($_REQUEST['redirect_to']);
60 } elseif ( isset($reg_redirect_page_id) && (int)$reg_redirect_page_id > 0) {
61 $reg_redirect_to = get_permalink($reg_redirect_page_id);
62 } else {
63 $reg_redirect_to = home_url('/');
64 }
65 $redirect = apply_filters('uwp_register_redirect', $reg_redirect_to);
66 }
67 $processed = true;
68 $type = 'register';
69 } elseif (isset($_POST['uwp_login_nonce'])) {
70 $errors = $this->process_login($_POST);
71 $redirect_page_id = uwp_get_option('login_redirect_to', -1);
72 if (isset($redirect_page_id) && (int)$redirect_page_id > 0) {
73 $redirect_to = get_permalink($redirect_page_id);
74 } elseif(isset( $_REQUEST['redirect_to'] ) && !empty($data['redirect_to'])){
75 $redirect_to = esc_url($_REQUEST['redirect_to']);
76 } else {
77 $redirect_to = home_url('/');
78 }
79 $redirect = apply_filters('uwp_login_redirect', $redirect_to);
80 $processed = true;
81 $type = 'login';
82 } elseif (isset($_POST['uwp_forgot_nonce'])) {
83 $errors = $this->process_forgot($_POST);
84 $message = __('Please check your email.', 'userswp');
85 $processed = true;
86 } elseif (isset($_POST['uwp_change_nonce'])) {
87 $errors = $this->process_change($_POST);
88 $message = __('Password changed successfully', 'userswp');
89 $processed = true;
90 } elseif (isset($_POST['uwp_reset_submit'])) {
91 $errors = $this->process_reset($_POST);
92 $message = sprintf(__('Password updated successfully. Please <a href="%s">login</a> with your new password', 'userswp'), $login_page_url);
93 $processed = true;
94 } elseif (isset($_POST['uwp_account_nonce'])) {
95 $errors = $this->process_account($_POST, $_FILES);
96 $message = __('Account updated successfully.', 'userswp');
97 $processed = true;
98 } elseif (isset($_POST['uwp_avatar_submit'])) {
99 $errors = $this->process_upload_submit($_POST, $_FILES, 'avatar');
100 if (!is_wp_error($errors)) {
101 $redirect = $errors;
102 }
103 $message = __('Avatar cropped successfully.', 'userswp');
104 $processed = true;
105 } elseif (isset($_POST['uwp_banner_submit'])) {
106 $errors = $this->process_upload_submit($_POST, $_FILES, 'banner');
107 if (!is_wp_error($errors)) {
108 $redirect = $errors;
109 }
110 $message = __('Banner cropped successfully.', 'userswp');
111 $processed = true;
112 } elseif (isset($_POST['uwp_avatar_crop'])) {
113 $errors = $this->process_image_crop($_POST, 'avatar', true);
114 if (!is_wp_error($errors)) {
115 $redirect = $errors;
116 }
117 $message = __('Avatar cropped successfully.', 'userswp');
118 $processed = true;
119 } elseif (isset($_POST['uwp_banner_crop'])) {
120 $errors = $this->process_image_crop($_POST, 'banner', true);
121 if (!is_wp_error($errors)) {
122 $redirect = $errors;
123 }
124 $message = __('Banner cropped successfully.', 'userswp');
125 $processed = true;
126 }
127
128 if ($processed) {
129 if (is_wp_error($errors)) {
130 echo '<div class="uwp-alert-error text-center">';
131 echo $errors->get_error_message();
132 echo '</div>';
133 } else {
134 if ($redirect) {
135 wp_safe_redirect($redirect);
136 exit();
137 } else {
138 echo '<div class="uwp-alert-success text-center">';
139 echo $message;
140 echo '</div>';
141 }
142 }
143 }
144
145 if($type){
146 $uwp_notices[] = array($type => ob_get_contents());
147 }else{
148 $uwp_notices[] = ob_get_contents();
149 }
150
151
152 ob_end_clean();
153
154 }
155
156 /**
157 * Displays UsersWP notices in forms.
158 *
159 * @since 1.0.0
160 * @package userswp
161 *
162 * @param string $type Form type
163 *
164 * @return void
165 */
166 public function display_notices($type) {
167 global $uwp_notices;
168
169 if (is_array($uwp_notices)) {
170 foreach ($uwp_notices as $notice) {
171
172 // If the notification is type specific then only output on that type
173 if(is_array($notice)){
174 foreach($notice as $key => $val){
175 if( $key == $type ){ echo $val; }
176 }
177 }else{
178 if (!empty($notice)) {
179 echo $notice;
180 }
181 }
182
183 }
184
185 }
186
187 if ($type == 'change') {
188 $user_id = get_current_user_id();
189 $password_nag = get_user_option('default_password_nag', $user_id);
190
191 if ($password_nag) {
192 $change_page = uwp_get_page_id('change_page', false);
193 $remove_nag_url = add_query_arg('uwp_remove_nag', 'yes', get_permalink($change_page));
194
195 if (isset($_GET['uwp_remove_nag']) && $_GET['uwp_remove_nag'] == 'yes') {
196 delete_user_meta( $user_id, 'default_password_nag' );
197 $message = sprintf(__('We have removed the system generated password warning for you. From this point forward you can continue to access our site as usual. To go to home page, <a href="%s">click here</a>.', 'userswp'), home_url('/'));
198 echo '<div class="uwp-alert-success text-center">';
199 echo $message;
200 echo '</div>';
201 } else {
202 $message = sprintf(__('<strong>Warning</strong>: You seems like you are using a system generated password. Please change the password in this page. If this is not a problem for you, you can remove this warning by <a href="%s">clicking here</a>.', 'userswp'), $remove_nag_url);
203 echo '<div class="uwp-alert-warning text-center">';
204 echo $message;
205 echo '</div>';
206 }
207 }
208 }
209 }
210
211 /**
212 * Processes register form submission.
213 *
214 * @since 1.0.0
215 * @package userswp
216 *
217 * @param array $data Submitted $_POST data
218 * @param array $files Submitted $_FILES data
219 *
220 * @return bool|WP_Error|string
221 */
222 public function process_register($data = array(), $files = array()) {
223
224 $errors = new WP_Error();
225 $file_obj = new UsersWP_Files();
226
227 if( ! isset( $data['uwp_register_nonce'] ) || ! wp_verify_nonce( $data['uwp_register_nonce'], 'uwp-register-nonce' ) ) {
228 return false;
229 }
230
231 if (!get_option('users_can_register')) {
232 $errors->add('register_disabled', __('<strong>ERROR</strong>: User registration is currently not allowed.', 'userswp'));
233 return $errors;
234 }
235
236 $reg_terms_page_id = uwp_get_option('register_terms_page', '');
237 $reg_terms_page_id = apply_filters('uwp_reg_terms_page_id', $reg_terms_page_id);
238 if (!empty($reg_terms_page_id)) {
239 if (!isset($data['agree_terms']) || $data['agree_terms'] != 'yes') {
240 $errors->add('accept_tos', __('<strong>ERROR</strong>: You must accept our terms and conditions.', 'userswp'));
241 return $errors;
242 }
243 }
244
245 do_action('uwp_before_validate', 'register');
246
247 $result = uwp_validate_fields($data, 'register');
248
249 $result = apply_filters('uwp_validate_result', $result, 'register', $data);
250
251 if (is_wp_error($result)) {
252 return $result;
253 }
254
255 $uploads_result = $file_obj->uwp_validate_uploads($files, 'register');
256
257 if (is_wp_error($uploads_result)) {
258 return $uploads_result;
259 }
260
261 do_action('uwp_after_validate', 'register');
262
263 $result = array_merge( $result, $uploads_result );
264
265 $error_code = $errors->get_error_code();
266 if (!empty($error_code)) {
267 return $errors;
268 }
269
270 if (isset($result['password']) && !empty($result['password'])) {
271 $password = $result['password'];
272 $generated_password = false;
273 } else {
274 $password = wp_generate_password();
275 $this->generated_password = $password;
276 $generated_password = true;
277 }
278
279 $first_name = "";
280 if (isset($result['uwp_account_first_name']) && !empty($result['uwp_account_first_name'])) {
281 $first_name = $result['uwp_account_first_name'];
282 }
283
284 $last_name = "";
285 if (isset($result['uwp_account_last_name']) && !empty($result['uwp_account_last_name'])) {
286 $last_name = $result['uwp_account_last_name'];
287 }
288
289 if (isset($result['uwp_account_display_name']) && !empty($result['uwp_account_display_name'])) {
290 $display_name = $result['uwp_account_display_name'];
291 } else {
292 if (!empty($first_name) || !empty($last_name)) {
293 $display_name = $first_name . ' ' . $last_name;
294 } else {
295 $display_name = $result['uwp_account_username'];
296 }
297 }
298
299 $description = "";
300 if (isset($result['uwp_account_bio']) && !empty($result['uwp_account_bio'])) {
301 $description = $result['uwp_account_bio'];
302 }
303
304
305 $args = array(
306 'user_login' => $result['uwp_account_username'],
307 'user_email' => $result['uwp_account_email'],
308 'user_pass' => $password,
309 'display_name' => $display_name,
310 'first_name' => $first_name,
311 'last_name' => $last_name,
312 'description' => $description
313 );
314
315 $user_id = wp_insert_user( $args );
316
317 if (!$user_id) {
318 $errors->add('registerfail', sprintf(__('<strong>Error</strong>: Something went wrong.', 'userswp'), get_option('admin_email')));
319 return $errors;
320 }
321
322 $result = apply_filters('uwp_before_extra_fields_save', $result, 'register', $user_id);
323
324 $save_result = $this->uwp_save_user_extra_fields($user_id, $result, 'register');
325
326 $save_result = apply_filters('uwp_after_extra_fields_save', $save_result, $result, 'register', $user_id);
327
328 if (is_wp_error($save_result)) {
329 return $save_result;
330 }
331
332 if (!$save_result) {
333 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp'));
334 }
335
336 $error_code = $errors->get_error_code();
337 if (!empty($error_code)) {
338 return $errors;
339 }
340
341 do_action('uwp_after_custom_fields_save', 'register', $data, $result, $user_id);
342
343 $reg_action = uwp_get_option('uwp_registration_action', false);
344
345 if ($reg_action == 'require_email_activation' && !$generated_password) {
346
347 $email = new UsersWP_Mails();
348 $send_result = $email->send( 'activate', $user_id );
349
350 if (!$send_result) {
351 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong when sending email. Please contact site admin.', 'userswp'));
352 }
353 } else {
354 $email = new UsersWP_Mails();
355 $send_result = $email->send( 'register', $user_id );
356
357 if (!$send_result) {
358 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong when sending email. Please contact site admin.', 'userswp'));
359 }
360 }
361
362 if ($reg_action != 'require_admin_review') {
363 $register_admin_notify = uwp_get_option('register_admin_notify', '');
364 if ($register_admin_notify == '1') {
365 $admin_register_send_result = $email->send_admin_email('register_admin', $user_id);
366 if (is_wp_error($admin_register_send_result)) {
367 return $admin_register_send_result;
368 }
369 }
370
371 }
372
373
374 $error_code = $errors->get_error_code();
375 if (!empty($error_code)) {
376 return $errors;
377 }
378
379 if ($reg_action == 'auto_approve_login') {
380 $res = wp_signon(
381 array(
382 'user_login' => $result['uwp_account_username'],
383 'user_password' => $password,
384 'remember' => false
385 )
386 );
387
388 if (is_wp_error($res)) {
389 $errors->add('invalid_userorpass', __('<strong>Error</strong>: Invalid username or Password.', 'userswp'));
390 return $errors;
391 } else {
392 $reg_redirect_page_id = uwp_get_option('register_redirect_to', '');
393 if(isset( $_REQUEST['redirect_to'] )) {
394 $reg_redirect_to = esc_url($_REQUEST['redirect_to']);
395 } elseif (empty($reg_redirect_page_id)) {
396 $reg_redirect_to = home_url('/');
397 } else {
398 $reg_redirect_to = get_permalink($reg_redirect_page_id);
399 }
400 $redirect = apply_filters('uwp_register_redirect', $reg_redirect_to);
401 wp_redirect($redirect);
402 exit();
403 }
404 } else {
405 if ($reg_action == 'require_email_activation') {
406 global $wp;
407 $resend_link = uwp_current_page_url();
408 $resend_link = add_query_arg(
409 array(
410 'user_id' => $user_id,
411 'action' => 'uwp_resend',
412 '_nonce' => wp_create_nonce('uwp_resend'),
413 ),
414 $resend_link
415 );
416 return sprintf(__('An email has been sent to your registered email address. Please click the activation link to proceed. <a href="%s">Resend</a>.', 'userswp'), $resend_link);
417 } elseif ($reg_action == 'require_admin_review' && defined('UWP_MOD_VERSION')) {
418 update_user_meta( $user_id, 'uwp_mod', '1' );
419
420 $email = new UsersWP_Mails();
421 $send_result = $email->send( 'mod_pending', $user_id );
422 $user_data = get_user_by('id', $user_id);
423 $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors);
424 if (is_wp_error($send_result)) {
425 return $send_result;
426 }
427
428 $admin_send_result = $email->send_admin_email('mod_admin', $user_id);
429 if (is_wp_error($admin_send_result)) {
430 return $admin_send_result;
431 }
432
433 return __('Your account is under moderation. We will email you once its approved.', 'userswp');
434 } else {
435
436 $login_page_url = wp_login_url();
437
438 if ($generated_password) {
439 return sprintf(__('Account registered successfully. A password has been generated and mailed to your registered Email ID. Please login <a href="%s">here</a>.', 'userswp'), $login_page_url);
440 } else {
441 return sprintf(__('Account registered successfully. Please login <a href="%s">here</a>', 'userswp'), $login_page_url);
442 }
443 }
444 }
445
446
447 }
448
449 /**
450 * Processes login form submission.
451 *
452 * @since 1.0.0
453 * @package userswp
454 *
455 * @param array $data Submitted $_POST data
456 *
457 * @return bool|WP_Error|string
458 */
459 public function process_login($data) {
460
461 $errors = new WP_Error();
462
463 if( ! isset( $data['uwp_login_nonce'] ) || ! wp_verify_nonce( $data['uwp_login_nonce'], 'uwp-login-nonce' ) ) {
464 return false;
465 }
466
467 do_action('uwp_before_validate', 'login');
468
469 $result = uwp_validate_fields($data, 'login');
470
471 $result = apply_filters('uwp_validate_result', $result, 'login', $data);
472
473 if (is_wp_error($result)) {
474 return $result;
475 }
476
477 do_action('uwp_after_validate', 'login');
478
479 if (isset($data['remember_me']) && $data['remember_me'] == 'forever') {
480 $remember_me = true;
481 } else {
482 $remember_me = false;
483 }
484
485 remove_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
486
487 $res = wp_signon(
488 array(
489 'user_login' => $result['uwp_login_username'],
490 'user_password' => $result['password'],
491 'remember' => $remember_me
492 )
493 );
494
495 add_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
496
497 if (is_wp_error($res)) {
498 $errors->add('invalid_userorpass', __('<strong>Error</strong>: Invalid username or Password.', 'userswp'));
499 return $errors;
500 } else {
501 $redirect_page_id = uwp_get_option('login_redirect_to', -1);
502 if (isset($_REQUEST['redirect_to']) && !empty($_REQUEST['redirect_to'])) {
503 $redirect_to = esc_url($_REQUEST['redirect_to']);
504 } elseif (isset($data['redirect_to']) && !empty($data['redirect_to'])) {
505 $redirect_to = esc_url($data['redirect_to']);
506 } elseif (isset($redirect_page_id) && (int)$redirect_page_id > 0) {
507 $redirect_to = get_permalink($redirect_page_id);
508 } else {
509 if ( current_user_can('manage_options') ) {
510 $redirect_to = admin_url();
511 } else {
512 $redirect_to = home_url('/');
513 }
514 }
515
516 $redirect_to = apply_filters('uwp_login_redirect', $redirect_to);
517 wp_redirect($redirect_to);
518 exit();
519 }
520 }
521
522 /**
523 * Processes forgot password form submission.
524 *
525 * @since 1.0.0
526 * @package userswp
527 *
528 * @param array $data Submitted $_POST data
529 *
530 * @return bool|WP_Error|string
531 */
532 public function process_forgot($data) {
533
534 $errors = new WP_Error();
535
536 if( ! isset( $data['uwp_forgot_nonce'] ) || ! wp_verify_nonce( $data['uwp_forgot_nonce'], 'uwp-forgot-nonce' ) ) {
537 return false;
538 }
539
540 do_action('uwp_before_validate', 'forgot');
541
542 $result = uwp_validate_fields($data, 'forgot');
543
544 $result = apply_filters('uwp_validate_result', $result, 'forgot', $data);
545
546 if (is_wp_error($result)) {
547 return $result;
548 }
549
550 do_action('uwp_after_validate', 'forgot');
551
552
553 $user_data = get_user_by('email', $data['uwp_forgot_email']);
554
555 // make sure user account is active before account reset
556 $mod_value = get_user_meta( $user_data->ID, 'uwp_mod', true );
557 if ($mod_value == 'email_unconfirmed') {
558 $errors->add('activate_account', __('<strong>Error</strong>: Your account is not activated yet. Please activate your account first.', 'userswp'));
559 }
560
561 $error_code = $errors->get_error_code();
562 if (!empty($error_code)) {
563 return $errors;
564 }
565
566 $email = new UsersWP_Mails();
567 $send_result = $email->send( 'forgot', $user_data->ID );
568
569 $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors);
570 if (is_wp_error($send_result)) {
571 return $send_result;
572 }
573
574 return true;
575 }
576
577 /**
578 * Processes change password form submission.
579 *
580 * @since 1.0.0
581 * @package userswp
582 *
583 * @param array $data Submitted $_POST data
584 *
585 * @return bool|WP_Error|string
586 */
587 public function process_change($data) {
588
589 $errors = new WP_Error();
590
591 if( ! isset( $data['uwp_change_nonce'] ) || ! wp_verify_nonce( $data['uwp_change_nonce'], 'uwp-change-nonce' ) ) {
592 return false;
593 }
594
595 do_action('uwp_before_validate', 'change');
596
597 $result = uwp_validate_fields($data, 'change');
598
599 $result = apply_filters('uwp_validate_result', $result, 'change', $data);
600
601 if (is_wp_error($result)) {
602 return $result;
603 }
604
605 do_action('uwp_after_validate', 'change');
606
607 $user_data = get_user_by('id', get_current_user_id());
608
609 if (is_wp_error($user_data)) {
610 return $user_data;
611 }
612
613 $email = new UsersWP_Mails();
614 $send_result = $email->send( 'change', $user_data->ID );
615
616 $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors);
617 if (is_wp_error($send_result)) {
618 return $send_result;
619 }
620
621 wp_set_password( $data['uwp_change_password'], $user_data->ID );
622 wp_set_auth_cookie( $user_data->ID, false);
623
624 return true;
625 }
626
627 /**
628 * Processes reset password form submission.
629 *
630 * @since 1.0.0
631 * @package userswp
632 *
633 * @param array $data Submitted $_POST data
634 *
635 * @return bool|WP_Error|string
636 */
637 public function process_reset($data) {
638
639 $errors = new WP_Error();
640
641 if( ! isset( $data['uwp_reset_nonce'] ) || ! wp_verify_nonce( $data['uwp_reset_nonce'], 'uwp-reset-nonce' ) ) {
642 return false;
643 }
644
645 do_action('uwp_before_validate', 'reset');
646
647 $result = uwp_validate_fields($data, 'reset');
648
649 $result = apply_filters('uwp_validate_result', $result, 'reset', $data);
650
651 if (is_wp_error($result)) {
652 return $result;
653 }
654
655 do_action('uwp_after_validate', 'reset');
656
657 $login = $data['uwp_reset_username'];
658 $key = $data['uwp_reset_key'];
659 $user_data = check_password_reset_key( $key, $login );
660
661 if (is_wp_error($user_data)) {
662 return $user_data;
663 }
664
665 $email = new UsersWP_Mails();
666 $send_result = $email->send( 'reset', $user_data->ID );
667
668 $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors);
669 if (is_wp_error($send_result)) {
670 return $send_result;
671 }
672
673 wp_set_password( $data['uwp_reset_password'], $user_data->ID );
674
675 return true;
676 }
677
678
679 /**
680 * Modifies the mail subject based on the admin notification type.
681 *
682 * @since 1.0.0
683 * @package userswp
684 * @subpackage userswp/includes
685 * @param string $subject Unmodified mail subject.
686 * @param string $type Notification type.
687 * @return string Modified mail subject.
688 */
689 public function init_mail_subject($subject, $type) {
690 switch ($type) {
691 case "register":
692 $subject = uwp_get_option('registration_success_email_subject', '');
693 break;
694 case "activate":
695 $subject = uwp_get_option('registration_activate_email_subject', '');
696 break;
697 case "forgot":
698 $subject = uwp_get_option('forgot_password_email_subject', '');
699 break;
700 case "reset":
701 $subject = uwp_get_option('reset_password_email_subject', '');
702 break;
703 case "change":
704 $subject = uwp_get_option('change_password_email_subject', '');
705 break;
706 case "account":
707 $subject = uwp_get_option('account_update_email_subject', '');
708 break;
709 }
710 return $subject;
711 }
712
713 /**
714 * Modifies the mail content based on the admin notification type.
715 *
716 * @since 1.0.0
717 * @package userswp
718 * @subpackage userswp/includes
719 * @param string $content Unmodified mail content.
720 * @param string $type Notification type.
721 * @return string Modified mail content.
722 */
723 public function init_mail_content($content, $type) {
724 switch ($type) {
725 case "register":
726 $content = uwp_get_option('registration_success_email_content', '');
727 break;
728 case "activate":
729 $content = uwp_get_option('registration_activate_email_content', '');
730 break;
731 case "forgot":
732 $content = uwp_get_option('forgot_password_email_content', '');
733 break;
734 case "reset":
735 $content = uwp_get_option('reset_password_email_content', '');
736 break;
737 case "change":
738 $content = uwp_get_option('change_password_email_content', '');
739 break;
740 case "account":
741 $content = uwp_get_option('account_update_email_content', '');
742 break;
743 }
744 return $content;
745 }
746
747 /**
748 * Modifies the mail extras based on the notification type.
749 *
750 * @since 1.0.0
751 * @package userswp
752 * @subpackage userswp/includes
753 * @param string $extras Unmodified mail extras.
754 * @param string $type Notification type.
755 * @return string Modified mail extras.
756 */
757 public function init_mail_extras($extras, $type, $user_id) {
758 switch ($type) {
759 case "activate":
760 $extras = $this->generate_activate_message($user_id);
761 break;
762 case "register":
763 $extras = $this->generate_register_message($user_id);
764 break;
765 case "forgot":
766 $extras = $this->generate_forgot_message($user_id);
767 }
768 return $extras;
769 }
770
771 /**
772 * Modifies the admin mail subject based on the admin notification type.
773 *
774 * @since 1.0.0
775 * @package userswp
776 * @subpackage userswp/includes
777 * @param string $subject Unmodified admin mail subject.
778 * @param string $type Admin notification type.
779 * @return string Modified admin mail subject.
780 */
781 public function init_admin_mail_subject($subject, $type) {
782 switch ($type) {
783 case "register_admin":
784 $subject = uwp_get_option('registration_success_email_subject_admin', '');
785 break;
786 }
787 return $subject;
788 }
789
790 /**
791 * Modifies the admin mail content based on the admin notification type.
792 *
793 * @since 1.0.0
794 * @package userswp
795 * @subpackage userswp/includes
796 * @param string $content Unmodified admin mail content.
797 * @param string $type Admin notification type.
798 * @return string Modified admin mail content.
799 */
800 public function init_admin_mail_content($content, $type) {
801 switch ($type) {
802 case "register_admin":
803 $content = uwp_get_option('registration_success_email_content_admin', '');
804 break;
805 }
806 return $content;
807 }
808
809 /**
810 * Modifies the admin mail extras based on the notification type.
811 *
812 * @since 1.0.0
813 * @package userswp
814 * @subpackage userswp/includes
815 * @param string $extras Unmodified mail extras.
816 * @param string $type Notification type.
817 * @return string Modified mail extras.
818 */
819 public function init_admin_mail_extras($extras, $type, $user_id) {
820 switch ($type) {
821 case "register_admin":
822 $user_data = get_userdata($user_id);
823 $extras = __('<p><b>' . __('User Information :', 'userswp') . '</b></p>
824 <p>' . __('First Name:', 'userswp') . ' ' . $user_data->first_name . '</p>
825 <p>' . __('Last Name:', 'userswp') . ' ' . $user_data->last_name . '</p>
826 <p>' . __('Username:', 'userswp') . ' ' . $user_data->user_login . '</p>
827 <p>' . __('Email:', 'userswp') . ' ' . $user_data->user_email . '</p>');
828 break;
829 }
830 return $extras;
831 }
832
833 /**
834 * Generates activate email message.
835 *
836 * @since 1.0.0
837 * @package userswp
838 *
839 * @param int $user_id User ID.
840 *
841 * @return bool|string Message.
842 */
843 public function generate_activate_message($user_id) {
844
845 $user_data = get_userdata($user_id);
846 global $wpdb;
847 $key = wp_generate_password( 20, false );
848 do_action( 'uwp_activation_key', $user_data->user_login, $key );
849
850 global $wp_hasher;
851 if ( empty( $wp_hasher ) ) {
852 require_once ABSPATH . 'wp-includes/class-phpass.php';
853 $wp_hasher = new PasswordHash( 8, true );
854 }
855 $hashed = $wp_hasher->HashPassword( $key );
856 $wpdb->update( $wpdb->users, array( 'user_activation_key' => time().":".$hashed ), array( 'user_login' => $user_data->user_login ) );
857 update_user_meta( $user_id, 'uwp_mod', 'email_unconfirmed' );
858 $message = __('To activate your account, visit the following address:', 'userswp') . "\r\n\r\n";
859 $act_url = add_query_arg(
860 array(
861 'uwp_activate' => 'yes',
862 'key' => $key,
863 'login' => $user_data->user_login
864 ),
865 site_url()
866 );
867
868 $message .= "<a href='".$act_url."' target='_blank'>".$act_url."</a>" . "\r\n";
869
870 $activate_message = __('<p><b>' . __('Please activate your account :', 'userswp') . '</b></p>
871 <p>' . $message . '</p>');
872
873 return $activate_message;
874
875 }
876
877 /**
878 * Generates register email message.
879 *
880 * @since 1.0.0
881 * @package userswp
882 *
883 * @param int $user_id User ID.
884 *
885 * @return bool|string Message.
886 */
887 public function generate_register_message($user_id) {
888
889 $user_data = get_userdata($user_id);
890 if(isset($this->generated_password) && !empty($this->generated_password)) {
891 if(!uwp_get_option('change_disable_password_nag')) {
892 update_user_meta($user_id, 'default_password_nag', true); //Set up the Password change nag.
893 }
894 $message_pass = $this->generated_password;
895 $this->generated_password = false;
896 } else {
897 $message_pass = __("Password you entered", 'userswp');
898 }
899 $message = __('<p><b>' . __('Your login Information :', 'userswp') . '</b></p>
900 <p>' . __('Username:', 'userswp') . ' ' . $user_data->user_login . '</p>
901 <p>' . __('Password:', 'userswp') . ' ' . $message_pass . '</p>');
902
903 return $message;
904
905 }
906
907 /**
908 * Generates forgot password email message.
909 *
910 * @since 1.0.0
911 * @package userswp
912 *
913 * @param int $user_id User ID.
914 *
915 * @return bool|string Message.
916 */
917 public function generate_forgot_message($user_id) {
918
919 $user_data = get_userdata($user_id);
920 global $wpdb, $wp_hasher;
921
922 $allow = apply_filters('allow_password_reset', true, $user_data->ID);
923 if ( ! $allow )
924 return false;
925 else if ( is_wp_error($allow) )
926 return false;
927
928 $as_password = apply_filters('uwp_forgot_message_as_password', false);
929
930 if ($as_password) {
931 $new_pass = wp_generate_password(12, false);
932 wp_set_password($new_pass, $user_data->ID);
933 if(!uwp_get_option('change_disable_password_nag')) {
934 update_user_meta($user_data->ID, 'default_password_nag', true); //Set up the Password change nag.
935 }
936 $message = '<p><b>' . __('Your login Information :', 'userswp') . '</b></p>';
937 $message .= '<p>' . sprintf(__('Username: %s', 'userswp'), $user_data->user_login) . "</p>";
938 $message .= '<p>' . sprintf(__('Password: %s', 'userswp'), $new_pass) . "</p>";
939
940 } else {
941 $key = wp_generate_password( 20, false );
942 do_action( 'retrieve_password_key', $user_data->user_login, $key );
943
944 if ( empty( $wp_hasher ) ) {
945 require_once ABSPATH . 'wp-includes/class-phpass.php';
946 $wp_hasher = new PasswordHash( 8, true );
947 }
948 $hashed = $wp_hasher->HashPassword( $key );
949 $wpdb->update( $wpdb->users, array( 'user_activation_key' => time().":".$hashed ), array( 'user_login' => $user_data->user_login ) );
950 $message = '<p>' .__('You have requested to reset your password for the following account:', 'userswp') . "</p>";
951 $message .= home_url( '/' ) . "</p>";
952 $message .= '<p>' .sprintf(__('Username: %s', 'userswp'), $user_data->user_login) . "</p>";
953 $message .= '<p>' .__('If this was by mistake, just ignore this email and nothing will happen.', 'userswp') . "</p>";
954 $message .= '<p>' .__('To reset your password, click the following link and follow the instructions.', 'userswp') . "</p>";
955 $message = apply_filters('uwp_forgot_password_message', $message, $user_data);
956 $reset_page = uwp_get_page_id('reset_page', false);
957 if ($reset_page) {
958 $reset_link = add_query_arg( array(
959 'key' => $key,
960 'login' => rawurlencode($user_data->user_login),
961 ), get_permalink($reset_page) );
962 $message .= "<a href='".$reset_link."' target='_blank'>".$reset_link."</a>" . "\r\n";
963 } else {
964 $message .= site_url("reset?key=$key&login=" . rawurlencode($user_data->user_login), 'login') . "\r\n";
965 }
966 }
967
968
969 return $message;
970
971 }
972
973 /**
974 * Processes account form submission.
975 *
976 * @since 1.0.0
977 * @package userswp
978 *
979 * @param array $data Submitted $_POST data
980 * @param array $files Submitted $_FILES data
981 *
982 * @return bool|WP_Error|string
983 */
984 public function process_account($data = array(), $files = array()) {
985
986 $file_obj = new UsersWP_Files();
987
988 $current_user_id = get_current_user_id();
989 if (!$current_user_id) {
990 return false;
991 }
992
993 $errors = new WP_Error();
994
995 if( ! isset( $data['uwp_account_nonce'] ) || ! wp_verify_nonce( $data['uwp_account_nonce'], 'uwp-account-nonce' ) ) {
996 return false;
997 }
998
999 do_action('uwp_before_validate', 'account');
1000
1001 $result = uwp_validate_fields($data, 'account');
1002
1003 $result = apply_filters('uwp_validate_result', $result, 'account', $data);
1004
1005 if (is_wp_error($result)) {
1006 return $result;
1007 }
1008
1009 $uploads_result = $file_obj->uwp_validate_uploads($files, 'account');
1010
1011 if (is_wp_error($uploads_result)) {
1012 return $uploads_result;
1013 }
1014
1015 do_action('uwp_after_validate', 'account');
1016
1017 //unset if value is empty for files
1018 foreach ($uploads_result as $upload_file_key => $upload_file_value) {
1019 if (empty($upload_file_value)) {
1020 unset($uploads_result[$upload_file_key]);
1021 }
1022 }
1023
1024 $result = array_merge( $result, $uploads_result );
1025
1026
1027 $args = array(
1028 'ID' => $current_user_id
1029 );
1030
1031 if (isset($result['uwp_account_email'])) {
1032 $args['user_email'] = $result['uwp_account_email'];
1033 }
1034
1035 if (isset($result['uwp_account_first_name']) && isset($result['uwp_account_last_name'])) {
1036 $args['display_name'] = $result['uwp_account_first_name'] . ' ' . $result['uwp_account_last_name'];
1037 }
1038
1039 if (isset($result['uwp_account_first_name'])) {
1040 $args['first_name'] = $result['uwp_account_first_name'];
1041 }
1042
1043 if (isset($result['uwp_account_last_name'])) {
1044 $args['last_name'] = $result['uwp_account_last_name'];
1045 }
1046
1047 if (isset($result['uwp_account_bio'])) {
1048 $args['description'] = $result['uwp_account_bio'];
1049 }
1050
1051 if (isset($result['uwp_account_display_name']) && !empty($result['uwp_account_display_name'])) {
1052 $args['display_name'] = $result['uwp_account_display_name'];
1053 }
1054
1055 if (isset($result['password'])) {
1056 $args['user_pass'] = $result['password'];
1057 }
1058
1059 $user_id = wp_update_user( $args );
1060
1061 if (!$user_id) {
1062 $errors->add('registerfail', sprintf(__('<strong>Error</strong>: Something went wrong.', 'userswp'), get_option('admin_email')));
1063 return $errors;
1064 }
1065
1066 $res = $this->uwp_save_user_extra_fields($user_id, $result, 'account');
1067
1068 if (!$res) {
1069 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp'));
1070 }
1071
1072 $error_code = $errors->get_error_code();
1073 if (!empty($error_code)) {
1074 return $errors;
1075 }
1076
1077
1078 if (uwp_get_option('enable_account_update_notification') == '1') {
1079 $user_data = get_user_by('id', $user_id);
1080
1081 $email = new UsersWP_Mails();
1082 $send_result = $email->send( 'account', $user_data->ID );
1083
1084 $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors);
1085 if (is_wp_error($send_result)) {
1086 return $send_result;
1087 }
1088
1089 }
1090
1091 return true;
1092
1093 }
1094
1095 /**
1096 * Processes avatar and banner uploads form submission.
1097 *
1098 * @since 1.0.0
1099 * @package userswp
1100 *
1101 * @param array $data Submitted $_POST data
1102 * @param array $files Submitted $_FILES data
1103 *
1104 * @return bool|WP_Error|string File url to crop.
1105 */
1106 public function process_upload_submit($data = array(), $files = array(), $type = 'avatar') {
1107
1108 $file_obj = new UsersWP_Files();
1109
1110 $current_user_id = get_current_user_id();
1111 if (!$current_user_id) {
1112 return false;
1113 }
1114
1115 if( ! isset( $data['uwp_upload_nonce'] ) || ! wp_verify_nonce( $data['uwp_upload_nonce'], 'uwp-upload-nonce' ) ) {
1116 return false;
1117 }
1118
1119 do_action('uwp_before_validate', $type);
1120
1121 $result = $file_obj->uwp_validate_uploads($files, $type);
1122
1123 $result = apply_filters('uwp_validate_result', $result, $type, $data);
1124
1125 if (is_wp_error($result)) {
1126 return $result;
1127 }
1128
1129 $profile_url = uwp_build_profile_tab_url($current_user_id);
1130
1131 $url = add_query_arg(
1132 array(
1133 'uwp_crop' => $result['uwp_'.$type.'_file'],
1134 'type' => $type
1135 ),
1136 $profile_url);
1137
1138 return $url;
1139
1140 }
1141
1142 /**
1143 * Processes avatar and banner uploads image crop.
1144 *
1145 * @since 1.0.0
1146 * @since 1.0.12 New param $unlink_prev_img introduced.
1147 * @package userswp
1148 *
1149 * @param array $data Submitted $_POST data
1150 * @param string $type Image type. Default 'avatar'.
1151 * @param bool $unlink_prev_img True to remove previous image. Default false;
1152 *
1153 * @return bool|WP_Error|string Profile url.
1154 */
1155 public function process_image_crop($data = array(), $type = 'avatar', $unlink_prev_img = false) {
1156
1157 if (!is_user_logged_in()) {
1158 return false;
1159 }
1160
1161 // If is current user's profile (profile.php)
1162 if ( is_admin() && defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE ) {
1163 $user_id = get_current_user_id();
1164 // If is another user's profile page
1165 } elseif (is_admin() && ! empty($_GET['user_id']) && is_numeric($_GET['user_id']) ) {
1166 $user_id = $_GET['user_id'];
1167 // Otherwise something is wrong.
1168 } else {
1169 $user_id = get_current_user_id();
1170 }
1171 $image_url = $data['uwp_crop'];
1172
1173 $errors = new WP_Error();
1174 if (empty($image_url)) {
1175 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp'));
1176 }
1177
1178 $error_code = $errors->get_error_code();
1179 if (!empty($error_code)) {
1180 return $errors;
1181 }
1182
1183 if ($image_url) {
1184 if ($type == 'avatar') {
1185 $full_width = apply_filters('uwp_avatar_image_width', 150);
1186 } else {
1187 $full_width = apply_filters('uwp_banner_image_width', uwp_get_option('profile_banner_width', 1000));
1188 }
1189
1190 $image_url = esc_url($image_url);
1191 add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
1192 $uploads = wp_upload_dir();
1193 remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
1194 $upload_url = $uploads['baseurl'];
1195 $upload_path = $uploads['basedir'];
1196 $image_url = str_replace($upload_url, $upload_path, $image_url);
1197 $ext = pathinfo($image_url, PATHINFO_EXTENSION); // to get extension
1198 $name =pathinfo($image_url, PATHINFO_FILENAME); //file name without extension
1199 $thumb_image_name = $name.'_uwp_'.$type.'_thumb'.'.'.$ext;
1200 $thumb_image_location = str_replace($name.'.'.$ext, $thumb_image_name, $image_url);
1201 //Get the new coordinates to crop the image.
1202 $x = $data["x"];
1203 $y = $data["y"];
1204 $w = $data["w"];
1205 $h = $data["h"];
1206 //Scale the image based on cropped width setting
1207 $scale = $full_width/$w;
1208 //$scale = 1; // no scaling
1209 $cropped = uwp_resizeThumbnailImage($thumb_image_location, $image_url,$x, $y, $w, $h,$scale);
1210 $cropped = str_replace($upload_path, $upload_url, $cropped);
1211
1212 // Remove previous avatar/banner
1213 $unlink_img = '';
1214 if ($unlink_prev_img) {
1215 if ($type == 'avatar') {
1216 $previous_img = uwp_get_usermeta($user_id, 'uwp_account_avatar_thumb');
1217 } else if ($type == 'banner') {
1218 $previous_img = uwp_get_usermeta($user_id, 'uwp_account_banner_thumb');
1219 } else {
1220 $previous_img = '';
1221 }
1222
1223 if ($previous_img) {
1224 $unlink_img = untrailingslashit($upload_path) . '/' . ltrim($previous_img, '/');
1225 }
1226 }
1227
1228 // remove the uploads path for easy migrations
1229 $cropped = str_replace($upload_url, '', $cropped);
1230 if ($type == 'avatar') {
1231 uwp_update_usermeta($user_id, 'uwp_account_avatar_thumb', $cropped);
1232 } else {
1233 uwp_update_usermeta($user_id, 'uwp_account_banner_thumb', $cropped);
1234 }
1235
1236 if ($unlink_img && $unlink_img != $thumb_image_location && is_file($unlink_img) && file_exists($unlink_img)) {
1237 @unlink($unlink_img);
1238 $unlink_ori_img = str_replace('_uwp_'.$type.'_thumb'.'.', '.', $unlink_img);
1239 if (is_file($unlink_ori_img) && file_exists($unlink_ori_img)) {
1240 @unlink($unlink_ori_img);
1241 }
1242 }
1243 }
1244
1245 if (is_admin()) {
1246 if ($user_id == get_current_user_id()) {
1247 $profile_url = admin_url( 'profile.php' );
1248 } else {
1249 $profile_url = admin_url( 'user-edit.php?user_id='.$user_id );
1250 }
1251 } else {
1252 $profile_url = uwp_build_profile_tab_url($user_id);
1253 }
1254 return $profile_url;
1255
1256 }
1257
1258 /**
1259 * Saves UsersWP related user custom fields.
1260 *
1261 * @since 1.0.0
1262 * @package userswp
1263 *
1264 * @param int $user_id User ID.
1265 * @param array $data Result array.
1266 * @param string $type Form type.
1267 *
1268 * @return bool True when success. False when failure.
1269 */
1270 public function uwp_save_user_extra_fields($user_id, $data, $type) {
1271
1272 if (empty($user_id) || empty($data) || empty($type)) {
1273 return false;
1274 }
1275
1276 // custom user fields not applicable for login and forgot
1277 if ($type == 'login' || $type == 'forgot') {
1278 return true;
1279 }
1280
1281
1282 if ($type == 'account' || $type == 'register') {
1283 if (isset($data['password'])) {
1284 unset($data['password']);
1285 }
1286 }
1287
1288 if ($type == 'register') {
1289 if (isset($data['uwp_account_username'])) {
1290 unset($data['uwp_account_username']);
1291 }
1292 if (isset($data['uwp_account_email'])) {
1293 unset($data['uwp_account_email']);
1294 }
1295 if (isset($data['uwp_account_display_name'])) {
1296 unset($data['uwp_account_display_name']);
1297 }
1298 if (isset($data['uwp_account_first_name'])) {
1299 unset($data['uwp_account_first_name']);
1300 }
1301 if (isset($data['uwp_account_last_name'])) {
1302 unset($data['uwp_account_last_name']);
1303 }
1304 if (isset($data['uwp_account_bio'])) {
1305 unset($data['uwp_account_bio']);
1306 }
1307 }
1308
1309 if (empty($data)) {
1310 // no extra fields. so just return
1311 return true;
1312 } else {
1313 foreach($data as $key => $value) {
1314 uwp_update_usermeta($user_id, $key, $value);
1315 }
1316 return true;
1317 }
1318 }
1319
1320 /**
1321 * Logs the error message.
1322 *
1323 * @since 1.0.0
1324 * @package userswp
1325 *
1326 * @param array|object|string $log Error message.
1327 *
1328 * @return void
1329 */
1330 public static function uwp_error_log($log){
1331
1332 $should_log = apply_filters( 'uwp_log_errors', WP_DEBUG);
1333 if ( true === $should_log ) {
1334 if ( is_array( $log ) || is_object( $log ) ) {
1335 error_log( print_r( $log, true ) );
1336 } else {
1337 error_log( $log );
1338 }
1339 }
1340 }
1341
1342 /**
1343 *
1344 *
1345 * @since 1.0.0
1346 * @since 1.0.12 Unlink file.
1347 * @package userswp
1348 * @return void
1349 */
1350 public function uwp_upload_file_remove() {
1351
1352 $htmlvar = strip_tags(esc_sql($_POST['htmlvar']));
1353 $user_id = (int) strip_tags(esc_sql($_POST['uid']));
1354 $permission = false;
1355 if ($user_id == get_current_user_id()) {
1356 $permission = true;
1357 } else {
1358 if (current_user_can('manage_options')) {
1359 $permission = true;
1360 }
1361 }
1362 if ($permission) {
1363 // Remove file
1364 if ($htmlvar == "uwp_account_banner_thumb") {
1365 $file = uwp_get_usermeta($user_id, 'uwp_account_banner_thumb');
1366 $type = 'banner';
1367 } elseif ($htmlvar == "uwp_account_avatar_thumb") {
1368 $file = uwp_get_usermeta($user_id, 'uwp_account_avatar_thumb');
1369 $type = 'avatar';
1370 } else {
1371 $file = '';
1372 $type = '';
1373 }
1374
1375 uwp_update_usermeta($user_id, $htmlvar, '');
1376
1377 if ($file) {
1378 $uploads = wp_upload_dir();
1379 $upload_path = $uploads['basedir'];
1380 $unlink_file = untrailingslashit($upload_path) . '/' . ltrim($file, '/');
1381
1382 if (is_file($unlink_file) && file_exists($unlink_file)) {
1383 @unlink($unlink_file);
1384 $unlink_ori_file = str_replace('_uwp_'.$type.'_thumb'.'.', '.', $unlink_file);
1385 if (is_file($unlink_ori_file) && file_exists($unlink_ori_file)) {
1386 @unlink($unlink_ori_file);
1387 }
1388 }
1389 }
1390 }
1391 die();
1392 }
1393
1394
1395 /**
1396 * Form field template for datepicker field type.
1397 *
1398 * @since 1.0.0
1399 * @package userswp
1400 *
1401 * @param string $html Form field html
1402 * @param object $field Field info.
1403 * @param string $value Form field default value.
1404 * @param string $form_type Form type
1405 *
1406 * @return string Modified form field html.
1407 */
1408 public function uwp_form_input_datepicker($html, $field, $value, $form_type){
1409
1410 // Check if there is a field specific filter.
1411 if(has_filter("uwp_form_input_html_datepicker_{$field->htmlvar_name}")){
1412 $html = apply_filters("uwp_form_input_html_datepicker_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1413 }
1414
1415 // If no html then we run the standard output.
1416 if(empty($html)) {
1417
1418 ob_start(); // Start buffering;
1419
1420 $extra_fields = unserialize($field->extra_fields);
1421
1422 if ($extra_fields['date_format'] == '')
1423 $extra_fields['date_format'] = 'yy-mm-dd';
1424
1425 $date_format = $extra_fields['date_format'];
1426 $jquery_date_format = $date_format;
1427
1428 if (!empty($value) && !is_string($value)) {
1429 $value = date('Y-m-d', $value);
1430 }
1431
1432
1433 // check if we need to change the format or not
1434 $date_format_len = strlen(str_replace(' ', '', $date_format));
1435 if($date_format_len>5){// if greater then 5 then it's the old style format.
1436
1437 $search = array('dd','d','DD','mm','m','MM','yy'); //jQuery UI datepicker format
1438 $replace = array('d','j','l','m','n','F','Y');//PHP date format
1439
1440 $date_format = str_replace($search, $replace, $date_format);
1441 }else{
1442 $jquery_date_format = uwp_date_format_php_to_jqueryui( $jquery_date_format );
1443 }
1444 if($value=='0000-00-00'){$value='';}//if date not set, then mark it empty
1445 $value = uwp_date($value, 'Y-m-d', $date_format);
1446 ?>
1447 <script type="text/javascript">
1448
1449 jQuery(function () {
1450
1451 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker({changeMonth: true, changeYear: true
1452 <?php if($field->htmlvar_name == 'uwp_account_dob'){ echo ", yearRange: '1900:+0'"; } else { echo ", yearRange: '1900:2050'"; }?>
1453 <?php echo apply_filters("uwp_datepicker_extra_{$field->htmlvar_name}",'');?>});
1454
1455 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker("option", "dateFormat", '<?php echo $jquery_date_format;?>');
1456
1457 <?php if(!empty($value)){?>
1458 var parsedDate = jQuery.datepicker.parseDate('yy-mm-dd', '<?php echo $value;?>');
1459 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker("setDate", parsedDate);
1460 <?php } ?>
1461
1462 });
1463
1464 </script>
1465 <div id="<?php echo $field->htmlvar_name;?>_row"
1466 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row clearfix uwp_clear uwp-fieldset-details">
1467
1468 <?php
1469 $site_title = uwp_get_form_label($field);
1470 if (!is_admin()) { ?>
1471 <label>
1472 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1473 <?php if ($field->is_required) echo '<span>*</span>';?>
1474 </label>
1475 <?php } ?>
1476
1477 <input name="<?php echo $field->htmlvar_name;?>"
1478 id="<?php echo $field->htmlvar_name;?>"
1479 placeholder="<?php echo $site_title; ?>"
1480 title="<?php echo $site_title; ?>"
1481 type="text"
1482 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
1483 value="<?php echo esc_attr($value);?>" class="uwp_textfield"/>
1484
1485 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1486 <?php if ($field->is_required) { ?>
1487 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1488 <?php } ?>
1489 </div>
1490
1491 <?php
1492 $html = ob_get_clean();
1493 }
1494
1495 return $html;
1496 }
1497
1498 /**
1499 * Form field template for time field type.
1500 *
1501 * @since 1.0.0
1502 * @package userswp
1503 *
1504 * @param string $html Form field html
1505 * @param object $field Field info.
1506 * @param string $value Form field default value.
1507 * @param string $form_type Form type
1508 *
1509 * @return string Modified form field html.
1510 */
1511 public function uwp_form_input_time($html, $field, $value, $form_type){
1512
1513 if(has_filter("uwp_form_input_html_time_{$field->htmlvar_name}")){
1514
1515 $html = apply_filters("uwp_form_input_html_time_{$field->htmlvar_name}",$html, $field, $value, $form_type);
1516 }
1517
1518 // If no html then we run the standard output.
1519 if(empty($html)) {
1520
1521 ob_start(); // Start buffering;
1522
1523 if ($value != '')
1524 $value = date('H:i', strtotime($value));
1525 ?>
1526 <script type="text/javascript">
1527 jQuery(document).ready(function () {
1528
1529 jQuery('#<?php echo $field->htmlvar_name;?>').timepicker({
1530 showPeriod: true,
1531 showLeadingZero: true
1532 });
1533 });
1534 </script>
1535 <div id="<?php echo $field->htmlvar_name;?>_row"
1536 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row clearfix uwp_clear uwp-fieldset-details">
1537
1538 <?php
1539 $site_title = uwp_get_form_label($field);
1540 if (!is_admin()) { ?>
1541 <label>
1542 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1543 <?php if ($field->is_required) echo '<span>*</span>';?>
1544 </label>
1545 <?php } ?>
1546
1547 <input readonly="readonly" name="<?php echo $field->htmlvar_name;?>"
1548 id="<?php echo $field->htmlvar_name;?>"
1549 value="<?php echo esc_attr($value);?>"
1550 placeholder="<?php echo $site_title; ?>"
1551 type="text"
1552 class="uwp_textfield"/>
1553
1554 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1555 <?php if ($field->is_required) { ?>
1556 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1557 <?php } ?>
1558 </div>
1559 <?php
1560 $html = ob_get_clean();
1561 }
1562
1563 return $html;
1564 }
1565
1566 /**
1567 * Form field template for select field type.
1568 *
1569 * @since 1.0.0
1570 * @package userswp
1571 *
1572 * @param string $html Form field html
1573 * @param object $field Field info.
1574 * @param string $value Form field default value.
1575 * @param string $form_type Form type
1576 *
1577 * @return string Modified form field html.
1578 */
1579 public function uwp_form_input_select($html, $field, $value, $form_type){
1580
1581 // Check if there is a field specific filter.
1582 if(has_filter("uwp_form_input_html_select_{$field->htmlvar_name}")){
1583 $html = apply_filters("uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1584 }
1585
1586 // Check if there is a field type specific filter.
1587 if(has_filter("uwp_form_input_html_select_{$field->field_type_key}")){
1588 $html = apply_filters("uwp_form_input_html_select_{$field->field_type_key}", $html, $field, $value, $form_type);
1589 }
1590
1591 // If no html then we run the standard output.
1592 if(empty($html)) {
1593
1594 ob_start(); // Start buffering;
1595
1596 ?>
1597 <div id="<?php echo $field->htmlvar_name;?>_row"
1598 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear">
1599
1600 <?php
1601 $site_title = uwp_get_form_label($field);
1602 if (!is_admin()) { ?>
1603 <label>
1604 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1605 <?php if ($field->is_required) echo '<span>*</span>';?>
1606 </label>
1607 <?php } ?>
1608
1609 <?php
1610 $option_values_arr = uwp_string_values_to_options($field->option_values, true);
1611 $select_options = '';
1612 if (!empty($option_values_arr)) {
1613 foreach ($option_values_arr as $option_row) {
1614 if (isset($option_row['optgroup']) && ($option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end')) {
1615 $option_label = isset($option_row['label']) ? $option_row['label'] : '';
1616
1617 $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
1618 } else {
1619 $option_label = isset($option_row['label']) ? $option_row['label'] : '';
1620 $option_value = isset($option_row['value']) ? $option_row['value'] : '';
1621 $selected = $option_value == $value ? 'selected="selected"' : '';
1622
1623 $select_options .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
1624 }
1625 }
1626 }
1627 ?>
1628 <select name="<?php echo $field->htmlvar_name;?>" id="<?php echo $field->htmlvar_name;?>"
1629 class="uwp_textfield"
1630 title="<?php echo $site_title; ?>"
1631 data-placeholder="<?php echo __('Choose', 'userswp') . ' ' . $site_title . '&hellip;';?>"
1632 ><?php echo $select_options;?>
1633 </select>
1634 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1635 <?php if ($field->is_required) { ?>
1636 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1637 <?php } ?>
1638 </div>
1639
1640 <?php
1641 $html = ob_get_clean();
1642 }
1643
1644 return $html;
1645 }
1646
1647 /**
1648 * Form field template for multiselect field type.
1649 *
1650 * @since 1.0.0
1651 * @package userswp
1652 *
1653 * @param string $html Form field html
1654 * @param object $field Field info.
1655 * @param string $value Form field default value.
1656 * @param string $form_type Form type
1657 *
1658 * @return string Modified form field html.
1659 */
1660 public function uwp_form_input_multiselect($html, $field, $value, $form_type){
1661
1662 // Check if there is a field specific filter.
1663 if(has_filter("uwp_form_input_html_multiselect_{$field->htmlvar_name}")){
1664 $html = apply_filters("uwp_form_input_html_multiselect_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1665 }
1666
1667
1668 if(empty($html)) {
1669
1670 ob_start(); // Start buffering;
1671
1672 $multi_display = 'select';
1673 if (!empty($field->extra_fields)) {
1674 $multi_display = unserialize($field->extra_fields);
1675 }
1676 ?>
1677 <div id="<?php echo $field->htmlvar_name;?>_row"
1678 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear">
1679
1680 <?php
1681 $site_title = uwp_get_form_label($field);
1682 if (!is_admin()) { ?>
1683 <label>
1684 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1685 <?php if ($field->is_required) echo '<span>*</span>';?>
1686 </label>
1687 <?php } ?>
1688
1689 <input type="hidden" name="<?php echo $field->htmlvar_name;?>" value=""/>
1690 <?php if ($multi_display == 'select') { ?>
1691 <div class="uwp_multiselect_list">
1692 <select name="<?php echo $field->htmlvar_name;?>[]"
1693 id="<?php echo $field->htmlvar_name;?>"
1694 title="<?php echo $site_title; ?>"
1695 multiple="multiple" class="uwp_chosen_select"
1696 data-placeholder="<?php echo $site_title; ?>"
1697 >
1698 <?php
1699 } else {
1700 ?>
1701 <ul class="uwp_multi_choice">
1702 <?php
1703 }
1704
1705 $option_values_arr = uwp_string_values_to_options($field->option_values, true);
1706 $select_options = '';
1707 if (!empty($option_values_arr)) {
1708 foreach ($option_values_arr as $option_row) {
1709 if (isset($option_row['optgroup']) && ($option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end')) {
1710 $option_label = isset($option_row['label']) ? $option_row['label'] : '';
1711
1712 if ($multi_display == 'select') {
1713 $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
1714 } else {
1715 $select_options .= $option_row['optgroup'] == 'start' ? '<li>' . $option_label . '</li>' : '';
1716 }
1717 } else {
1718 $option_label = isset($option_row['label']) ? $option_row['label'] : '';
1719 $option_value = isset($option_row['value']) ? $option_row['value'] : '';
1720 $selected = $option_value == $value ? 'selected="selected"' : '';
1721 $checked = '';
1722
1723 if ((!is_array($value) && trim($value) != '') || (is_array($value) && !empty($value))) {
1724 if (!is_array($value)) {
1725 $value_array = explode(',', $value);
1726 } else {
1727 $value_array = $value;
1728 }
1729
1730 if (is_array($value_array)) {
1731 if (in_array($option_value, $value_array)) {
1732 $selected = 'selected="selected"';
1733 $checked = 'checked="checked"';
1734 }
1735 }
1736 }
1737
1738 if ($multi_display == 'select') {
1739 $select_options .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
1740 } else {
1741 $select_options .= '<li><input name="' . $field->name . '[]" ' . $checked . ' value="' . esc_attr($option_value) . '" class="uwp-' . $multi_display . '" type="' . $multi_display . '" />&nbsp;' . $option_label . ' </li>';
1742 }
1743 }
1744 }
1745 }
1746 echo $select_options;
1747
1748 if ($multi_display == 'select') { ?></select></div>
1749 <?php } else { ?>
1750 </ul>
1751 <?php } ?>
1752 <?php if ($field->is_required) { ?>
1753 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1754 <?php } ?>
1755 </div>
1756 <?php
1757 $html = ob_get_clean();
1758 }
1759
1760 return $html;
1761 }
1762
1763 /**
1764 * Form field template for file field type.
1765 *
1766 * @since 1.0.0
1767 * @package userswp
1768 *
1769 * @param string $html Form field html
1770 * @param object $field Field info.
1771 * @param string $value Form field default value.
1772 * @param string $form_type Form type
1773 *
1774 * @return string Modified form field html.
1775 */
1776 public function uwp_form_input_file($html, $field, $value, $form_type){
1777
1778 $file_obj = new UsersWP_Files();
1779
1780 // Check if there is a field specific filter.
1781 if(has_filter("uwp_form_input_html_file_{$field->htmlvar_name}")){
1782 $html = apply_filters("uwp_form_input_html_file_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1783 }
1784
1785 // If no html then we run the standard output.
1786 if(empty($html)) {
1787
1788 ob_start(); // Start buffering;
1789
1790 ?>
1791 <div id="<?php echo $field->htmlvar_name;?>_row"
1792 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
1793
1794 <?php
1795 $site_title = uwp_get_form_label($field);
1796 if (!is_admin()) { ?>
1797 <label>
1798 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1799 <?php if ($field->is_required) echo '<span>*</span>';?>
1800 </label>
1801 <?php } ?>
1802
1803 <?php echo $file_obj->uwp_file_upload_preview($field, $value); ?>
1804 <input name="<?php echo $field->htmlvar_name; ?>"
1805 class="<?php echo $field->css_class; ?>"
1806 placeholder="<?php echo $site_title; ?>"
1807 title="<?php echo $site_title; ?>"
1808 <?php
1809 if ($field->is_required == 1 ) { echo 'data-is-required="1"'; }
1810 if ($field->is_required == 1 && !$value) { echo 'required="required"'; }
1811 ?>
1812 type="<?php echo $field->field_type; ?>">
1813 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1814 <?php if ($field->is_required) { ?>
1815 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1816 <?php } ?>
1817 </div>
1818
1819 <?php
1820 $html = ob_get_clean();
1821 }
1822
1823 return $html;
1824 }
1825
1826 /**
1827 * Form field template for checkbox field type.
1828 *
1829 * @since 1.0.0
1830 * @package userswp
1831 *
1832 * @param string $html Form field html
1833 * @param object $field Field info.
1834 * @param string $value Form field default value.
1835 * @param string $form_type Form type
1836 *
1837 * @return string Modified form field html.
1838 */
1839 public function uwp_form_input_checkbox($html, $field, $value, $form_type){
1840
1841 // Check if there is a field specific filter.
1842 if(has_filter("uwp_form_input_html_checkbox_{$field->htmlvar_name}")){
1843 $html = apply_filters("uwp_form_input_html_checkbox_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1844 }
1845
1846 // If no html then we run the standard output.
1847 if(empty($html)) {
1848
1849 ob_start(); // Start buffering;
1850 $site_title = uwp_get_form_label($field);
1851 ?>
1852 <div id="<?php echo $field->htmlvar_name;?>_row"
1853 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
1854 <input type="hidden" name="<?php echo $field->htmlvar_name; ?>" value="0" />
1855 <input name="<?php echo $field->htmlvar_name; ?>"
1856 class="<?php echo $field->css_class; ?>"
1857 placeholder="<?php echo $site_title; ?>"
1858 title="<?php echo $site_title; ?>"
1859 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
1860 <?php if ($value == '1') { echo 'checked="checked"'; } ?>
1861 type="<?php echo $field->field_type; ?>"
1862 value="1">
1863 <?php
1864 echo (trim($site_title)) ? $site_title : '&nbsp;';
1865 ?>
1866 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1867 <?php if ($field->is_required) { ?>
1868 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1869 <?php } ?>
1870 </div>
1871
1872 <?php
1873 $html = ob_get_clean();
1874 }
1875
1876 return $html;
1877 }
1878
1879 /**
1880 * Form field template for radio field type.
1881 *
1882 * @since 1.0.0
1883 * @package userswp
1884 *
1885 * @param string $html Form field html
1886 * @param object $field Field info.
1887 * @param string $value Form field default value.
1888 * @param string $form_type Form type
1889 *
1890 * @return string Modified form field html.
1891 */
1892 public function uwp_form_input_radio($html, $field, $value, $form_type){
1893
1894 // Check if there is a field specific filter.
1895 if(has_filter("uwp_form_input_html_radio_{$field->htmlvar_name}")){
1896 $html = apply_filters("uwp_form_input_html_radio_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1897 }
1898
1899 // If no html then we run the standard output.
1900 if(empty($html)) {
1901
1902 ob_start(); // Start buffering;
1903
1904 ?>
1905 <div id="<?php echo $field->htmlvar_name;?>_row"
1906 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
1907
1908 <?php
1909 $site_title = uwp_get_form_label($field);
1910 if (!is_admin()) { ?>
1911 <label>
1912 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1913 <?php if ($field->is_required) echo '<span>*</span>';?>
1914 </label>
1915 <?php } ?>
1916
1917
1918 <?php if ($field->option_values) {
1919 $option_values = uwp_string_values_to_options($field->option_values, true);
1920
1921 if (!empty($option_values)) {
1922 $count = 0;
1923 foreach ($option_values as $option_value) {
1924 if (empty($option_value['optgroup'])) {
1925 $count++;
1926 if ($count == 1) {
1927 $class = "uwp-radio-first";
1928 } else {
1929 $class = "";
1930 }
1931 ?>
1932 <span class="uwp-radios <?php echo $class; ?>">
1933 <input name="<?php echo $field->htmlvar_name; ?>"
1934 id="<?php echo $field->htmlvar_name; ?>"
1935 title="<?php echo esc_attr($option_value['label']); ?>"
1936 <?php checked($value, $option_value['value']);?>
1937 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
1938 value="<?php echo esc_attr($option_value['value']); ?>"
1939 class="uwp-radio" type="radio" />
1940 <?php echo $option_value['label']; ?>
1941 </span>
1942 <?php
1943 }
1944 }
1945 }
1946 }
1947 ?>
1948 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1949 <?php if ($field->is_required) { ?>
1950 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1951 <?php } ?>
1952 </div>
1953 <?php
1954 $html = ob_get_clean();
1955 }
1956
1957 return $html;
1958 }
1959
1960 /**
1961 * Form field template for text field type.
1962 *
1963 * @since 1.0.0
1964 * @package userswp
1965 *
1966 * @param string $html Form field html
1967 * @param object $field Field info.
1968 * @param string $value Form field default value.
1969 * @param string $form_type Form type
1970 *
1971 * @return string Modified form field html.
1972 */
1973 public function uwp_form_input_text($html, $field, $value, $form_type){
1974
1975 // Check if there is a custom field specific filter.
1976 if(has_filter("uwp_form_input_text_{$field->htmlvar_name}")){
1977 $html = apply_filters("uwp_form_input_text_{$field->htmlvar_name}",$html, $field, $value, $form_type);
1978 }
1979
1980 // If no html then we run the standard output.
1981 if(empty($html)) {
1982
1983 ob_start(); // Start buffering;
1984
1985 $type = 'text';
1986 $step = false;
1987 //number and float validation $validation_pattern
1988 if(isset($field->data_type) && $field->data_type == 'INT'){
1989 $type = 'number';
1990 } elseif(isset($field->data_type) && $field->data_type == 'FLOAT'){
1991 $dp = $field->decimal_point;
1992 switch ($dp) {
1993 case "1":
1994 $step = "0.1";
1995 break;
1996 case "2":
1997 $step = "0.01";
1998 break;
1999 case "3":
2000 $step = "0.001";
2001 break;
2002 case "4":
2003 $step = "0.0001";
2004 break;
2005 case "5":
2006 $step = "0.00001";
2007 break;
2008 case "6":
2009 $step = "0.000001";
2010 break;
2011 case "7":
2012 $step = "0.0000001";
2013 break;
2014 case "8":
2015 $step = "0.00000001";
2016 break;
2017 case "9":
2018 $step = "0.000000001";
2019 break;
2020 case "10":
2021 $step = "0.0000000001";
2022 break;
2023 default:
2024 $step = "0.01";
2025 break;
2026 }
2027 $type = 'number';
2028 }
2029
2030 ?>
2031
2032 <div id="<?php echo $field->htmlvar_name;?>_row"
2033 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
2034
2035 <?php
2036 $site_title = uwp_get_form_label($field);
2037 $manual_label = apply_filters('uwp_login_username_label_manual', true);
2038 if ($manual_label
2039 && isset($field->form_type)
2040 && $field->form_type == 'login'
2041 && $field->htmlvar_name == 'uwp_login_username') {
2042 $site_title = __("Username or Email", 'userswp');
2043 }
2044 if (!is_admin()) { ?>
2045 <label>
2046 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2047 <?php if ($field->is_required) echo '<span>*</span>';?>
2048 </label>
2049 <?php } ?>
2050
2051 <input name="<?php echo $field->htmlvar_name;?>"
2052 class="<?php echo $field->css_class; ?> uwp_textfield"
2053 id="<?php echo $field->htmlvar_name;?>"
2054 placeholder="<?php echo $site_title; ?>"
2055 value="<?php echo esc_attr(stripslashes($value));?>"
2056 title="<?php echo $site_title; ?>"
2057 oninvalid="this.setCustomValidity('<?php _e($field->required_msg, 'userswp'); ?>')"
2058 oninput="setCustomValidity('')"
2059 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2060 <?php if ($field->for_admin_use == 1) { echo 'readonly="readonly"'; } ?>
2061 type="<?php echo $type; ?>"
2062 <?php if ($step) { echo 'step="'.$step.'"'; } ?>
2063 />
2064 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2065 <?php if ($field->is_required) { ?>
2066 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2067 <?php } ?>
2068 </div>
2069
2070
2071 <?php
2072 $html = ob_get_clean();
2073 }
2074
2075 return $html;
2076 }
2077
2078 /**
2079 * Form field template for textarea field type.
2080 *
2081 * @since 1.0.0
2082 * @package userswp
2083 *
2084 * @param string $html Form field html
2085 * @param object $field Field info.
2086 * @param string $value Form field default value.
2087 * @param string $form_type Form type
2088 *
2089 * @return string Modified form field html.
2090 */
2091 public function uwp_form_input_textarea($html, $field, $value, $form_type){
2092
2093 // Check if there is a field specific filter.
2094 if(has_filter("uwp_form_input_textarea_{$field->htmlvar_name}")){
2095 $html = apply_filters("uwp_form_input_textarea_{$field->htmlvar_name}", $html, $field, $value, $form_type);
2096 }
2097
2098 // If no html then we run the standard output.
2099 if(empty($html)) {
2100
2101 ob_start(); // Start buffering;
2102
2103 ?>
2104 <div id="<?php echo $field->htmlvar_name;?>_row"
2105 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
2106
2107 <?php
2108 $site_title = uwp_get_form_label($field);
2109 if (!is_admin()) { ?>
2110 <label>
2111 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2112 <?php if ($field->is_required) echo '<span>*</span>';?>
2113 </label>
2114 <?php } ?>
2115
2116 <textarea name="<?php echo $field->htmlvar_name; ?>"
2117 class="<?php echo $field->css_class; ?>"
2118 placeholder="<?php echo $site_title; ?>"
2119 title="<?php echo $site_title; ?>"
2120 oninvalid="this.setCustomValidity('<?php _e($field->required_msg, 'userswp'); ?>')"
2121 oninput="setCustomValidity('')"
2122 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2123 type="<?php echo $field->field_type; ?>"
2124 rows="4"><?php echo stripslashes($value); ?></textarea>
2125 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2126 <?php if ($field->is_required) { ?>
2127 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2128 <?php } ?>
2129 </div>
2130
2131 <?php
2132 $html = ob_get_clean();
2133 }
2134
2135 return $html;
2136 }
2137
2138 /**
2139 * Form field template for fieldset field type.
2140 *
2141 * @since 1.0.0
2142 * @package userswp
2143 *
2144 * @param string $html Form field html
2145 * @param object $field Field info.
2146 * @param string $value Form field default value.
2147 * @param string $form_type Form type
2148 *
2149 * @return string Modified form field html.
2150 */
2151 public function uwp_form_input_fieldset($html, $field, $value, $form_type) {
2152 // Check if there is a custom field specific filter.
2153 if(has_filter("uwp_form_input_fieldset_{$field->htmlvar_name}")){
2154 $html = apply_filters("uwp_form_input_fieldset_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2155 }
2156
2157 // If no html then we run the standard output.
2158 if(empty($html)) {
2159
2160 ob_start(); // Start buffering;
2161 ?>
2162 <h3 class="uwp_input_fieldset <?php echo $field->css_class; ?>">
2163 <?php echo $field->site_title;; ?>
2164 <?php if ( $field->help_text != '' ) {
2165 echo '<small>( ' . $field->help_text . ' )</small>';
2166 } ?></h3>
2167 <?php
2168 $html = ob_get_clean();
2169 }
2170
2171 return $html;
2172 }
2173
2174 /**
2175 * Form field template for url field type.
2176 *
2177 * @since 1.0.0
2178 * @package userswp
2179 *
2180 * @param string $html Form field html
2181 * @param object $field Field info.
2182 * @param string $value Form field default value.
2183 * @param string $form_type Form type
2184 *
2185 * @return string Modified form field html.
2186 */
2187 public function uwp_form_input_url($html, $field, $value, $form_type){
2188
2189
2190 // Check if there is a custom field specific filter.
2191 if(has_filter("uwp_form_input_url_{$field->htmlvar_name}")){
2192 $html = apply_filters("uwp_form_input_url_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2193 }
2194
2195 // If no html then we run the standard output.
2196 if(empty($html)) {
2197
2198 ob_start(); // Start buffering;
2199 ?>
2200 <div id="<?php echo $field->htmlvar_name;?>_row"
2201 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
2202
2203 <?php
2204 $site_title = uwp_get_form_label($field);
2205 if (!is_admin()) { ?>
2206 <label>
2207 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2208 <?php if ($field->is_required) echo '<span>*</span>';?>
2209 </label>
2210 <?php } ?>
2211
2212 <input name="<?php echo $field->htmlvar_name;?>"
2213 class="<?php echo $field->css_class; ?> uwp_textfield"
2214 id="<?php echo $field->htmlvar_name;?>"
2215 placeholder="<?php echo $site_title; ?>"
2216 value="<?php echo esc_attr(stripslashes($value));?>"
2217 title="<?php echo $site_title; ?>"
2218 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2219 type="url"
2220 oninvalid="setCustomValidity('<?php _e('Please enter a valid URL including http://', 'userswp'); ?>')"
2221 onchange="try{setCustomValidity('')}catch(e){}"
2222 />
2223 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2224 <?php if ($field->is_required) { ?>
2225 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2226 <?php } ?>
2227 </div>
2228
2229 <?php
2230 $html = ob_get_clean();
2231 }
2232
2233 return $html;
2234 }
2235
2236 /**
2237 * Form field template for email field type.
2238 *
2239 * @since 1.0.0
2240 * @package userswp
2241 *
2242 * @param string $html Form field html
2243 * @param object $field Field info.
2244 * @param string $value Form field default value.
2245 * @param string $form_type Form type
2246 *
2247 * @return string Modified form field html.
2248 */
2249 public function uwp_form_input_email($html, $field, $value, $form_type){
2250
2251
2252 // Check if there is a custom field specific filter.
2253 if(has_filter("uwp_form_input_email_{$field->htmlvar_name}")){
2254 $html = apply_filters("uwp_form_input_email_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2255 }
2256
2257 // If no html then we run the standard output.
2258 if(empty($html)) {
2259
2260 ob_start(); // Start buffering;
2261 ?>
2262 <div id="<?php echo $field->htmlvar_name;?>_row"
2263 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
2264
2265 <?php
2266 $site_title = uwp_get_form_label($field);
2267 if (!is_admin()) { ?>
2268 <label>
2269 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2270 <?php if ($field->is_required) echo '<span>*</span>';?>
2271 </label>
2272 <?php } ?>
2273
2274 <input name="<?php echo $field->htmlvar_name;?>"
2275 class="<?php echo $field->css_class; ?> uwp_textfield"
2276 id="<?php echo $field->htmlvar_name;?>"
2277 placeholder="<?php echo $site_title; ?>"
2278 value="<?php echo esc_attr(stripslashes($value));?>"
2279 title="<?php echo $site_title; ?>"
2280 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2281 type="email"
2282 />
2283 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2284 <?php if ($field->is_required) { ?>
2285 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2286 <?php } ?>
2287 </div>
2288
2289
2290 <?php
2291 $html = ob_get_clean();
2292 }
2293
2294 if(has_filter("uwp_form_input_email_{$field->htmlvar_name}_after")){
2295 $html = apply_filters("uwp_form_input_email_{$field->htmlvar_name}_after",$html, $field, $value, $form_type);
2296 }
2297
2298 return $html;
2299 }
2300
2301 /**
2302 * Form field template for password field type.
2303 *
2304 * @since 1.0.0
2305 * @package userswp
2306 *
2307 * @param string $html Form field html
2308 * @param object $field Field info.
2309 * @param string $value Form field default value.
2310 * @param string $form_type Form type
2311 *
2312 * @return string Modified form field html.
2313 */
2314 public function uwp_form_input_password($html, $field, $value, $form_type){
2315
2316
2317 // Check if there is a custom field specific filter.
2318 if(has_filter("uwp_form_input_password_{$field->htmlvar_name}")){
2319 $html = apply_filters("uwp_form_input_password_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2320 }
2321
2322 // If no html then we run the standard output.
2323 if(empty($html)) {
2324
2325 ob_start(); // Start buffering;
2326 ?>
2327 <div id="<?php echo $field->htmlvar_name;?>_row"
2328 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
2329
2330 <?php
2331 $site_title = uwp_get_form_label($field);
2332 if (!is_admin()) { ?>
2333 <label>
2334 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2335 <?php if ($field->is_required) echo '<span>*</span>';?>
2336 </label>
2337 <?php } ?>
2338
2339 <input name="<?php echo $field->htmlvar_name;?>"
2340 class="<?php echo $field->css_class; ?> uwp_textfield"
2341 id="<?php echo $field->htmlvar_name;?>"
2342 placeholder="<?php echo $site_title; ?>"
2343 value="<?php echo esc_attr(stripslashes($value));?>"
2344 title="<?php echo $site_title; ?>"
2345 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2346 type="password"
2347 />
2348 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2349 <?php if ($field->is_required) { ?>
2350 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2351 <?php } ?>
2352 </div>
2353
2354
2355 <?php
2356 $html = ob_get_clean();
2357 }
2358
2359 if(has_filter("uwp_form_input_password_{$field->htmlvar_name}_after")){
2360 $html = apply_filters("uwp_form_input_password_{$field->htmlvar_name}_after",$html, $field, $value, $form_type);
2361 }
2362
2363 return $html;
2364 }
2365
2366 /**
2367 * Adds enctype tag in form for file fields.
2368 *
2369 * @since 1.0.0
2370 * @package userswp
2371 *
2372 * @return void
2373 */
2374 function add_multipart_to_admin_edit_form() {
2375 global $wpdb;
2376 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2377 $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND field_type = 'file' AND is_default = '0' ORDER BY sort_order ASC");
2378 if ($fields) {
2379 echo 'enctype="multipart/form-data"';
2380 }
2381 }
2382
2383 /**
2384 * Handles UsersWP custom field requests from admin.
2385 *
2386 * @since 1.0.0
2387 * @package userswp
2388 *
2389 * @param int $user_id User ID.
2390 *
2391 * @return void
2392 */
2393 public function update_profile_extra_admin_edit($user_id) {
2394 global $wpdb;
2395 $file_obj = new UsersWP_Files();
2396 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2397 //Normal fields
2398 $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND field_type != 'file' AND field_type != 'fieldset' ORDER BY sort_order ASC");
2399 if ($fields) {
2400 $_POST['uwp_account_first_name'] = $_POST['first_name'];
2401 $_POST['uwp_account_last_name'] = $_POST['last_name'];
2402 $_POST['uwp_account_display_name'] = $_POST['nickname'];
2403 $_POST['uwp_account_email'] = $_POST['email'];
2404 $_POST['uwp_account_bio'] = $_POST['description'];
2405 $result = uwp_validate_fields($_POST, 'account', $fields);
2406 if (isset($result['uwp_account_display_name']) && !empty($result['uwp_account_display_name'])) {
2407 $display_name = $result['uwp_account_display_name'];
2408 } else {
2409 if (!empty($first_name) || !empty($last_name)) {
2410 $display_name = $result['uwp_account_first_name'] . ' ' . $result['uwp_account_last_name'];
2411 } else {
2412 $user_info = get_userdata($user_id);
2413 $display_name = $user_info->user_login;
2414 }
2415 }
2416 $result['uwp_account_display_name'] = $display_name;
2417 if (!is_wp_error($result)) {
2418 foreach ($fields as $field) {
2419 $value = isset($result[$field->htmlvar_name]) ? $result[$field->htmlvar_name] : '';
2420 if ($value == '0' || !empty($value)) {
2421 uwp_update_usermeta($user_id, $field->htmlvar_name, $value);
2422 }
2423 }
2424 }
2425 }
2426
2427 //File fields
2428 $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND field_type = 'file' AND is_default = '0' ORDER BY sort_order ASC");
2429 if ($fields) {
2430 $result = $file_obj->uwp_validate_uploads($_FILES, 'account', true, $fields);
2431 if (!is_wp_error($result)) {
2432 foreach ($fields as $field) {
2433 $value = $result[$field->htmlvar_name];
2434 if ($value == '0' || !empty($value)) {
2435 uwp_update_usermeta($user_id, $field->htmlvar_name, $value);
2436 }
2437 }
2438 }
2439 }
2440 }
2441
2442
2443 /**
2444 * Adds search form keyword input html.
2445 *
2446 * @since 1.0.0
2447 * @package userswp
2448 *
2449 * @param string $keyword Search keyword.
2450 *
2451 * @return void
2452 */
2453 public function uwp_users_search_form_text_field($keyword) {
2454 ?>
2455 <input placeholder="Search For" name="uwps" value="<?php echo $keyword; ?>" class="s search-input" type="text">
2456 <?php
2457 }
2458
2459 /**
2460 * Adds search form submit button html.
2461 *
2462 * @since 1.0.0
2463 * @package userswp
2464 *
2465 * @return void
2466 */
2467 public function uwp_users_search_form_submit() {
2468 ?>
2469 <input class="uwp-searchsubmit uwp-search-submit" value="Search" type="submit">
2470 <?php
2471 }
2472
2473 /**
2474 * Checks for errors in mail submission.
2475 *
2476 * @since 1.0.0
2477 * @package userswp
2478 *
2479 * @param array $res Result array.
2480 * @param object $user_data User object.
2481 * @param WP_Error $errors Error object
2482 *
2483 * @return WP_Error|array Error object when error. Result array when success.
2484 */
2485 public function uwp_forms_check_for_send_mail_errors($res, $user_data, $errors) {
2486 if (!$res) {
2487 if (get_option('admin_email') == $user_data->user_email) {
2488 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong when sending email. Please check your site error log for more details.', 'userswp'));
2489 } else {
2490 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong when sending email. Please contact site admin.', 'userswp'));
2491 }
2492 }
2493
2494 $error_code = $errors->get_error_code();
2495 if (!empty($error_code)) {
2496 return $errors;
2497 } else {
2498 return $res;
2499 }
2500
2501 }
2502
2503 /**
2504 * Form field template for country field.
2505 *
2506 * @since 1.0.0
2507 * @package userswp
2508 *
2509 * @param string $html Form field html
2510 * @param object $field Field info.
2511 * @param string $value Form field default value.
2512 * @param string $form_type Form type
2513 *
2514 * @return string Modified form field html.
2515 */
2516 public function uwp_form_input_select_country($html, $field, $value, $form_type){
2517
2518 // Check if there is a field specific filter.
2519 if(has_filter("uwp_form_input_html_select_{$field->htmlvar_name}")){
2520 $html = apply_filters("uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type);
2521 }
2522
2523 //print_r($field);
2524
2525 // If no html then we run the standard output.
2526 if(empty($html)) {
2527
2528 ob_start(); // Start buffering;
2529
2530 ?>
2531 <div id="<?php echo $field->htmlvar_name;?>_row"
2532 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear">
2533
2534 <?php
2535 $site_title = uwp_get_form_label($field);
2536 if (!is_admin()) { ?>
2537 <label>
2538 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2539 <?php if ($field->is_required) echo '<span>*</span>';?>
2540 </label>
2541 <?php } ?>
2542
2543 <?php
2544 // if value empty set the default
2545 if($value=='' && isset($field->default_value) && $field->default_value){
2546 $value = $field->default_value;
2547 }
2548 $select_country_options = apply_filters('uwp_form_input_select_country',"{defaultCountry: '$value'}",$field, $value, $form_type);
2549 ?>
2550
2551 <input type="text" class="uwp_textfield" title="<?php echo $site_title; ?>" id="<?php echo $field->htmlvar_name;?>" />
2552 <input type="hidden" id="<?php echo $field->htmlvar_name;?>_code" name="<?php echo $field->htmlvar_name;?>" />
2553
2554 <script>
2555 jQuery("#<?php echo $field->htmlvar_name;?>").countrySelect(<?php echo $select_country_options;?>);
2556 </script>
2557
2558
2559 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2560 <?php if ($field->is_required) { ?>
2561 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2562 <?php } ?>
2563 </div>
2564
2565 <?php
2566 $html = ob_get_clean();
2567 }
2568
2569 return $html;
2570 }
2571
2572 /**
2573 * Prints the username link in "Edit Account" page
2574 *
2575 * @since 1.0.0
2576 * @package userswp
2577 *
2578 * @param string $type Page type.
2579 *
2580 * @return void
2581 */
2582 public function uwp_display_username_in_account($type) {
2583 if ($type == 'account') {
2584 $user_id = get_current_user_id();
2585 $user_info = get_userdata($user_id);
2586 $display_name = $user_info->user_login;
2587 ?>
2588 <span class="uwp_account_page_username">
2589 <a href="<?php echo uwp_build_profile_tab_url($user_id); ?>">( @<?php echo $display_name; ?> )</a>
2590 </span>
2591 <?php
2592 }
2593 }
2594
2595
2596 /**
2597 * Adds confirm password field in forms.
2598 *
2599 * @since 1.0.0
2600 * @package userswp
2601 *
2602 * @param string $html Form field html
2603 * @param object $field Field info.
2604 * @param string $value Form field default value.
2605 * @param string $form_type Form type
2606 *
2607 * @return string Modified form field html.
2608 */
2609 public function uwp_register_confirm_password_field($html, $field, $value, $form_type) {
2610 if ($form_type == 'register') {
2611 //confirm password field
2612 $extra = array();
2613 if (isset($field->extra_fields) && $field->extra_fields != '') {
2614 $extra = unserialize($field->extra_fields);
2615 }
2616 $enable_confirm_password_field = isset($extra['confirm_password']) ? $extra['confirm_password'] : '0';
2617 if ($enable_confirm_password_field == '1') {
2618 ob_start(); // Start buffering;
2619 ?>
2620 <div id="uwp_account_confirm_password_row"
2621 class="<?php echo 'required_field';?> uwp_form_password_row uwp_clear">
2622
2623 <?php
2624 $site_title = __("Confirm Password", 'userswp');
2625 if (!is_admin()) { ?>
2626 <label>
2627 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2628 <?php echo '<span>*</span>'; ?>
2629 </label>
2630 <?php } ?>
2631
2632 <input name="uwp_account_confirm_password"
2633 class="uwp_textfield"
2634 id="uwp_account_confirm_password"
2635 placeholder="<?php echo $site_title; ?>"
2636 value=""
2637 title="<?php echo $site_title; ?>"
2638 <?php echo 'required="required"'; ?>
2639 type="password"
2640 />
2641 </div>
2642
2643 <?php
2644 $confirm_html = ob_get_clean();
2645 $html = $html.$confirm_html;
2646 }
2647 }
2648 return $html;
2649 }
2650
2651 /**
2652 * Adds confirm email field in forms.
2653 *
2654 * @since 1.0.0
2655 * @package userswp
2656 *
2657 * @param string $html Form field html
2658 * @param object $field Field info.
2659 * @param string $value Form field default value.
2660 * @param string $form_type Form type
2661 *
2662 * @return string Modified form field html.
2663 */
2664 public function uwp_register_confirm_email_field($html, $field, $value, $form_type) {
2665 if ($form_type == 'register') {
2666 //confirm email field
2667 $extra = array();
2668 if (isset($field->extra_fields) && $field->extra_fields != '') {
2669 $extra = unserialize($field->extra_fields);
2670 }
2671 $enable_confirm_email_field = isset($extra['confirm_email']) ? $extra['confirm_email'] : '0';
2672 if ($enable_confirm_email_field == '1') {
2673 ob_start(); // Start buffering;
2674 ?>
2675 <div id="uwp_account_confirm_email_row"
2676 class="<?php echo 'required_field';?> uwp_form_email_row uwp_clear">
2677
2678 <?php
2679 $site_title = __("Confirm Email", 'userswp');
2680 if (!is_admin()) { ?>
2681 <label>
2682 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2683 <?php echo '<span>*</span>'; ?>
2684 </label>
2685 <?php } ?>
2686
2687 <input name="uwp_account_confirm_email"
2688 class="uwp_textfield"
2689 id="uwp_account_confirm_email"
2690 placeholder="<?php echo $site_title; ?>"
2691 value=""
2692 title="<?php echo $site_title; ?>"
2693 <?php echo 'required="required"'; ?>
2694 type="email"
2695 />
2696 </div>
2697
2698 <?php
2699 $confirm_html = ob_get_clean();
2700 $html = $html.$confirm_html;
2701 }
2702 }
2703 return $html;
2704 }
2705
2706
2707 /**
2708 * Handles the privacy form submission.
2709 *
2710 * @since 1.0.0
2711 * @package userswp
2712 *
2713 * @return void
2714 */
2715 public function uwp_privacy_submit_handler() {
2716 if (isset($_POST['uwp_privacy_submit'])) {
2717 if( ! isset( $_POST['uwp_privacy_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_privacy_nonce'], 'uwp-privacy-nonce' ) ) {
2718 return;
2719 }
2720
2721 $extra_where = "AND is_public='2'";
2722 $fields = get_account_form_fields($extra_where);
2723 $fields = apply_filters('uwp_account_privacy_fields', $fields);
2724 if ($fields) {
2725 foreach ($fields as $field) {
2726 $field_name = $field->htmlvar_name.'_privacy';
2727 if (isset($_POST[$field_name])) {
2728 $value = strip_tags(esc_sql($_POST[$field_name]));
2729 $user_id = get_current_user_id();
2730 uwp_update_usermeta($user_id, $field_name, $value);
2731 }
2732 }
2733 }
2734
2735 $user_id = get_current_user_id();
2736 if (isset($_POST['uwp_hide_from_listing']) && 1 == $_POST['uwp_hide_from_listing']) {
2737 update_user_meta($user_id, 'uwp_hide_from_listing', 1);
2738 } else {
2739 update_user_meta($user_id, 'uwp_hide_from_listing', 0);
2740 }
2741
2742 $make_profile_private = uwp_can_make_profile_private();
2743 if ($make_profile_private) {
2744 $field_name = 'uwp_make_profile_private';
2745 if (isset($_POST[$field_name])) {
2746 $value = strip_tags(esc_sql($_POST[$field_name]));
2747 $user_id = get_current_user_id();
2748 update_user_meta($user_id, $field_name, $value);
2749 }
2750 }
2751
2752 }
2753 }
2754
2755 }