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

3,455 lines 131.3 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 if (isset($_POST['uwp_avatar_submit'])) {
48 $errors = $this->process_upload_submit($_POST, $_FILES, 'avatar');
49 if (!is_wp_error($errors)) {
50 $redirect = $errors;
51 }
52 $message = __('Avatar cropped successfully.', 'userswp');
53 $processed = true;
54 } elseif (isset($_POST['uwp_banner_submit'])) {
55 $errors = $this->process_upload_submit($_POST, $_FILES, 'banner');
56 if (!is_wp_error($errors)) {
57 $redirect = $errors;
58 }
59 $message = __('Banner cropped successfully.', 'userswp');
60 $processed = true;
61 } elseif (isset($_POST['uwp_avatar_crop'])) {
62 $errors = $this->process_image_crop($_POST, 'avatar', true);
63 if (!is_wp_error($errors)) {
64 $redirect = $errors;
65 }
66 $message = __('Avatar cropped successfully.', 'userswp');
67 $processed = true;
68 } elseif (isset($_POST['uwp_banner_crop'])) {
69 $errors = $this->process_image_crop($_POST, 'banner', true);
70 if (!is_wp_error($errors)) {
71 $redirect = $errors;
72 }
73 $message = __('Banner cropped successfully.', 'userswp');
74 $processed = true;
75 }
76
77 if ($processed) {
78 if (is_wp_error($errors)) {
79 echo '<div class="uwp-alert-error text-center">';
80 echo $errors->get_error_message();
81 echo '</div>';
82 } else {
83 if ($redirect) {
84 wp_safe_redirect($redirect);
85 exit();
86 } else {
87 echo '<div class="uwp-alert-success text-center">';
88 echo $message;
89 echo '</div>';
90 }
91 }
92 }
93
94 if($type){
95 $uwp_notices[] = array($type => ob_get_contents());
96 }else{
97 $uwp_notices[] = ob_get_contents();
98 }
99
100 ob_end_clean();
101
102 }
103
104 /**
105 * Displays links in a dropdown
106 *
107 * @since 1.0.0
108 * @package userswp
109 *
110 * @param $options
111 */
112 public function output_dashboard_links($options){
113 if(!empty($options)){
114 $class = uwp_get_option("design_style",'bootstrap')=='bootstrap' ? 'form-control' : 'aui-select2';
115 echo "<select class='$class' onchange='window.location = jQuery(this).val();'>";
116 $this->output_options($options);
117 echo "<select>";
118 }
119 }
120
121 /**
122 * Displays options for the dashboard links
123 *
124 * @since 1.0.0
125 * @package userswp
126 *
127 * @param $options
128 */
129 public function output_options($options){
130 if(!empty($options)){
131 foreach($options as $key => $link){
132
133 if(!isset($link['text']) && isset($link[0]) && is_array($link[0])){
134 $this->output_options($link);
135 }else{
136 if(!empty($link['optgroup']) && $link['optgroup']=='open'){
137 echo "<optgroup label='".esc_attr($link['text'])."'>";
138 }elseif(!empty($link['optgroup']) && $link['optgroup']=='close'){
139 echo "</optgroup>";
140 }elseif(!empty($link['text'])){
141 $disabled = !empty($link['disabled']) ? 'disabled' : '';
142 $selected = !empty($link['selected']) ? 'selected' : '';
143 $value = !empty($link['url']) ? esc_url($link['url']) : '';
144 $display_none = !empty($link['display_none']) ? 'style="display:none;"' : '';
145 echo "<option $disabled $selected value='$value' $display_none>";
146 echo esc_attr($link['text']);
147 echo "</option>";
148 }
149 }
150 }
151 }
152 }
153
154 /**
155 * Displays UsersWP notices in forms.
156 *
157 * @since 1.0.0
158 * @package userswp
159 *
160 * @param string $type Form type
161 *
162 * @return void
163 */
164 public function display_notices($type) {
165 global $uwp_notices;
166
167 if (is_array($uwp_notices)) {
168 foreach ($uwp_notices as $notice) {
169
170 // If the notification is type specific then only output on that type
171 if(is_array($notice)){
172 foreach($notice as $key => $val){
173 if( $key == $type ){ echo $val; }
174 }
175 }else{
176 if (!empty($notice)) {
177 echo $notice;
178 }
179 }
180
181 }
182
183 }
184
185 if ($type == 'change') {
186 $user_id = get_current_user_id();
187 $password_nag = get_user_option('default_password_nag', $user_id);
188
189 if ($password_nag) {
190 $change_page = uwp_get_page_id('change_page', false);
191 $remove_nag_url = add_query_arg('uwp_remove_nag', 'yes', get_permalink($change_page));
192
193 if (isset($_GET['uwp_remove_nag']) && $_GET['uwp_remove_nag'] == 'yes') {
194 delete_user_meta( $user_id, 'default_password_nag' );
195 $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('/'));
196 echo aui()->alert(array(
197 'class'=>'text-center',
198 'type'=>'success',
199 'content'=> $message
200 ));
201 } else {
202 $message = sprintf(__('<strong>Warning</strong>: It 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 aui()->alert(array(
204 'class'=>'text-center',
205 'type'=>'warning',
206 'content'=> $message
207 ));
208 }
209 }
210 }
211 }
212
213 /**
214 * Processes register form submission.
215 *
216 * @since 1.0.0
217 * @package userswp
218 *
219 */
220 public function process_register() {
221
222 $data = $_POST;
223
224 if( ! isset( $data['uwp_register_nonce'] )){
225 return;
226 }
227
228 if( ! isset( $data['uwp_register_nonce'] ) || ! wp_verify_nonce( $data['uwp_register_nonce'], 'uwp-register-nonce' ) ) {
229 $message = aui()->alert(array(
230 'type'=>'error',
231 'content'=> __('Security verification failed. Try again.', 'userswp')
232 )
233 );
234 if(wp_doing_ajax()){wp_send_json_error($message);}
235 else{return;}
236 }
237
238 global $uwp_notices;
239
240 $files = $_FILES;
241 $errors = new WP_Error();
242 $file_obj = new UsersWP_Files();
243
244 if (!get_option('users_can_register')) {
245 $message = aui()->alert(array(
246 'type'=>'error',
247 'content'=> __('<strong>ERROR</strong>: User registration is currently not allowed. Please check settings of your site.', 'userswp')
248 )
249 );
250 if(wp_doing_ajax()){wp_send_json_error($message);}
251 else{$uwp_notices[] = array('register' => $message); return;}
252 }
253
254 $reg_terms_page_id = uwp_get_option('register_terms_page', '');
255 $reg_terms_page_id = apply_filters('uwp_reg_terms_page_id', $reg_terms_page_id);
256 if (!empty($reg_terms_page_id)) {
257 if (!isset($data['agree_terms']) || $data['agree_terms'] != 'yes') {
258 $message = aui()->alert(array(
259 'type'=>'error',
260 'content'=> __('<strong>ERROR</strong>: You must accept our terms and conditions.', 'userswp')
261 )
262 );
263 if(wp_doing_ajax()){wp_send_json_error($message);}
264 else{$uwp_notices[] = array('register' => $message); return;}
265 }
266 }
267
268 do_action('uwp_before_validate', 'register');
269
270 $result = uwp_validate_fields($data, 'register');
271
272 $result = apply_filters('uwp_validate_result', $result, 'register', $data);
273
274 if (is_wp_error($result)) {
275 $message = aui()->alert(array(
276 'type'=>'error',
277 'content'=> $result->get_error_message()
278 )
279 );
280 if(wp_doing_ajax()){wp_send_json_error($message);}
281 else{$uwp_notices[] = array('register' => $message); return;}
282 }
283
284 $uploads_result = $file_obj->validate_uploads($files, 'register');
285
286 if (is_wp_error($uploads_result)) {
287 $message = aui()->alert(array(
288 'type'=>'error',
289 'content'=> $uploads_result->get_error_message()
290 )
291 );
292 if(wp_doing_ajax()){wp_send_json_error($message);}
293 else{$uwp_notices[] = array('register' => $message); return;}
294 }
295
296 do_action('uwp_after_validate', 'register');
297
298 $result = array_merge( $result, $uploads_result );
299
300 if (isset($result['password']) && !empty($result['password'])) {
301 $password = $result['password'];
302 $generated_password = false;
303 } else {
304 $password = wp_generate_password();
305 $this->generated_password = $password;
306 $generated_password = true;
307 }
308
309 $first_name = "";
310 if (isset($result['first_name']) && !empty($result['first_name'])) {
311 $first_name = $result['first_name'];
312 }
313
314 $last_name = "";
315 if (isset($result['last_name']) && !empty($result['last_name'])) {
316 $last_name = $result['last_name'];
317 }
318
319 if (isset($result['display_name']) && !empty($result['display_name'])) {
320 $display_name = $result['display_name'];
321 } else {
322 if (!empty($first_name) || !empty($last_name)) {
323 $display_name = $first_name . ' ' . $last_name;
324 } else {
325 $display_name = $result['username'];
326 }
327 }
328
329 $description = "";
330 if (isset($result['bio']) && !empty($result['bio'])) {
331 $description = $result['bio'];
332 }
333
334 $user_login = !empty($result['username']) ? $result['username'] : '';
335 $email = !empty($result['email']) ? $result['email'] : '';
336
337 if(empty($user_login)){
338 $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
339 if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
340 $new_user_login = strstr($email, '@', true);
341 if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
342 $user_login = sanitize_user($new_user_login, true );
343 }
344 if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
345 $user_append_text = rand(10,1000);
346 $user_login = sanitize_user($new_user_login.$user_append_text, true );
347 }
348
349 if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
350 $user_login = $email;
351 }
352 }
353 }else{
354 if(!validate_username( $user_login )){
355 $message = aui()->alert(array(
356 'type'=>'error',
357 'content'=> __('Sorry, that username is not allowed.', 'userswp')
358 )
359 );
360 if(wp_doing_ajax()){wp_send_json_error($message);}
361 else{$uwp_notices[] = array('register' => $message); return;}
362 }
363 }
364
365 $args = array(
366 'user_login' => $user_login,
367 'user_email' => $email,
368 'user_pass' => $password,
369 'display_name' => $display_name,
370 'first_name' => $first_name,
371 'last_name' => $last_name,
372 'description' => $description
373 );
374
375 // print_r($args);exit;
376
377 $user_id = wp_insert_user( $args );
378
379 // echo '###';print_r($user_id);exit;
380
381 if (is_wp_error($user_id)) {
382 $message = aui()->alert(array(
383 'type'=>'error',
384 'content'=> $user_id->get_error_message()
385 )
386 );
387 if(wp_doing_ajax()){wp_send_json_error($message);}
388 else{$uwp_notices[] = array('register' => $message); return;}
389 }
390
391 $result = apply_filters('uwp_before_extra_fields_save', $result, 'register', $user_id);
392
393 $save_result = $this->save_user_extra_fields($user_id, $result, 'register');
394
395 $save_result = apply_filters('uwp_after_extra_fields_save', $save_result, $result, 'register', $user_id);
396
397 if (is_wp_error($save_result)) {
398 $message = aui()->alert(array(
399 'type'=>'error',
400 'content'=> $save_result->get_error_message()
401 )
402 );
403 if(wp_doing_ajax()){wp_send_json_error($message);}
404 else{$uwp_notices[] = array('register' => $message); return;}
405 }
406
407 if (!$save_result) {
408 $message = aui()->alert(array(
409 'type'=>'error',
410 'content'=> __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp')
411 )
412 );
413 if(wp_doing_ajax()){wp_send_json_error($message);}
414 else{$uwp_notices[] = array('register' => $message); return;}
415 }
416
417 do_action('uwp_after_custom_fields_save', 'register', $data, $result, $user_id);
418
419 $reg_action = uwp_get_option('uwp_registration_action', false);
420
421 if ($reg_action == 'require_email_activation' && !$generated_password) {
422
423 if( 1 == uwp_get_option('registration_activate_email' )) {
424 $email = new UsersWP_Mails();
425 $email->send('activate', $user_id);
426 }
427
428 } else {
429 if( 1 == uwp_get_option('registration_success_email' )) {
430 $email = new UsersWP_Mails();
431 $email->send('register', $user_id);
432 }
433 }
434
435 $error_code = $errors->get_error_code();
436 if (!empty($error_code)) {
437 $message = aui()->alert(array(
438 'type'=>'error',
439 'content'=> $result->get_error_message()
440 )
441 );
442 if(wp_doing_ajax()){wp_send_json_error($message);}
443 else{$uwp_notices[] = array('register' => $message); return;}
444 }
445
446 if ($reg_action != 'require_admin_review') {
447 $register_admin_notify = uwp_get_option('register_admin_notify', '');
448 if ($register_admin_notify == '1') {
449 $email = new UsersWP_Mails();
450 $email->send_admin_email('register_admin', $user_id);
451 }
452
453 }
454
455 if ($reg_action == 'force_redirect') {
456 $redirect_to = $this->get_register_redirect_url($data, $user_id);
457 do_action('uwp_after_process_register', $data);
458 if(wp_doing_ajax()){
459 $message = aui()->alert(array(
460 'type'=>'success',
461 'content'=> __('Account registered successfully. Redirecting...', 'userswp')
462 )
463 );
464 $response = array(
465 'message' => $message,
466 'redirect' => $redirect_to,
467 );
468 wp_send_json_success($response);
469 }else{
470 wp_redirect($redirect_to);
471 }
472 exit();
473 } elseif ($reg_action == 'auto_approve_login') {
474 $res = wp_signon(
475 array(
476 'user_login' => $result['username'],
477 'user_password' => $password,
478 'remember' => false
479 )
480 );
481
482 if (is_wp_error($res)) {
483 $error = aui()->alert(array(
484 'type'=>'error',
485 'content'=> __( 'Invalid username or Password.', 'userswp' )
486 )
487 );
488 $uwp_notices[] = array('register' => $error);
489 } else {
490 $redirect_to = $this->get_register_redirect_url($data, $user_id);
491 do_action('uwp_after_process_register', $data);
492
493 if(wp_doing_ajax()){
494 $message = aui()->alert(array(
495 'type'=>'success',
496 'content'=> __('Account registered successfully. Redirecting...', 'userswp')
497 )
498 );
499 $response = array(
500 'message' => $message,
501 'redirect' => $redirect_to,
502 );
503 wp_send_json_success($response);
504 }else{
505 wp_redirect($redirect_to);
506 }
507 exit();
508 }
509 } else {
510 if ($reg_action == 'require_email_activation') {
511 $resend_link = uwp_current_page_url();
512 $resend_link = add_query_arg(
513 array(
514 'user_id' => $user_id,
515 'action' => 'uwp_resend',
516 '_nonce' => wp_create_nonce('uwp_resend'),
517 ),
518 $resend_link
519 );
520 $message = aui()->alert(array(
521 'type'=>'success',
522 'content'=> sprintf(__('An email has been sent to your registered email address. Please click the activation link to proceed. %sResend%s.', 'userswp'), '<a href="'.$resend_link.'"">', '</a>')
523 )
524 );
525
526 } elseif ($reg_action == 'require_admin_review' && defined('UWP_MOD_VERSION')) {
527 update_user_meta( $user_id, 'uwp_mod', '1' );
528
529 $email = new UsersWP_Mails();
530 if( 1 == uwp_get_option('enable_moderation_notification' )) {
531 $email->send('mod_pending', $user_id);
532 }
533 if( 1 == uwp_get_option('enable_moderation_notification' )) {
534 $email->send_admin_email('mod_admin', $user_id);
535 }
536 $message = aui()->alert(array(
537 'type'=>'success',
538 'content'=> __('Your account is under moderation. We will email you once its approved.', 'userswp')
539 )
540 );
541 } else {
542
543 $login_page_url = wp_login_url();
544
545 if ($generated_password) {
546 $msg = sprintf(__('Account registered successfully. A password has been generated and mailed to your registered Email ID. Please login %shere%s.', 'userswp'), '<a href="'.$login_page_url.'">', '</a>');
547 } else {
548 $msg = sprintf(__('Account registered successfully. Please login %shere%s', 'userswp'), '<a href="'.$login_page_url.'">', '</a>');
549 }
550
551 $message = aui()->alert(array(
552 'type'=>'success',
553 'content'=> $msg
554 )
555 );
556 }
557
558 do_action('uwp_after_process_register', $data, $user_id);
559
560 if(wp_doing_ajax()){wp_send_json_success($message);}
561 else{$uwp_notices[] = array('register' => $message);}
562
563 }
564
565 if(wp_doing_ajax()){wp_send_json_error();} // if we got this far there is a problem
566
567 }
568
569 /**
570 * Processes login form submission.
571 *
572 * @since 1.0.0
573 * @package userswp
574 *
575 */
576 public function process_login() {
577
578 $data = $_POST;
579
580 if( ! isset( $data['uwp_login_nonce'] )){
581 return;
582 }
583
584 if( ! isset( $data['uwp_login_nonce'] ) || ! wp_verify_nonce( $data['uwp_login_nonce'], 'uwp-login-nonce' ) ) {
585 $message = aui()->alert(array(
586 'type'=>'error',
587 'content'=> __('Security verification failed. Try again.', 'userswp')
588 )
589 );
590 if(wp_doing_ajax()){wp_send_json_error($message);}
591 else{return;}
592 }
593
594 global $uwp_notices;
595
596 do_action('uwp_before_validate', 'login');
597
598 $result = uwp_validate_fields($data, 'login');
599
600 $result = apply_filters('uwp_validate_result', $result, 'login', $data);
601
602 if (is_wp_error($result)) {
603 $message = aui()->alert(array(
604 'type'=>'error',
605 'content'=> $result->get_error_message()
606 )
607 );
608 if(wp_doing_ajax()){wp_send_json_error($message);}
609 else{$uwp_notices[] = array('login' => $message); return;}
610 }
611
612 do_action('uwp_after_validate', 'login');
613
614 if (isset($data['remember_me']) && $data['remember_me'] == 'forever') {
615 $remember_me = true;
616 } else {
617 $remember_me = false;
618 }
619
620 remove_action( 'authenticate', 'gglcptch_login_check', 21 );
621
622 $user = wp_signon(
623 array(
624 'user_login' => $result['username'],
625 'user_password' => $result['password'],
626 'remember' => $remember_me
627 )
628 );
629
630 add_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
631
632 if (is_wp_error($user)) {
633 $message = aui()->alert(array(
634 'type'=>'error',
635 'content'=> __( 'Invalid username or Password.', 'userswp' )
636 )
637 );
638 if(wp_doing_ajax()){wp_send_json_error($message);}
639 else{$uwp_notices[] = array('login' => $message); return;}
640 } else {
641 do_action('uwp_after_process_login', $data);
642 $message = aui()->alert(array(
643 'type'=>'success',
644 'content'=> __('Login successful. Redirecting...','userswp')
645 )
646 );
647 if(wp_doing_ajax()){wp_send_json_success($message);}
648 else{
649 $redirect_to = $this->get_login_redirect_url($data, $user);
650 wp_redirect($redirect_to);
651 exit();
652 }
653
654 }
655
656 }
657
658 /**
659 * Processes forgot password form submission.
660 *
661 * @since 1.0.0
662 * @package userswp
663 *
664 */
665 public function process_forgot() {
666
667 $data = $_POST;
668
669 if( ! isset( $data['uwp_forgot_nonce'] )){
670 return;
671 }
672
673 if( ! isset( $data['uwp_forgot_nonce'] ) || ! wp_verify_nonce( $data['uwp_forgot_nonce'], 'uwp-forgot-nonce' ) ) {
674 $message = aui()->alert(array(
675 'type'=>'error',
676 'content'=> __('Security verification failed. Try again.', 'userswp')
677 )
678 );
679 if(wp_doing_ajax()){wp_send_json_error($message);}
680 else{return;}
681 }
682
683 global $uwp_notices;
684
685 do_action('uwp_before_validate', 'forgot');
686
687 $result = uwp_validate_fields($data, 'forgot');
688
689 $result = apply_filters('uwp_validate_result', $result, 'forgot', $data);
690
691 if (is_wp_error($result)) {
692 $message = aui()->alert(array(
693 'type'=>'error',
694 'content'=> $result->get_error_message()
695 )
696 );
697 if(wp_doing_ajax()){wp_send_json_error($message);}
698 else{$uwp_notices[] = array('forgot' => $message); return;}
699 }
700
701 do_action('uwp_after_validate', 'forgot');
702
703
704 $user_data = get_user_by('email', $data['email']);
705
706 // if no user we fake it and bail
707 if(!$user_data){
708 $message = aui()->alert(array(
709 'type'=>'success',
710 'content'=> apply_filters('uwp_change_password_success_message', __('Please check your email.', 'userswp'), $data)
711 )
712 );
713 if(wp_doing_ajax()){wp_send_json_success($message);}
714 else{$uwp_notices[] = array('forgot' => $message);return;}
715 }
716
717 // make sure user account is active before account reset
718 $mod_value = get_user_meta( $user_data->ID, 'uwp_mod', true );
719 if ($mod_value == 'email_unconfirmed') {
720 $message = aui()->alert(array(
721 'type'=>'error',
722 'content'=> __('<strong>Error</strong>: Your account is not activated yet. Please activate your account first.', 'userswp')
723 )
724 );
725 if(wp_doing_ajax()){wp_send_json_error($message);}
726 else{$uwp_notices[] = array('forgot' => $message); return;}
727 }
728
729 $email = new UsersWP_Mails();
730 $email->send( 'forgot', $user_data->ID );
731
732 do_action('uwp_after_process_forgot', $data);
733
734 $message = aui()->alert(array(
735 'type'=>'success',
736 'content'=> apply_filters('uwp_change_password_success_message', __('Please check your email.', 'userswp'), $data)
737 )
738 );
739 if(wp_doing_ajax()){wp_send_json_success($message);}
740 else{$uwp_notices[] = array('forgot' => $message);}
741 }
742
743 /**
744 * Processes change password form submission.
745 *
746 * @since 1.0.0
747 * @package userswp
748 *
749 */
750 public function process_change() {
751
752 $data = $_POST;
753
754 if( ! isset( $data['uwp_change_nonce'] ) || ! wp_verify_nonce( $data['uwp_change_nonce'], 'uwp-change-nonce' ) ) {
755 return;
756 }
757
758 global $uwp_notices;
759
760 do_action('uwp_before_validate', 'change');
761
762 $result = uwp_validate_fields($data, 'change');
763
764 $result = apply_filters('uwp_validate_result', $result, 'change', $data);
765
766 if (is_wp_error($result)) {
767 $message = aui()->alert(array(
768 'type'=>'error',
769 'content'=> $result->get_error_message()
770 )
771 );
772 $uwp_notices[] = array('change' => $message );
773 return;
774 }
775
776 do_action('uwp_after_validate', 'change');
777
778 $user_data = get_user_by('id', get_current_user_id());
779
780 if (!$user_data) {
781 $message = aui()->alert(array(
782 'type'=>'error',
783 'content'=> $user_data->get_error_message()
784 )
785 );
786 $uwp_notices[] = array('change' => $message);
787 return;
788 }
789
790 $email = new UsersWP_Mails();
791 $email->send( 'change', $user_data->ID );
792
793 wp_set_password( $result['password'], $user_data->ID );
794
795 $password_nag = get_user_option('default_password_nag', $user_data->ID);
796 if ($password_nag) {
797 delete_user_meta( $user_data->ID, 'default_password_nag' );
798 }
799
800 $message = aui()->alert(array(
801 'type'=>'success',
802 'content'=> apply_filters('uwp_change_password_success_message', __('Password changed successfully', 'userswp'), $data)
803 )
804 );
805
806 $uwp_notices[] = array('change' => $message);
807
808 do_action('uwp_after_process_change', $data);
809
810 wp_logout();exit();
811 }
812
813 /**
814 * Processes reset password form submission.
815 *
816 * @since 1.0.0
817 * @package userswp
818 *
819 */
820 public function process_reset() {
821
822 $data = $_POST;
823
824 if( ! isset( $data['uwp_reset_nonce'] ) || ! wp_verify_nonce( $data['uwp_reset_nonce'], 'uwp-reset-nonce' ) ) {
825 return;
826 }
827
828 global $uwp_notices;
829
830 do_action('uwp_before_validate', 'reset');
831
832 $result = uwp_validate_fields($data, 'reset');
833
834 $result = apply_filters('uwp_validate_result', $result, 'reset', $data);
835
836 if (is_wp_error($result)) {
837 $message = aui()->alert(array(
838 'type'=>'error',
839 'content'=> $result->get_error_message()
840 )
841 );
842 $uwp_notices[] = array('reset' => $message);
843 return;
844 }
845
846 do_action('uwp_after_validate', 'reset');
847
848 $login = $data['uwp_reset_username'];
849 $key = $data['uwp_reset_key'];
850 $user_data = check_password_reset_key( $key, $login );
851
852 if (is_wp_error($user_data)) {
853 $message = aui()->alert(array(
854 'type'=>'error',
855 'content'=> $user_data->get_error_message()
856 )
857 );
858 $uwp_notices[] = array('reset' => $message);
859 return;
860 }
861
862 $email = new UsersWP_Mails();
863 $email->send( 'reset', $user_data->ID );
864
865 wp_set_password( $data['password'], $user_data->ID );
866
867 $login_page_url = uwp_get_login_page_url();
868 $message = sprintf(__('Password updated successfully. Please <a href="%s">login</a> with your new password', 'userswp'), $login_page_url);
869 $message = apply_filters('uwp_reset_password_success_message', $message, $data);
870 $message = aui()->alert(array(
871 'type'=>'success',
872 'content'=> $message
873 )
874 );
875 $uwp_notices[] = array('reset' => $message);
876
877 do_action('uwp_after_process_reset', $data);
878 }
879
880 /**
881 * Processes account form submission.
882 *
883 * @since 1.0.0
884 * @package userswp
885 *
886 */
887 public function process_account() {
888
889 $data = $_POST;
890 $files = $_FILES;
891
892 $current_user_id = get_current_user_id();
893 if (!$current_user_id) {
894 return;
895 }
896
897 if( ! isset( $data['uwp_account_nonce'] ) || ! wp_verify_nonce( $data['uwp_account_nonce'], 'uwp-account-nonce' ) ) {
898 return;
899 }
900
901 global $uwp_notices;
902 $file_obj = new UsersWP_Files();
903
904 do_action('uwp_before_validate', 'account');
905
906 $result = uwp_validate_fields($data, 'account');
907
908 $result = apply_filters('uwp_validate_result', $result, 'account', $data);
909
910 if (is_wp_error($result)) {
911 $message = aui()->alert(array(
912 'type'=>'error',
913 'content'=> $result->get_error_message()
914 )
915 );
916 $uwp_notices[] = array('account' => $message);
917 return;
918 }
919
920 $uploads_result = $file_obj->validate_uploads($files, 'account');
921
922 if (is_wp_error($uploads_result)) {
923 $message = aui()->alert(array(
924 'type'=>'error',
925 'content'=> $uploads_result->get_error_message()
926 )
927 );
928 $uwp_notices[] = array('account' => $message);
929 return;
930 }
931
932 do_action('uwp_after_validate', 'account');
933
934 //unset if value is empty for files
935 foreach ($uploads_result as $upload_file_key => $upload_file_value) {
936 if (empty($upload_file_value)) {
937 unset($uploads_result[$upload_file_key]);
938 }
939 }
940
941 $result = array_merge( $result, $uploads_result );
942
943
944 $args = array(
945 'ID' => $current_user_id
946 );
947
948 if (isset($result['email'])) {
949 $args['user_email'] = $result['email'];
950 }
951
952 if (isset($result['first_name']) && isset($result['last_name'])) {
953 $args['display_name'] = $result['first_name'] . ' ' . $result['last_name'];
954 }
955
956 if (isset($result['first_name'])) {
957 $args['first_name'] = $result['first_name'];
958 }
959
960 if (isset($result['last_name'])) {
961 $args['last_name'] = $result['last_name'];
962 }
963
964 if (isset($result['bio'])) {
965 $args['description'] = $result['bio'];
966 }
967
968 if (isset($result['display_name']) && !empty($result['display_name'])) {
969 $args['display_name'] = $result['display_name'];
970 }
971
972 if (isset($result['password'])) {
973 $args['user_pass'] = $result['password'];
974 }
975
976 $user_id = wp_update_user( $args );
977
978 if (!$user_id) {
979 $message = aui()->alert(array(
980 'type'=>'error',
981 'content'=> __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp')
982 )
983 );
984 $uwp_notices[] = array('account' => $message);
985 return;
986 }
987
988 $res = $this->save_user_extra_fields($user_id, $result, 'account');
989
990 if (!$res) {
991 $message = aui()->alert(array(
992 'type'=>'error',
993 'content'=> __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp')
994 )
995 );
996 $uwp_notices[] = array('account' => $message);
997 return;
998 }
999
1000
1001 if (uwp_get_option('account_update_email') == '1') {
1002 $user_data = get_user_by('id', $user_id);
1003
1004 $email = new UsersWP_Mails();
1005 $email->send( 'account', $user_data->ID );
1006
1007 }
1008
1009 $message = apply_filters('uwp_reset_password_success_message', __('Account updated successfully', 'userswp'), $data);
1010 $message = aui()->alert(array(
1011 'type'=>'success',
1012 'content'=> $message
1013 )
1014 );
1015 $uwp_notices[] = array('account' => $message);
1016
1017 do_action('uwp_after_process_account', $data);
1018
1019 }
1020
1021 /**
1022 * Processes avatar and banner uploads form submission.
1023 *
1024 * @since 1.0.0
1025 * @package userswp
1026 *
1027 * @param array $data Submitted $_POST data
1028 * @param array $files Submitted $_FILES data
1029 *
1030 * @return bool|WP_Error|string File url to crop.
1031 */
1032 public function process_upload_submit($data = array(), $files = array(), $type = 'avatar') {
1033
1034 $file_obj = new UsersWP_Files();
1035
1036 $current_user_id = get_current_user_id();
1037 if (!$current_user_id) {
1038 return false;
1039 }
1040
1041 if( ! isset( $data['uwp_upload_nonce'] ) || ! wp_verify_nonce( $data['uwp_upload_nonce'], 'uwp-upload-nonce' ) ) {
1042 return false;
1043 }
1044
1045 do_action('uwp_before_validate', $type);
1046
1047 $result = $file_obj->validate_uploads($files, $type);
1048
1049 $result = apply_filters('uwp_validate_result', $result, $type, $data);
1050
1051 if (is_wp_error($result)) {
1052 return $result;
1053 }
1054
1055 $profile_url = uwp_build_profile_tab_url($current_user_id);
1056
1057 $url = add_query_arg(
1058 array(
1059 'uwp_crop' => $result['uwp_'.$type.'_file'],
1060 'type' => $type
1061 ),
1062 $profile_url);
1063
1064 return $url;
1065
1066 }
1067
1068 /**
1069 * Processes avatar and banner uploads image crop.
1070 *
1071 * @since 1.0.0
1072 * @since 1.0.12 New param $unlink_prev_img introduced.
1073 * @package userswp
1074 *
1075 * @param array $data Submitted $_POST data
1076 * @param string $type Image type. Default 'avatar'.
1077 * @param bool $unlink_prev_img True to remove previous image. Default false;
1078 *
1079 * @return bool|WP_Error|string Profile url.
1080 */
1081 public function process_image_crop($data = array(), $type = 'avatar', $unlink_prev_img = false) {
1082
1083 if (!is_user_logged_in()) {
1084 return false;
1085 }
1086
1087 // If is current user's profile (profile.php)
1088 if ( is_admin() && defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE ) {
1089 $user_id = get_current_user_id();
1090 // If is another user's profile page
1091 } elseif (is_admin() && ! empty($_GET['user_id']) && is_numeric($_GET['user_id']) ) {
1092 $user_id = $_GET['user_id'];
1093 // Otherwise something is wrong.
1094 } else {
1095 $user_id = get_current_user_id();
1096 }
1097 $image_url = $data['uwp_crop'];
1098
1099 $errors = new WP_Error();
1100 if (empty($image_url)) {
1101 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp'));
1102 }
1103
1104 $error_code = $errors->get_error_code();
1105 if (!empty($error_code)) {
1106 return $errors;
1107 }
1108
1109 if ($image_url) {
1110 if ($type == 'avatar') {
1111 $full_width = apply_filters('uwp_avatar_image_width', 150);
1112 } else {
1113 $full_width = apply_filters('uwp_banner_image_width', uwp_get_option('profile_banner_width', 1000));
1114 }
1115
1116 $image_url = esc_url($image_url);
1117 add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
1118 $uploads = wp_upload_dir();
1119 remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
1120 $upload_url = $uploads['baseurl'];
1121 $upload_path = $uploads['basedir'];
1122 $image_url = str_replace($upload_url, $upload_path, $image_url);
1123 $ext = pathinfo($image_url, PATHINFO_EXTENSION); // to get extension
1124 $name =pathinfo($image_url, PATHINFO_FILENAME); //file name without extension
1125 $thumb_image_name = $name.'_uwp_'.$type.'_thumb'.'.'.$ext;
1126 $thumb_image_location = str_replace($name.'.'.$ext, $thumb_image_name, $image_url);
1127 //Get the new coordinates to crop the image.
1128 $x = $data["x"];
1129 $y = $data["y"];
1130 $w = $data["w"];
1131 $h = $data["h"];
1132 //Scale the image based on cropped width setting
1133 $scale = $full_width/$w;
1134 //$scale = 1; // no scaling
1135 $cropped = uwp_resizeThumbnailImage($thumb_image_location, $image_url,$x, $y, $w, $h,$scale);
1136 $cropped = str_replace($upload_path, $upload_url, $cropped);
1137
1138 // Remove previous avatar/banner
1139 $unlink_img = '';
1140 if ($unlink_prev_img) {
1141 if ($type == 'avatar') {
1142 $previous_img = uwp_get_usermeta($user_id, 'avatar_thumb');
1143 } else if ($type == 'banner') {
1144 $previous_img = uwp_get_usermeta($user_id, 'banner_thumb');
1145 } else {
1146 $previous_img = '';
1147 }
1148
1149 if ($previous_img) {
1150 $unlink_img = untrailingslashit($upload_path) . '/' . ltrim($previous_img, '/');
1151 }
1152 }
1153
1154 // remove the uploads path for easy migrations
1155 $cropped = str_replace($upload_url, '', $cropped);
1156 if ($type == 'avatar') {
1157 uwp_update_usermeta($user_id, 'avatar_thumb', $cropped);
1158 } else {
1159 uwp_update_usermeta($user_id, 'banner_thumb', $cropped);
1160 }
1161
1162 if ($unlink_img && $unlink_img != $thumb_image_location && is_file($unlink_img) && file_exists($unlink_img)) {
1163 @unlink($unlink_img);
1164 $unlink_ori_img = str_replace('_uwp_'.$type.'_thumb'.'.', '.', $unlink_img);
1165 if (is_file($unlink_ori_img) && file_exists($unlink_ori_img)) {
1166 @unlink($unlink_ori_img);
1167 }
1168 }
1169 }
1170
1171 if (is_admin()) {
1172 if ($user_id == get_current_user_id()) {
1173 $profile_url = admin_url( 'profile.php' );
1174 } else {
1175 $profile_url = admin_url( 'user-edit.php?user_id='.$user_id );
1176 }
1177 } else {
1178 $profile_url = uwp_build_profile_tab_url($user_id);
1179 }
1180 return $profile_url;
1181
1182 }
1183
1184 /**
1185 * Modifies the mail extras based on the notification type.
1186 *
1187 * @since 1.0.0
1188 * @package userswp
1189 * @subpackage userswp/includes
1190 * @param string $extras Unmodified mail extras.
1191 * @param string $type Notification type.
1192 * @return string Modified mail extras.
1193 */
1194 public function init_mail_extras($extras, $type, $user_id) {
1195 switch ($type) {
1196 case "activate":
1197 $extras = $this->generate_activate_message($user_id);
1198 break;
1199 case "register":
1200 $extras = $this->generate_register_message($user_id);
1201 break;
1202 case "forgot":
1203 $extras = $this->generate_forgot_message($user_id);
1204 }
1205 return $extras;
1206 }
1207
1208 /**
1209 * Modifies the admin mail extras based on the notification type.
1210 *
1211 * @since 1.0.0
1212 * @package userswp
1213 * @subpackage userswp/includes
1214 * @param string $extras Unmodified mail extras.
1215 * @param string $type Notification type.
1216 * @return string Modified mail extras.
1217 */
1218 public function init_admin_mail_extras($extras, $type, $user_id) {
1219 switch ($type) {
1220 case "register_admin":
1221 $user_data = get_userdata($user_id);
1222 $extras = '<p><b>' .__('User Information :', 'userswp') . '</b></p>
1223 <p>' . __('First Name:', 'userswp') . ' ' . $user_data->first_name . '</p>
1224 <p>' . __('Last Name:', 'userswp') . ' ' . $user_data->last_name . '</p>
1225 <p>' . __('Username:', 'userswp') . ' ' . $user_data->user_login . '</p>
1226 <p>' . __('Email:', 'userswp') . ' ' . $user_data->user_email . '</p>';
1227 break;
1228 }
1229 return apply_filters('uwp_admin_mail_extras', $extras, $type, $user_id );
1230 }
1231
1232 /**
1233 * Modifies the forms field in email based on the form type.
1234 *
1235 * @package userswp
1236 * @subpackage userswp/includes
1237 * @param string $form_fields Form fields.
1238 * @param string $type Form type.
1239 * @param int $user_id User ID.
1240 * @return string Modified mail field.
1241 */
1242 public function init_mail_form_fields( $form_fields, $type, $user_id ) {
1243 switch ($type) {
1244 case "account":
1245 $fields = get_account_form_fields();
1246 $user_data = get_userdata($user_id);
1247 if( !empty( $fields ) && is_array($fields)) {
1248 $form_fields = '<p><b>'.__('User Information:','userswp').'</b></p>';
1249 foreach ( $fields as $key => $field ) {
1250 if( $field->htmlvar_name == 'email' && isset($user_data->user_email) ) {
1251 $field_value = $user_data->user_email;
1252 } elseif ( $field->htmlvar_name == 'display_name' && isset($user_data->user_login) ) {
1253 $field_value = $user_data->user_login;
1254 } elseif ( $field->htmlvar_name == 'bio' ){
1255 $field_value = get_user_meta($user_id, 'description', true);
1256 } else {
1257 $field_value = uwp_get_usermeta($user_id, $field->htmlvar_name);
1258 }
1259
1260 if(is_array($field_value) && count($field_value) > 0){
1261 $field_value = uwp_maybe_serialize($field->htmlvar_name, $field_value);
1262 }
1263
1264 if(isset($field->site_title) && !empty($field_value)){
1265 $form_fields .= '<p><b>' . $field->site_title . '</b>&nbsp;' . $field_value . '</p>';
1266 }
1267 }
1268 }
1269 break;
1270 }
1271 return apply_filters('uwp_mail_form_fields', $form_fields, $type, $user_id );;
1272 }
1273
1274 /**
1275 * Generates activate email message.
1276 *
1277 * @since 1.0.0
1278 * @package userswp
1279 *
1280 * @param int $user_id User ID.
1281 *
1282 * @return bool|string Message.
1283 */
1284 public function generate_activate_message($user_id) {
1285
1286 $user_data = get_userdata($user_id);
1287 global $wpdb;
1288 $key = wp_generate_password( 20, false );
1289 do_action( 'uwp_activation_key', $user_data->user_login, $key );
1290
1291 global $wp_hasher;
1292 if ( empty( $wp_hasher ) ) {
1293 require_once ABSPATH . 'wp-includes/class-phpass.php';
1294 $wp_hasher = new PasswordHash( 8, true );
1295 }
1296 $hashed = $wp_hasher->HashPassword( $key );
1297 $wpdb->update( $wpdb->users, array( 'user_activation_key' => time().":".$hashed ), array( 'user_login' => $user_data->user_login ) );
1298 update_user_meta( $user_id, 'uwp_mod', 'email_unconfirmed' );
1299 $message = __('To activate your account, visit the following address:', 'userswp') . "\r\n\r\n";
1300 $act_url = add_query_arg(
1301 array(
1302 'uwp_activate' => 'yes',
1303 'key' => $key,
1304 'login' => $user_data->user_login
1305 ),
1306 site_url()
1307 );
1308
1309 $message .= "<a href='".esc_url($act_url)."' target='_blank'>".esc_url($act_url)."</a>" . "\r\n";
1310
1311 $activate_message = '<p><b>' . __('Please activate your account :', 'userswp') . '</b></p><p>' . $message . '</p>';
1312
1313 return apply_filters('uwp_activation_mail_message', $activate_message, $user_id);
1314
1315 }
1316
1317 /**
1318 * Generates register email message.
1319 *
1320 * @since 1.0.0
1321 * @package userswp
1322 *
1323 * @param int $user_id User ID.
1324 *
1325 * @return bool|string Message.
1326 */
1327 public function generate_register_message($user_id) {
1328
1329 $user_data = get_userdata($user_id);
1330 if(isset($this->generated_password) && !empty($this->generated_password)) {
1331 if(!uwp_get_option('change_disable_password_nag')) {
1332 update_user_meta($user_id, 'default_password_nag', true); //Set up the Password change nag.
1333 }
1334 $message_pass = $this->generated_password;
1335 $this->generated_password = false;
1336 } else {
1337 $message_pass = __("Password you entered", 'userswp');
1338 }
1339 $message = __('<p><b>' . __('Your login Information :', 'userswp') . '</b></p>
1340 <p>' . __('Username:', 'userswp') . ' ' . $user_data->user_login . '</p>
1341 <p>' . __('Password:', 'userswp') . ' ' . $message_pass . '</p>');
1342
1343 return apply_filters('uwp_register_mail_message', $message, $user_id, $this->generated_password);
1344
1345 }
1346
1347 /**
1348 * Generates forgot password email message.
1349 *
1350 * @since 1.0.0
1351 * @package userswp
1352 *
1353 * @param int $user_id User ID.
1354 *
1355 * @return bool|string Message.
1356 */
1357 public function generate_forgot_message($user_id) {
1358
1359 $user_data = get_userdata($user_id);
1360 global $wpdb, $wp_hasher;
1361
1362 $allow = apply_filters('allow_password_reset', true, $user_data->ID);
1363 if ( ! $allow )
1364 return false;
1365 else if ( is_wp_error($allow) )
1366 return false;
1367
1368 $as_password = apply_filters('uwp_forgot_message_as_password', false);
1369
1370 if ($as_password) {
1371 $new_pass = wp_generate_password(12, false);
1372 wp_set_password($new_pass, $user_data->ID);
1373 if(!uwp_get_option('change_disable_password_nag')) {
1374 update_user_meta($user_data->ID, 'default_password_nag', true); //Set up the Password change nag.
1375 }
1376 $message = '<p><b>' . __('Your login Information :', 'userswp') . '</b></p>';
1377 $message .= '<p>' . sprintf(__('Username: %s', 'userswp'), $user_data->user_login) . "</p>";
1378 $message .= '<p>' . sprintf(__('Password: %s', 'userswp'), $new_pass) . "</p>";
1379
1380 } else {
1381 $key = wp_generate_password( 20, false );
1382 do_action( 'retrieve_password_key', $user_data->user_login, $key );
1383
1384 if ( empty( $wp_hasher ) ) {
1385 require_once ABSPATH . 'wp-includes/class-phpass.php';
1386 $wp_hasher = new PasswordHash( 8, true );
1387 }
1388 $hashed = $wp_hasher->HashPassword( $key );
1389 $wpdb->update( $wpdb->users, array( 'user_activation_key' => time().":".$hashed ), array( 'user_login' => $user_data->user_login ) );
1390 $message = '<p>' .__('You have requested to reset your password for the following account:', 'userswp') . "</p>";
1391 $message .= home_url( '/' ) . "</p>";
1392 $message .= '<p>' .sprintf(__('Username: %s', 'userswp'), $user_data->user_login) . "</p>";
1393 $message .= '<p>' .__('If this was by mistake, just ignore this email and nothing will happen.', 'userswp') . "</p>";
1394 $message .= '<p>' .__('To reset your password, click the following link and follow the instructions.', 'userswp') . "</p>";
1395 $message = apply_filters('uwp_forgot_password_message', $message, $user_data);
1396 $reset_page = uwp_get_page_id('reset_page', false);
1397 if ($reset_page) {
1398 $reset_link = add_query_arg( array(
1399 'key' => $key,
1400 'login' => rawurlencode($user_data->user_login),
1401 ), get_permalink($reset_page) );
1402 $message .= "<a href='".$reset_link."' target='_blank'>".$reset_link."</a>" . "\r\n";
1403 } else {
1404 $message .= site_url("reset?key=$key&login=" . rawurlencode($user_data->user_login), 'login') . "\r\n";
1405 }
1406 }
1407
1408
1409 return apply_filters('uwp_forgot_mail_message', $message, $user_id);
1410
1411 }
1412
1413 /**
1414 * Saves UsersWP related user custom fields.
1415 *
1416 * @since 1.0.0
1417 * @package userswp
1418 *
1419 * @param int $user_id User ID.
1420 * @param array $data Result array.
1421 * @param string $type Form type.
1422 *
1423 * @return bool True when success. False when failure.
1424 */
1425 public function save_user_extra_fields($user_id, $data, $type) {
1426
1427 if (empty($user_id) || empty($data) || empty($type)) {
1428 return false;
1429 }
1430
1431 // custom user fields not applicable for login and forgot
1432 if ($type == 'login' || $type == 'forgot') {
1433 return true;
1434 }
1435
1436
1437 if ($type == 'account' || $type == 'register') {
1438 if (isset($data['password'])) {
1439 unset($data['password']);
1440 }
1441 }
1442
1443 if ($type == 'register') {
1444 if (isset($data['username'])) {
1445 unset($data['username']);
1446 }
1447 if (isset($data['email'])) {
1448 unset($data['email']);
1449 }
1450 if (isset($data['display_name'])) {
1451 unset($data['display_name']);
1452 }
1453 if (isset($data['first_name'])) {
1454 unset($data['first_name']);
1455 }
1456 if (isset($data['last_name'])) {
1457 unset($data['last_name']);
1458 }
1459 if (isset($data['bio'])) {
1460 unset($data['bio']);
1461 }
1462 }
1463
1464 if (empty($data)) {
1465 // no extra fields. so just return
1466 return true;
1467 } else {
1468 foreach($data as $key => $value) {
1469 uwp_update_usermeta($user_id, $key, $value);
1470 }
1471 return true;
1472 }
1473 }
1474
1475 /**
1476 * Logs the error message.
1477 *
1478 * @since 1.0.0
1479 * @package userswp
1480 *
1481 * @param array|object|string $log Error message.
1482 *
1483 * @return void
1484 */
1485 public static function uwp_error_log($log){
1486 uwp_error_log($log);
1487 }
1488
1489 /**
1490 *
1491 *
1492 * @since 1.0.0
1493 * @since 1.0.12 Unlink file.
1494 * @package userswp
1495 * @return void
1496 */
1497 public function upload_file_remove() {
1498
1499 $htmlvar = strip_tags(esc_sql($_POST['htmlvar']));
1500 $user_id = (int) strip_tags(esc_sql($_POST['uid']));
1501 $permission = false;
1502 if ($user_id == get_current_user_id()) {
1503 $permission = true;
1504 } else {
1505 if (current_user_can('manage_options')) {
1506 $permission = true;
1507 }
1508 }
1509 if ($permission) {
1510 // Remove file
1511 if ($htmlvar == "banner_thumb") {
1512 $file = uwp_get_usermeta($user_id, 'banner_thumb');
1513 $type = 'banner';
1514 } elseif ($htmlvar == "avatar_thumb") {
1515 $file = uwp_get_usermeta($user_id, 'avatar_thumb');
1516 $type = 'avatar';
1517 } else {
1518 $file = '';
1519 $type = '';
1520 }
1521
1522 uwp_update_usermeta($user_id, $htmlvar, '');
1523
1524 if ($file) {
1525 $uploads = wp_upload_dir();
1526 $upload_path = $uploads['basedir'];
1527 $unlink_file = untrailingslashit($upload_path) . '/' . ltrim($file, '/');
1528
1529 if (is_file($unlink_file) && file_exists($unlink_file)) {
1530 @unlink($unlink_file);
1531 $unlink_ori_file = str_replace('_uwp_'.$type.'_thumb'.'.', '.', $unlink_file);
1532 if (is_file($unlink_ori_file) && file_exists($unlink_ori_file)) {
1533 @unlink($unlink_ori_file);
1534 }
1535 }
1536 }
1537 }
1538 die();
1539 }
1540
1541
1542 /**
1543 * Form field template for datepicker field type.
1544 *
1545 * @since 1.0.0
1546 * @package userswp
1547 *
1548 * @param string $html Form field html
1549 * @param object $field Field info.
1550 * @param string $value Form field default value.
1551 * @param string $form_type Form type
1552 *
1553 * @return string Modified form field html.
1554 */
1555 public function form_input_datepicker($html, $field, $value, $form_type){
1556
1557 // Check if there is a field specific filter.
1558 if(has_filter("uwp_form_input_html_datepicker_{$field->htmlvar_name}")){
1559 $html = apply_filters("uwp_form_input_html_datepicker_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1560 }
1561
1562 // If no html then we run the standard output.
1563 if(empty($html)) {
1564
1565 $design_style = uwp_get_option("design_style","bootstrap");
1566 $bs_form_group = $design_style ? "form-group" : "";
1567 $bs_sr_only = $design_style ? "sr-only" : "";
1568 $bs_form_control = $design_style ? "form-control" : "";
1569
1570 ob_start(); // Start buffering;
1571
1572 $extra_fields = unserialize($field->extra_fields);
1573
1574 if ($extra_fields['date_format'] == '')
1575 $extra_fields['date_format'] = 'yy-mm-dd';
1576
1577 $date_format = $extra_fields['date_format'];
1578 $jquery_date_format = $date_format;
1579
1580 if (!empty($value) && !is_string($value)) {
1581 $value = date('Y-m-d', $value);
1582 }
1583
1584
1585 // check if we need to change the format or not
1586 $date_format_len = strlen(str_replace(' ', '', $date_format));
1587 if($date_format_len>5){// if greater then 5 then it's the old style format.
1588
1589 $search = array('dd','d','DD','mm','m','MM','yy'); //jQuery UI datepicker format
1590 $replace = array('d','j','l','m','n','F','Y');//PHP date format
1591
1592 $date_format = str_replace($search, $replace, $date_format);
1593 }else{
1594 $jquery_date_format = uwp_date_format_php_to_jqueryui( $jquery_date_format );
1595 }
1596 if($value=='0000-00-00'){$value='';}//if date not set, then mark it empty
1597 $value = uwp_date($value, 'Y-m-d', $date_format);
1598 ?>
1599 <script type="text/javascript">
1600
1601 jQuery(function () {
1602
1603 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker({changeMonth: true, changeYear: true
1604 <?php if($field->htmlvar_name == 'dob'){ echo ", yearRange: '1900:+0'"; } else { echo ", yearRange: '1900:2050'"; }?>
1605 <?php echo apply_filters("uwp_datepicker_extra_{$field->htmlvar_name}",'');?>});
1606
1607 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker("option", "dateFormat", '<?php echo $jquery_date_format;?>');
1608
1609 <?php if(!empty($value)){?>
1610 var parsedDate = jQuery.datepicker.parseDate('yy-mm-dd', '<?php echo $value;?>');
1611 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker("setDate", parsedDate);
1612 <?php } ?>
1613
1614 });
1615
1616 </script>
1617 <div id="<?php echo $field->htmlvar_name;?>_row"
1618 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row clearfix uwp_clear uwp-fieldset-details <?php echo esc_attr($bs_form_group);?>">
1619
1620 <?php
1621 $site_title = uwp_get_form_label($field);
1622 if (!is_admin()) { ?>
1623 <label class="<?php echo esc_attr($bs_sr_only);?>">
1624 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1625 <?php if ($field->is_required) echo '<span>*</span>';?>
1626 </label>
1627 <?php } ?>
1628
1629 <input name="<?php echo $field->htmlvar_name;?>"
1630 id="<?php echo $field->htmlvar_name;?>"
1631 placeholder="<?php echo $site_title; ?>"
1632 title="<?php echo $site_title; ?>"
1633 type="text"
1634 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
1635 value="<?php echo esc_attr($value);?>" class="uwp_textfield <?php echo esc_attr($bs_form_control);?>"/>
1636
1637 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1638 <?php if ($field->is_required) { ?>
1639 <span class="uwp_message_error invalid-feedback"><?php _e($field->required_msg, 'userswp'); ?></span>
1640 <?php } ?>
1641 </div>
1642
1643 <?php
1644 $html = ob_get_clean();
1645 }
1646
1647 return $html;
1648 }
1649
1650 /**
1651 * Form field template for time field type.
1652 *
1653 * @since 1.0.0
1654 * @package userswp
1655 *
1656 * @param string $html Form field html
1657 * @param object $field Field info.
1658 * @param string $value Form field default value.
1659 * @param string $form_type Form type
1660 *
1661 * @return string Modified form field html.
1662 */
1663 public function form_input_time($html, $field, $value, $form_type){
1664
1665 if(has_filter("uwp_form_input_html_time_{$field->htmlvar_name}")){
1666
1667 $html = apply_filters("uwp_form_input_html_time_{$field->htmlvar_name}",$html, $field, $value, $form_type);
1668 }
1669
1670 // If no html then we run the standard output.
1671 if(empty($html)) {
1672
1673 $design_style = uwp_get_option("design_style","bootstrap");
1674 $bs_form_group = $design_style ? "form-group" : "";
1675 $bs_sr_only = $design_style ? "sr-only" : "";
1676 $bs_form_control = $design_style ? "form-control bg-white" : "";
1677
1678 ob_start(); // Start buffering;
1679
1680 if ($value != '')
1681 $value = date('H:i', strtotime($value));
1682 ?>
1683 <script type="text/javascript">
1684 jQuery(document).ready(function () {
1685
1686 jQuery('#<?php echo $field->htmlvar_name;?>').timepicker({
1687 showPeriod: true,
1688 showLeadingZero: true
1689 });
1690 });
1691 </script>
1692 <div id="<?php echo $field->htmlvar_name;?>_row"
1693 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row clearfix uwp_clear uwp-fieldset-details <?php echo esc_attr($bs_form_group);?>">
1694
1695 <?php
1696 $site_title = uwp_get_form_label($field);
1697 if (!is_admin()) { ?>
1698 <label class="<?php echo esc_attr($bs_sr_only);?>">
1699 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1700 <?php if ($field->is_required) echo '<span>*</span>';?>
1701 </label>
1702 <?php } ?>
1703
1704 <input readonly="readonly" name="<?php echo $field->htmlvar_name;?>"
1705 id="<?php echo $field->htmlvar_name;?>"
1706 value="<?php echo esc_attr($value);?>"
1707 placeholder="<?php echo $site_title; ?>"
1708 type="text"
1709 class="uwp_textfield <?php echo esc_attr($bs_form_control);?>"/>
1710
1711 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1712 <?php if ($field->is_required) { ?>
1713 <span class="uwp_message_error invalid-feedback"><?php _e($field->required_msg, 'userswp'); ?></span>
1714 <?php } ?>
1715 </div>
1716 <?php
1717 $html = ob_get_clean();
1718 }
1719
1720 return $html;
1721 }
1722
1723 /**
1724 * Form field template for select field type.
1725 *
1726 * @since 1.0.0
1727 * @package userswp
1728 *
1729 * @param string $html Form field html
1730 * @param object $field Field info.
1731 * @param string $value Form field default value.
1732 * @param string $form_type Form type
1733 *
1734 * @return string Modified form field html.
1735 */
1736 public function form_input_select($html, $field, $value, $form_type){
1737
1738 // Check if there is a field specific filter.
1739 if(has_filter("uwp_form_input_html_select_{$field->htmlvar_name}")){
1740 $html = apply_filters("uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1741 }
1742
1743 // Check if there is a field type specific filter.
1744 if(has_filter("uwp_form_input_html_select_{$field->field_type_key}")){
1745 $html = apply_filters("uwp_form_input_html_select_{$field->field_type_key}", $html, $field, $value, $form_type);
1746 }
1747
1748 // If no html then we run the standard output.
1749 if(empty($html)) {
1750
1751 $design_style = uwp_get_option("design_style","bootstrap");
1752 $bs_form_group = $design_style ? "form-group" : "";
1753 $bs_sr_only = $design_style ? "sr-only" : "";
1754 $bs_form_control = $design_style ? "form-control" : "";
1755
1756 ob_start(); // Start buffering;
1757 $option_values_arr = uwp_string_values_to_options($field->option_values, true);
1758
1759 // bootstrap
1760 if( $design_style ) {
1761
1762 echo aui()->select(array(
1763 'id' => $field->htmlvar_name,
1764 'name' => $field->htmlvar_name,
1765 'placeholder' => uwp_get_form_label( $field ),
1766 'title' => uwp_get_form_label( $field ),
1767 'value' => $value,
1768 'required' => $field->is_required,
1769 'validation_text' => !empty($field->is_required) ? __($field->required_msg, 'userswp') : '',
1770 'help_text' => __( $field->help_text, 'userswp' ),
1771 'label' => uwp_get_form_label( $field ),
1772 'options'=> $option_values_arr,
1773 'select2' => true
1774 ));
1775 }else{
1776 ?>
1777 <div id="<?php echo $field->htmlvar_name;?>_row"
1778 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear <?php echo esc_attr($bs_form_group);?>">
1779
1780 <?php
1781 $site_title = uwp_get_form_label($field);
1782 if (!is_admin()) { ?>
1783 <label class="<?php echo esc_attr($bs_sr_only);?>">
1784 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1785 <?php if ($field->is_required) echo '<span>*</span>';?>
1786 </label>
1787 <?php } ?>
1788
1789 <?php
1790
1791 $select_options = '';
1792 if (!empty($option_values_arr)) {
1793 foreach ($option_values_arr as $option_row) {
1794 if (isset($option_row['optgroup']) && ($option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end')) {
1795 $option_label = isset($option_row['label']) ? $option_row['label'] : '';
1796
1797 $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
1798 } else {
1799 $option_label = isset($option_row['label']) ? $option_row['label'] : '';
1800 $option_value = isset($option_row['value']) ? $option_row['value'] : '';
1801 $selected = $option_value == $value ? 'selected="selected"' : '';
1802
1803 $select_options .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
1804 }
1805 }
1806 }
1807 ?>
1808 <select name="<?php echo $field->htmlvar_name;?>" id="<?php echo $field->htmlvar_name;?>"
1809 class="uwp_textfield aui-select2 <?php echo esc_attr($bs_form_control);?>"
1810 title="<?php echo $site_title; ?>"
1811 data-placeholder="<?php echo __('Choose', 'userswp') . ' ' . $site_title . '&hellip;';?>"
1812 ><?php echo $select_options;?>
1813 </select>
1814 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1815 <?php if ($field->is_required) { ?>
1816 <span class="uwp_message_error invalid-feedback"><?php _e($field->required_msg, 'userswp'); ?></span>
1817 <?php } ?>
1818 </div>
1819
1820 <?php
1821 }
1822 $html = ob_get_clean();
1823 }
1824
1825 return $html;
1826 }
1827
1828 /**
1829 * Form field template for multiselect field type.
1830 *
1831 * @since 1.0.0
1832 * @package userswp
1833 *
1834 * @param string $html Form field html
1835 * @param object $field Field info.
1836 * @param string $value Form field default value.
1837 * @param string $form_type Form type
1838 *
1839 * @return string Modified form field html.
1840 */
1841 public function form_input_multiselect($html, $field, $value, $form_type){
1842
1843 // Check if there is a field specific filter.
1844 if(has_filter("uwp_form_input_html_multiselect_{$field->htmlvar_name}")){
1845 $html = apply_filters("uwp_form_input_html_multiselect_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1846 }
1847
1848 if(empty($html)) {
1849
1850 $design_style = uwp_get_option("design_style","bootstrap");
1851 $bs_form_group = $design_style ? "form-group" : "";
1852 $bs_sr_only = $design_style ? "sr-only" : "";
1853 $bs_form_control = $design_style ? "form-control" : "";
1854
1855 ob_start(); // Start buffering;
1856
1857 $multi_display = 'select';
1858 if (!empty($field->extra_fields)) {
1859 $multi_display = unserialize($field->extra_fields);
1860 }
1861
1862 $option_values_arr = uwp_string_values_to_options($field->option_values, true);
1863
1864 // bootstrap
1865 if( $design_style ) {
1866
1867 echo aui()->select(array(
1868 'id' => $field->htmlvar_name,
1869 'name' => $field->htmlvar_name,
1870 'placeholder' => uwp_get_form_label( $field ),
1871 'title' => uwp_get_form_label( $field ),
1872 'value' => $value,
1873 'required' => $field->is_required,
1874 'validation_text' => !empty($field->is_required) ? __($field->required_msg, 'userswp') : '',
1875 'help_text' => __( $field->help_text, 'userswp' ),
1876 'label' => uwp_get_form_label( $field ),
1877 'options'=> $option_values_arr,
1878 'select2' => true,
1879 'multiple' => true
1880 ));
1881 }else {
1882 ?>
1883 <div id="<?php echo $field->htmlvar_name; ?>_row"
1884 class="<?php if ( $field->is_required ) {
1885 echo 'required_field';
1886 } ?> uwp_form_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
1887
1888 <?php
1889 $site_title = uwp_get_form_label( $field );
1890 if ( ! is_admin() ) { ?>
1891 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
1892 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
1893 <?php if ( $field->is_required ) {
1894 echo '<span>*</span>';
1895 } ?>
1896 </label>
1897 <?php } ?>
1898
1899 <input type="hidden" name="<?php echo $field->htmlvar_name; ?>" value=""/>
1900 <?php if ( $multi_display == 'select' ) { ?>
1901 <div class="uwp_multiselect_list">
1902 <select name="<?php echo $field->htmlvar_name; ?>[]"
1903 id="<?php echo $field->htmlvar_name; ?>"
1904 title="<?php echo $site_title; ?>"
1905 data-placeholder="<?php echo $site_title; ?>"
1906 class="aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
1907 >
1908 <?php
1909 } else {
1910 ?>
1911 <ul class="uwp_multi_choice">
1912 <?php
1913 }
1914
1915 $option_values_arr = uwp_string_values_to_options( $field->option_values, true );
1916 $select_options = '';
1917 if ( ! empty( $option_values_arr ) ) {
1918 foreach ( $option_values_arr as $option_row ) {
1919 if ( isset( $option_row['optgroup'] ) && ( $option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end' ) ) {
1920 $option_label = isset( $option_row['label'] ) ? $option_row['label'] : '';
1921
1922 if ( $multi_display == 'select' ) {
1923 $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
1924 } else {
1925 $select_options .= $option_row['optgroup'] == 'start' ? '<li>' . $option_label . '</li>' : '';
1926 }
1927 } else {
1928 $option_label = isset( $option_row['label'] ) ? $option_row['label'] : '';
1929 $option_value = isset( $option_row['value'] ) ? $option_row['value'] : '';
1930 $selected = $option_value == $value ? 'selected="selected"' : '';
1931 $checked = '';
1932
1933 if ( ( ! is_array( $value ) && trim( $value ) != '' ) || ( is_array( $value ) && ! empty( $value ) ) ) {
1934 if ( ! is_array( $value ) ) {
1935 $value_array = explode( ',', $value );
1936 } else {
1937 $value_array = $value;
1938 }
1939
1940 if ( is_array( $value_array ) ) {
1941 if ( in_array( $option_value, $value_array ) ) {
1942 $selected = 'selected="selected"';
1943 $checked = 'checked="checked"';
1944 }
1945 }
1946 }
1947
1948 if ( $multi_display == 'select' ) {
1949 $select_options .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . '>' . $option_label . '</option>';
1950 } else {
1951 $select_options .= '<li><input name="' . $field->name . '[]" ' . $checked . ' value="' . esc_attr( $option_value ) . '" class="uwp-' . $multi_display . '" type="' . $multi_display . '" />&nbsp;' . $option_label . ' </li>';
1952 }
1953 }
1954 }
1955 }
1956 echo $select_options;
1957
1958 if ( $multi_display == 'select' ) { ?></select></div>
1959 <?php } else { ?>
1960 </ul>
1961 <?php } ?>
1962 <?php if ( $field->is_required ) { ?>
1963 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
1964 <?php } ?>
1965 </div>
1966 <?php
1967 }
1968 $html = ob_get_clean();
1969 }
1970
1971 return $html;
1972 }
1973
1974 /**
1975 * Form field template for file field type.
1976 *
1977 * @since 1.0.0
1978 * @package userswp
1979 *
1980 * @param string $html Form field html
1981 * @param object $field Field info.
1982 * @param string $value Form field default value.
1983 * @param string $form_type Form type
1984 *
1985 * @return string Modified form field html.
1986 */
1987 public function form_input_file($html, $field, $value, $form_type){
1988
1989 $file_obj = new UsersWP_Files();
1990
1991 // Check if there is a field specific filter.
1992 if(has_filter("uwp_form_input_html_file_{$field->htmlvar_name}")){
1993 $html = apply_filters("uwp_form_input_html_file_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1994 }
1995
1996 // If no html then we run the standard output.
1997 if(empty($html)) {
1998
1999 $design_style = uwp_get_option("design_style","bootstrap");
2000 $bs_form_group = $design_style ? "form-group" : "";
2001 $bs_sr_only = $design_style ? "sr-only" : "";
2002 $bs_form_control = $design_style ? "form-control" : "";
2003
2004 ob_start(); // Start buffering;
2005
2006 ?>
2007 <div id="<?php echo $field->htmlvar_name;?>_row"
2008 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr($bs_form_group);?>">
2009
2010 <?php
2011 $site_title = uwp_get_form_label($field);
2012 if (!is_admin()) { ?>
2013 <label class="<?php echo esc_attr($bs_sr_only);?>">
2014 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2015 <?php if ($field->is_required) echo '<span>*</span>';?>
2016 </label>
2017 <?php } ?>
2018
2019 <?php echo $file_obj->file_upload_preview($field, $value); ?>
2020 <input name="<?php echo $field->htmlvar_name; ?>"
2021 class="<?php echo $field->css_class; ?> <?php echo esc_attr($bs_form_control);?>"
2022 placeholder="<?php echo $site_title; ?>"
2023 title="<?php echo $site_title; ?>"
2024 <?php
2025 if ($field->is_required == 1 ) { echo 'data-is-required="1"'; }
2026 if ($field->is_required == 1 && !$value) { echo 'required="required"'; }
2027 ?>
2028 type="<?php echo $field->field_type; ?>">
2029 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2030 <?php if ($field->is_required) { ?>
2031 <span class="uwp_message_error invalid-feedback"><?php _e($field->required_msg, 'userswp'); ?></span>
2032 <?php } ?>
2033 </div>
2034
2035 <?php
2036 $html = ob_get_clean();
2037 }
2038
2039 return $html;
2040 }
2041
2042 /**
2043 * Form field template for checkbox field type.
2044 *
2045 * @since 1.0.0
2046 * @package userswp
2047 *
2048 * @param string $html Form field html
2049 * @param object $field Field info.
2050 * @param string $value Form field default value.
2051 * @param string $form_type Form type
2052 *
2053 * @return string Modified form field html.
2054 */
2055 public function form_input_checkbox($html, $field, $value, $form_type){
2056
2057 // Check if there is a field specific filter.
2058 if(has_filter("uwp_form_input_html_checkbox_{$field->htmlvar_name}")){
2059 $html = apply_filters("uwp_form_input_html_checkbox_{$field->htmlvar_name}", $html, $field, $value, $form_type);
2060 }
2061
2062 // If no html then we run the standard output.
2063 if(empty($html)) {
2064
2065 $design_style = uwp_get_option("design_style","bootstrap");
2066 $bs_form_group = $design_style ? "form-group form-check" : "";
2067 $bs_sr_only = $design_style ? "form-check-label" : "";
2068 $bs_form_control = $design_style ? "form-check-input" : "";
2069
2070 ob_start(); // Start buffering;
2071 $site_title = uwp_get_form_label($field);
2072
2073 $design_style = uwp_get_option("design_style","bootstrap");
2074
2075 // bootstrap
2076 if( $design_style ) {
2077
2078 echo aui()->input(array(
2079 'type' => 'checkbox',
2080 'id' => wp_doing_ajax() ? $field->htmlvar_name."_ajax" : $field->htmlvar_name,
2081 'name' => $field->htmlvar_name,
2082 'placeholder' => uwp_get_form_label( $field ),
2083 'title' => uwp_get_form_label( $field ),
2084 'value' => $value,
2085 'required' => $field->is_required,
2086 'validation_text' => !empty($field->is_required) ? __($field->required_msg, 'userswp') : '',
2087 'help_text' => __( $field->help_text, 'userswp' ),
2088 'label' => uwp_get_form_label( $field ),
2089 ));
2090 }else{
2091 ?>
2092 <div id="<?php echo $field->htmlvar_name;?>_row"
2093 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr($bs_form_group);?>">
2094 <?php if(!empty($design_style)){ ?>
2095 <label class="<?php echo $bs_sr_only; ?>">
2096 <?php } ?>
2097 <input type="hidden" name="<?php echo $field->htmlvar_name; ?>" value="0" />
2098 <input name="<?php echo $field->htmlvar_name; ?>"
2099 class="<?php echo $field->css_class; ?> <?php echo esc_attr($bs_form_control);?>"
2100 placeholder="<?php echo $site_title; ?>"
2101 title="<?php echo $site_title; ?>"
2102 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2103 <?php if ($value == '1') { echo 'checked="checked"'; } ?>
2104 type="<?php echo $field->field_type; ?>"
2105 value="1">
2106 <?php
2107 echo (trim($site_title)) ? $site_title : '&nbsp;';
2108 ?>
2109 <?php if(!empty($design_style)){ ?>
2110 </label>
2111 <?php } ?>
2112 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2113 <?php if ($field->is_required) { ?>
2114 <span class="uwp_message_error invalid-feedback"><?php _e($field->required_msg, 'userswp'); ?></span>
2115 <?php } ?>
2116 </div>
2117
2118 <?php
2119
2120 }
2121 $html = ob_get_clean();
2122
2123 }
2124
2125 return $html;
2126 }
2127
2128 /**
2129 * Form field template for radio field type.
2130 *
2131 * @since 1.0.0
2132 * @package userswp
2133 *
2134 * @param string $html Form field html
2135 * @param object $field Field info.
2136 * @param string $value Form field default value.
2137 * @param string $form_type Form type
2138 *
2139 * @return string Modified form field html.
2140 */
2141 public function form_input_radio($html, $field, $value, $form_type){
2142
2143 // Check if there is a field specific filter.
2144 if(has_filter("uwp_form_input_html_radio_{$field->htmlvar_name}")){
2145 $html = apply_filters("uwp_form_input_html_radio_{$field->htmlvar_name}", $html, $field, $value, $form_type);
2146 }
2147
2148 // If no html then we run the standard output.
2149 if(empty($html)) {
2150
2151 $design_style = uwp_get_option("design_style","bootstrap");
2152 $bs_form_group = $design_style ? "form-group form-check-inline" : "";
2153 $bs_sr_only = $design_style ? "sr-only" : "";
2154 $bs_label_class = $design_style ? "form-check-label" : "";
2155 $bs_form_control = $design_style ? "form-check-input" : "";
2156
2157 ob_start(); // Start buffering;
2158
2159 ?>
2160 <div id="<?php echo $field->htmlvar_name;?>_row"
2161 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr($bs_form_group);?>">
2162
2163 <?php
2164 $site_title = uwp_get_form_label($field);
2165 if (!is_admin()) { ?>
2166 <label class="<?php echo esc_attr($bs_sr_only);?>">
2167 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2168 <?php if ($field->is_required) echo '<span>*</span>';?>
2169 </label>
2170 <?php } ?>
2171
2172 <?php if ($field->option_values) {
2173 $option_values = uwp_string_values_to_options($field->option_values, true);
2174
2175 if (!empty($option_values)) {
2176 $count = 0;
2177 foreach ($option_values as $option_value) {
2178 if (empty($option_value['optgroup'])) {
2179 $count++;
2180 if ($count == 1) {
2181 $class = "uwp-radio-first";
2182 } else {
2183 $class = "";
2184 }
2185 ?>
2186 <?php if(!empty($design_style)){ ?>
2187 <label class="<?php echo $bs_label_class; ?>">
2188 <?php } else { ?>
2189 <span class="uwp-radios <?php echo $class; ?>">
2190 <?php } ?>
2191 <input name="<?php echo $field->htmlvar_name; ?>"
2192 id="<?php echo $field->htmlvar_name; ?>"
2193 title="<?php echo esc_attr($option_value['label']); ?>"
2194 <?php checked($value, $option_value['value']);?>
2195 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2196 value="<?php echo esc_attr($option_value['value']); ?>"
2197 class="uwp-radio <?php echo esc_attr($bs_form_control);?>" type="radio" />
2198 <?php echo $option_value['label']; ?>
2199 <?php if(!empty($design_style)){ ?>
2200 </label>
2201 <?php } else { ?>
2202 </span>
2203 <?php
2204 }
2205 }
2206 }
2207 }
2208 }
2209 ?>
2210 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2211 <?php if ($field->is_required) { ?>
2212 <span class="uwp_message_error invalid-feedback"><?php _e($field->required_msg, 'userswp'); ?></span>
2213 <?php } ?>
2214 </div>
2215 <?php
2216 $html = ob_get_clean();
2217 }
2218
2219 return $html;
2220 }
2221
2222 /**
2223 * Form field template for text field type.
2224 *
2225 * @since 1.0.0
2226 * @package userswp
2227 *
2228 * @param string $html Form field html
2229 * @param object $field Field info.
2230 * @param string $value Form field default value.
2231 * @param string $form_type Form type
2232 *
2233 * @return string Modified form field html.
2234 */
2235 public function form_input_text($html, $field, $value, $form_type){
2236
2237 // Check if there is a custom field specific filter.
2238 if(has_filter("uwp_form_input_text_{$field->htmlvar_name}")){
2239 $html = apply_filters("uwp_form_input_text_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2240 }
2241
2242 // If no html then we run the standard output.
2243 if(empty($html)) {
2244
2245 ob_start(); // Start buffering;
2246
2247 $type = 'text';
2248 $step = false;
2249 //number and float validation $validation_pattern
2250 if(isset($field->data_type) && $field->data_type == 'INT'){
2251 $type = 'number';
2252 } elseif(isset($field->data_type) && $field->data_type == 'FLOAT'){
2253 $dp = $field->decimal_point;
2254 switch ($dp) {
2255 case "1":
2256 $step = "0.1";
2257 break;
2258 case "2":
2259 $step = "0.01";
2260 break;
2261 case "3":
2262 $step = "0.001";
2263 break;
2264 case "4":
2265 $step = "0.0001";
2266 break;
2267 case "5":
2268 $step = "0.00001";
2269 break;
2270 case "6":
2271 $step = "0.000001";
2272 break;
2273 case "7":
2274 $step = "0.0000001";
2275 break;
2276 case "8":
2277 $step = "0.00000001";
2278 break;
2279 case "9":
2280 $step = "0.000000001";
2281 break;
2282 case "10":
2283 $step = "0.0000000001";
2284 break;
2285 default:
2286 $step = "0.01";
2287 break;
2288 }
2289 $type = 'number';
2290 }
2291
2292
2293 $site_title = uwp_get_form_label($field);
2294 $manual_label = apply_filters('uwp_login_username_label_manual', true);
2295 if ($manual_label
2296 && isset($field->form_type)
2297 && $field->form_type == 'login'
2298 && $field->htmlvar_name == 'username') {
2299 $site_title = __("Username or Email", 'userswp');
2300 }
2301
2302 $design_style = uwp_get_option("design_style","bootstrap");
2303 $bs_form_group = $design_style ? "form-group" : "";
2304 $bs_sr_only = $design_style ? "sr-only" : "";
2305 $bs_form_control = $design_style ? "form-control" : "";
2306
2307 // bootstrap
2308 if( $design_style ){
2309 echo aui()->input(array(
2310 'type' => $type,
2311 'id' => $field->htmlvar_name,
2312 'name' => $field->htmlvar_name,
2313 'placeholder' => $site_title,
2314 'title' => $site_title,
2315 'value' => $value,
2316 'required' => $field->is_required,
2317 'validation_text' => __($field->required_msg, 'userswp'),
2318 'help_text' => __( $field->help_text, 'userswp' ),
2319 'label' => is_admin() ? '' : uwp_get_form_label( $field ),
2320 'step' => $step
2321 ));
2322 }else{
2323 ?>
2324 <div id="<?php echo $field->htmlvar_name;?>_row" class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr($bs_form_group);?>">
2325 <?php
2326
2327 if (!is_admin()) { ?>
2328 <label class="<?php echo esc_attr($bs_sr_only);?>">
2329 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2330 <?php if ($field->is_required) echo '<span>*</span>';?>
2331 </label>
2332 <?php }
2333 ?>
2334
2335 <input name="<?php echo $field->htmlvar_name;?>" class="<?php echo $field->css_class; ?> uwp_textfield <?php echo esc_attr($bs_form_control);?>"
2336 id="<?php echo $field->htmlvar_name;?>"
2337 placeholder="<?php echo $site_title; ?>"
2338 value="<?php echo esc_attr(stripslashes($value));?>"
2339 title="<?php echo $site_title; ?>"
2340 oninvalid="this.setCustomValidity('<?php _e($field->required_msg, 'userswp'); ?>')"
2341 oninput="setCustomValidity('')"
2342 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2343 <?php if ($field->for_admin_use == 1) { echo 'readonly="readonly"'; } ?>
2344 type="<?php echo $type; ?>"
2345 <?php if ($step) { echo 'step="'.$step.'"'; } ?>
2346 />
2347 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2348 <?php if ($field->is_required) { ?>
2349 <span class="uwp_message_error invalid-feedback"><?php _e($field->required_msg, 'userswp'); ?></span>
2350 <?php } ?>
2351 </div>
2352
2353
2354 <?php
2355 }
2356 $html = ob_get_clean();
2357 }
2358
2359 return $html;
2360 }
2361
2362 /**
2363 * Form field template for textarea field type.
2364 *
2365 * @since 1.0.0
2366 * @package userswp
2367 *
2368 * @param string $html Form field html
2369 * @param object $field Field info.
2370 * @param string $value Form field default value.
2371 * @param string $form_type Form type
2372 *
2373 * @return string Modified form field html.
2374 */
2375 public function form_input_textarea($html, $field, $value, $form_type){
2376
2377 // Check if there is a field specific filter.
2378 if(has_filter("uwp_form_input_textarea_{$field->htmlvar_name}")){
2379 $html = apply_filters("uwp_form_input_textarea_{$field->htmlvar_name}", $html, $field, $value, $form_type);
2380 }
2381
2382 // If no html then we run the standard output.
2383 if(empty($html)) {
2384
2385 $design_style = uwp_get_option("design_style","bootstrap");
2386 $bs_form_group = $design_style ? "form-group" : "";
2387 $bs_sr_only = $design_style ? "sr-only" : "";
2388 $bs_form_control = $design_style ? "form-control" : "";
2389 $site_title = uwp_get_form_label($field);
2390 ob_start(); // Start buffering;
2391
2392 // bootstrap
2393 if( $design_style ){
2394 echo aui()->textarea(array(
2395 'id' => $field->htmlvar_name,
2396 'name' => $field->htmlvar_name,
2397 'placeholder' => $site_title,
2398 'title' => $site_title,
2399 'value' => stripslashes($value),
2400 'required' => $field->is_required,
2401 'validation_text' => __($field->required_msg, 'userswp'),
2402 'help_text' => __( $field->help_text, 'userswp' ),
2403 'label' => is_admin() ? '' : uwp_get_form_label( $field ),
2404 'rows' => '4'
2405 ));
2406 }else{
2407
2408
2409 ?>
2410
2411 <div id="<?php echo $field->htmlvar_name;?>_row"
2412 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr($bs_form_group);?>">
2413
2414 <?php
2415
2416 if (!is_admin()) { ?>
2417 <label class="<?php echo esc_attr($bs_sr_only);?>">
2418 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2419 <?php if ($field->is_required) echo '<span>*</span>';?>
2420 </label>
2421 <?php } ?>
2422
2423 <textarea name="<?php echo $field->htmlvar_name; ?>"
2424 class="<?php echo $field->css_class; ?> <?php echo esc_attr($bs_form_control);?>"
2425 placeholder="<?php echo $site_title; ?>"
2426 title="<?php echo $site_title; ?>"
2427 oninvalid="this.setCustomValidity('<?php _e($field->required_msg, 'userswp'); ?>')"
2428 oninput="setCustomValidity('')"
2429 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2430 type="<?php echo $field->field_type; ?>"
2431 rows="4"><?php echo stripslashes($value); ?></textarea>
2432 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2433 <?php if ($field->is_required) { ?>
2434 <span class="uwp_message_error invalid-feedback"><?php _e($field->required_msg, 'userswp'); ?></span>
2435 <?php } ?>
2436 </div>
2437
2438 <?php
2439 }
2440 $html = ob_get_clean();
2441 }
2442
2443 return $html;
2444 }
2445
2446 /**
2447 * Form field template for fieldset field type.
2448 *
2449 * @since 1.0.0
2450 * @package userswp
2451 *
2452 * @param string $html Form field html
2453 * @param object $field Field info.
2454 * @param string $value Form field default value.
2455 * @param string $form_type Form type
2456 *
2457 * @return string Modified form field html.
2458 */
2459 public function form_input_fieldset($html, $field, $value, $form_type) {
2460 // Check if there is a custom field specific filter.
2461 if(has_filter("uwp_form_input_fieldset_{$field->htmlvar_name}")){
2462 $html = apply_filters("uwp_form_input_fieldset_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2463 }
2464
2465 // If no html then we run the standard output.
2466 if(empty($html)) {
2467
2468 ob_start(); // Start buffering;
2469 ?>
2470 <h3 class="uwp_input_fieldset <?php echo $field->css_class; ?>">
2471 <?php echo $field->site_title;; ?>
2472 <?php if ( $field->help_text != '' ) {
2473 echo '<small>( ' . $field->help_text . ' )</small>';
2474 } ?></h3>
2475 <?php
2476 $html = ob_get_clean();
2477 }
2478
2479 return $html;
2480 }
2481
2482 /**
2483 * Form field template for url field type.
2484 *
2485 * @since 1.0.0
2486 * @package userswp
2487 *
2488 * @param string $html Form field html
2489 * @param object $field Field info.
2490 * @param string $value Form field default value.
2491 * @param string $form_type Form type
2492 *
2493 * @return string Modified form field html.
2494 */
2495 public function form_input_url($html, $field, $value, $form_type){
2496
2497
2498 // Check if there is a custom field specific filter.
2499 if(has_filter("uwp_form_input_url_{$field->htmlvar_name}")){
2500 $html = apply_filters("uwp_form_input_url_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2501 }
2502
2503 // If no html then we run the standard output.
2504 if(empty($html)) {
2505
2506 $design_style = uwp_get_option("design_style","bootstrap");
2507 $bs_form_group = $design_style ? "form-group" : "";
2508 $bs_sr_only = $design_style ? "sr-only" : "";
2509 $bs_form_control = $design_style ? "form-control" : "";
2510
2511 ob_start(); // Start buffering;
2512
2513 // bootstrap
2514 if( $design_style ){
2515 echo aui()->input(array(
2516 'type' => 'url',
2517 'id' => $field->htmlvar_name,
2518 'name' => $field->htmlvar_name,
2519 'placeholder' => uwp_get_form_label( $field ),
2520 'title' => uwp_get_form_label( $field ),
2521 'value' => $value,
2522 'required' => $field->is_required,
2523 'validation_text' => __( 'Please enter a valid URL including http://', 'userswp' ),
2524 'help_text' => __( $field->help_text, 'userswp' ),
2525 'label' => is_admin() ? '' : uwp_get_form_label( $field )
2526 ));
2527 }else {
2528
2529
2530 ?>
2531 <div id="<?php echo $field->htmlvar_name; ?>_row"
2532 class="<?php if ( $field->is_required ) {
2533 echo 'required_field';
2534 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2535
2536 <?php
2537 $site_title = uwp_get_form_label( $field );
2538 if ( ! is_admin() ) { ?>
2539 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2540 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
2541 <?php if ( $field->is_required ) {
2542 echo '<span>*</span>';
2543 } ?>
2544 </label>
2545 <?php } ?>
2546
2547 <input name="<?php echo $field->htmlvar_name; ?>"
2548 class="<?php //echo $field->css_class;
2549 ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
2550 id="<?php echo $field->htmlvar_name; ?>"
2551 placeholder="<?php echo $site_title; ?>"
2552 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
2553 title="<?php echo $site_title; ?>"
2554 <?php if ( $field->is_required == 1 ) {
2555 echo 'required="required"';
2556 } ?>
2557 type="url"
2558 oninvalid="setCustomValidity('<?php _e( 'Please enter a valid URL including http://', 'userswp' ); ?>')"
2559 onchange="try{setCustomValidity('')}catch(e){}"
2560 />
2561 <span class="uwp_message_note"><?php _e( $field->help_text, 'userswp' ); ?></span>
2562 <?php if ( $field->is_required ) { ?>
2563 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
2564 <?php } ?>
2565 </div>
2566
2567 <?php
2568 }
2569
2570 $html = ob_get_clean();
2571 }
2572
2573 return $html;
2574 }
2575
2576 /**
2577 * Form field template for email field type.
2578 *
2579 * @since 1.0.0
2580 * @package userswp
2581 *
2582 * @param string $html Form field html
2583 * @param object $field Field info.
2584 * @param string $value Form field default value.
2585 * @param string $form_type Form type
2586 *
2587 * @return string Modified form field html.
2588 */
2589 public function form_input_email($html, $field, $value, $form_type){
2590
2591
2592 // Check if there is a custom field specific filter.
2593 if(has_filter("uwp_form_input_email_{$field->htmlvar_name}")){
2594 $html = apply_filters("uwp_form_input_email_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2595 }
2596
2597 // If no html then we run the standard output.
2598 if(empty($html)) {
2599
2600 $design_style = uwp_get_option("design_style","bootstrap");
2601 $bs_form_group = $design_style ? "form-group" : "";
2602 $bs_sr_only = $design_style ? "sr-only" : "";
2603 $bs_form_control = $design_style ? "form-control" : "";
2604
2605 ob_start(); // Start buffering;
2606
2607 if( $design_style ){
2608 echo aui()->input(array(
2609 'type' => 'email',
2610 'id' => $field->htmlvar_name,
2611 'name' => $field->htmlvar_name,
2612 'placeholder' => uwp_get_form_label( $field ),
2613 'title' => uwp_get_form_label( $field ),
2614 'value' => $value,
2615 'required' => $field->is_required,
2616 'help_text' => __( $field->help_text, 'userswp' ),
2617 'label' => is_admin() ? '' : uwp_get_form_label( $field )
2618 ));
2619 }else {
2620
2621
2622 ?>
2623 <div id="<?php echo $field->htmlvar_name; ?>_row"
2624 class="<?php if ( $field->is_required ) {
2625 echo 'required_field';
2626 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2627
2628 <?php
2629 $site_title = uwp_get_form_label( $field );
2630 if ( ! is_admin() ) { ?>
2631 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2632 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
2633 <?php if ( $field->is_required ) {
2634 echo '<span>*</span>';
2635 } ?>
2636 </label>
2637 <?php } ?>
2638
2639 <input name="<?php echo $field->htmlvar_name; ?>"
2640 class="<?php echo $field->css_class; ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
2641 id="<?php echo $field->htmlvar_name; ?>"
2642 placeholder="<?php echo $site_title; ?>"
2643 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
2644 title="<?php echo $site_title; ?>"
2645 <?php if ( $field->is_required == 1 ) {
2646 echo 'required="required"';
2647 } ?>
2648 type="email"
2649 />
2650 <span class="uwp_message_note"><?php _e( $field->help_text, 'userswp' ); ?></span>
2651 <?php if ( $field->is_required ) { ?>
2652 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
2653 <?php } ?>
2654 </div>
2655
2656
2657 <?php
2658 }
2659 $html = ob_get_clean();
2660
2661 }
2662
2663 if(has_filter("uwp_form_input_email_{$field->htmlvar_name}_after")){
2664 $html = apply_filters("uwp_form_input_email_{$field->htmlvar_name}_after",$html, $field, $value, $form_type);
2665 }
2666
2667 return $html;
2668 }
2669
2670 /**
2671 * Form field template for password field type.
2672 *
2673 * @since 1.0.0
2674 * @package userswp
2675 *
2676 * @param string $html Form field html
2677 * @param object $field Field info.
2678 * @param string $value Form field default value.
2679 * @param string $form_type Form type
2680 *
2681 * @return string Modified form field html.
2682 */
2683 public function form_input_password($html, $field, $value, $form_type){
2684
2685
2686 // Check if there is a custom field specific filter.
2687 if(has_filter("uwp_form_input_password_{$field->htmlvar_name}")){
2688 $html = apply_filters("uwp_form_input_password_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2689 }
2690
2691 // If no html then we run the standard output.
2692 if(empty($html)) {
2693
2694 $design_style = uwp_get_option("design_style","bootstrap");
2695 $bs_form_group = $design_style ? "form-group" : "";
2696 $bs_sr_only = $design_style ? "sr-only" : "";
2697 $bs_form_control = $design_style ? "form-control" : "";
2698
2699 ob_start(); // Start buffering;
2700
2701 if( $design_style ){
2702 echo aui()->input(array(
2703 'type' => 'password',
2704 'id' => $field->htmlvar_name,
2705 'name' => $field->htmlvar_name,
2706 'placeholder' => uwp_get_form_label( $field ),
2707 'title' => uwp_get_form_label( $field ),
2708 'value' => $value,
2709 'required' => $field->is_required,
2710 'help_text' => __( $field->help_text, 'userswp' ),
2711 'label' => is_admin() ? '' : uwp_get_form_label( $field )
2712 ));
2713 }else {
2714 ?>
2715 <div id="<?php echo $field->htmlvar_name; ?>_row" class="<?php if ( $field->is_required ) {
2716 echo 'required_field';
2717 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2718 <?php
2719 $site_title = uwp_get_form_label( $field );
2720 if ( ! is_admin() ) { ?>
2721 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2722 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
2723 <?php if ( $field->is_required ) {
2724 echo '<span>*</span>';
2725 } ?>
2726 </label>
2727 <?php } ?>
2728
2729 <input name="<?php echo $field->htmlvar_name; ?>"
2730 class="<?php echo $field->css_class; ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
2731 id="<?php echo $field->htmlvar_name; ?>"
2732 placeholder="<?php echo $site_title; ?>"
2733 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
2734 title="<?php echo $site_title; ?>"
2735 <?php if ( $field->is_required == 1 ) {
2736 echo 'required="required"';
2737 } ?>
2738 type="password"
2739 />
2740 <span class="uwp_message_note"><?php _e( $field->help_text, 'userswp' ); ?></span>
2741 <?php if ( $field->is_required ) { ?>
2742 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
2743 <?php } ?>
2744 </div>
2745
2746
2747 <?php
2748 }
2749
2750 $html = ob_get_clean();
2751 }
2752
2753 if(has_filter("uwp_form_input_password_{$field->htmlvar_name}_after")){
2754 $html = apply_filters("uwp_form_input_password_{$field->htmlvar_name}_after",$html, $field, $value, $form_type);
2755 }
2756
2757 return $html;
2758 }
2759
2760 /**
2761 * Form field template for Phone field.
2762 *
2763 * @since 1.0.0
2764 *
2765 * @param string $html Form field html
2766 * @param object $field Field info.
2767 * @param string $value Form field default value.
2768 * @param string $form_type Form type
2769 *
2770 * @return string $html Modified form field html.
2771 */
2772 public function form_input_phone($html, $field, $value, $form_type){
2773 if(empty($html)) {
2774 $design_style = uwp_get_option("design_style","bootstrap");
2775 $bs_form_group = $design_style ? "form-group" : "";
2776 $bs_sr_only = $design_style ? "sr-only" : "";
2777 $bs_form_control = $design_style ? "form-control" : "";
2778 ob_start(); // Start buffering;
2779
2780 if( $design_style ){
2781 echo aui()->input(array(
2782 'type' => 'tel',
2783 'id' => $field->htmlvar_name,
2784 'name' => $field->htmlvar_name,
2785 'placeholder' => uwp_get_form_label( $field ),
2786 'title' => uwp_get_form_label( $field ),
2787 'value' => $value,
2788 'required' => $field->is_required,
2789 'help_text' => __( $field->help_text, 'userswp' ),
2790 'label' => is_admin() ? '' : uwp_get_form_label( $field )
2791 ));
2792 }else {
2793 ?>
2794 <div id="<?php echo $field->htmlvar_name; ?>_row"
2795 class="<?php if ( $field->is_required ) {
2796 echo 'required_field';
2797 } ?> uwp_form_row clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2798 <?php
2799 $label = $site_title = uwp_get_form_label( $field );
2800 if ( ! is_admin() ) { ?>
2801 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2802 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
2803 <?php if ( $field->is_required ) {
2804 echo '<span>*</span>';
2805 } ?>
2806 </label>
2807 <?php } ?>
2808 <input name="<?php echo $field->htmlvar_name; ?>"
2809 class="<?php echo $field->css_class; ?> <?php echo esc_attr( $bs_form_control ); ?>"
2810 placeholder="<?php echo $label; ?>"
2811 title="<?php echo $label; ?>"
2812 <?php if ( $field->for_admin_use == 1 ) {
2813 echo 'readonly="readonly"';
2814 } ?>
2815 <?php if ( $field->is_required == 1 ) {
2816 echo 'required="required"';
2817 } ?>
2818 type="tel"
2819 value="<?php echo esc_html( $value ); ?>">
2820 </div>
2821 <?php
2822 }
2823 $html = ob_get_clean();
2824 }
2825 return $html;
2826 }
2827
2828 /**
2829 * Adds enctype tag in form for file fields.
2830 *
2831 * @since 1.0.0
2832 * @package userswp
2833 *
2834 * @return void
2835 */
2836 function add_multipart_to_admin_edit_form() {
2837 global $wpdb;
2838 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2839 $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");
2840 if ($fields) {
2841 echo 'enctype="multipart/form-data"';
2842 }
2843 }
2844
2845 /**
2846 * Handles UsersWP custom field requests from admin.
2847 *
2848 * @since 1.0.0
2849 * @package userswp
2850 *
2851 * @param int $user_id User ID.
2852 *
2853 * @return void
2854 */
2855 public function update_profile_extra_admin_edit($user_id) {
2856 global $wpdb;
2857 $file_obj = new UsersWP_Files();
2858 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2859 //Normal fields
2860 $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");
2861 if ($fields) {
2862 $result = uwp_validate_fields($_POST, 'account', $fields);
2863 if(is_wp_error($result )){
2864 die($result->get_error_message());
2865 }
2866 if (isset($result['display_name']) && !empty($result['display_name'])) {
2867 $display_name = $result['display_name'];
2868 } else {
2869 if (!empty($first_name) || !empty($last_name)) {
2870 $display_name = $result['first_name'] . ' ' . $result['last_name'];
2871 } else {
2872 $user_info = get_userdata($user_id);
2873 $display_name = $user_info->user_login;
2874 }
2875 }
2876 $result['display_name'] = $display_name;
2877 if (!is_wp_error($result)) {
2878 foreach ($fields as $field) {
2879 $value = isset($result[$field->htmlvar_name]) ? $result[$field->htmlvar_name] : '';
2880 if ($value == '0' || !empty($value)) {
2881 uwp_update_usermeta($user_id, $field->htmlvar_name, $value);
2882 }
2883 }
2884 }
2885 }
2886
2887 //File fields
2888 $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");
2889 if ($fields) {
2890 $result = $file_obj->validate_uploads($_FILES, 'account', true, $fields);
2891 if (!is_wp_error($result)) {
2892 foreach ($fields as $field) {
2893 $value = $result[$field->htmlvar_name];
2894 if ($value == '0' || !empty($value)) {
2895 uwp_update_usermeta($user_id, $field->htmlvar_name, $value);
2896 }
2897 }
2898 }
2899 }
2900 }
2901
2902 /**
2903 * Form field template for country field.
2904 *
2905 * @since 1.0.0
2906 * @package userswp
2907 *
2908 * @param string $html Form field html
2909 * @param object $field Field info.
2910 * @param string $value Form field default value.
2911 * @param string $form_type Form type
2912 *
2913 * @return string Modified form field html.
2914 */
2915 public function form_input_select_country($html, $field, $value, $form_type){
2916
2917 // If no html then we run the standard output.
2918 if(empty($html)) {
2919
2920 $design_style = uwp_get_option("design_style","bootstrap");
2921 $bs_form_group = $design_style ? "form-group m-0" : ""; // country wrapper div added by JS adds marginso we remove ours
2922 $bs_sr_only = $design_style ? "sr-only" : "";
2923 $bs_form_control = $design_style ? "form-control" : "";
2924
2925 ob_start(); // Start buffering;
2926
2927 ?>
2928 <div id="<?php echo $field->htmlvar_name;?>_row"
2929 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear <?php echo esc_attr($bs_form_group);?>">
2930
2931 <?php
2932 $site_title = uwp_get_form_label($field);
2933 if (!is_admin()) { ?>
2934 <label class="<?php echo esc_attr($bs_sr_only);?>">
2935 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2936 <?php if ($field->is_required) echo '<span>*</span>';?>
2937 </label>
2938 <?php } ?>
2939
2940 <?php
2941 // if value empty set the default
2942 if($value=='' && isset($field->default_value) && $field->default_value){
2943 $value = $field->default_value;
2944 }
2945 $select_country_options = apply_filters('uwp_form_input_select_country',"{defaultCountry: '$value'}",$field, $value, $form_type);
2946 ?>
2947
2948 <input type="text" class="uwp_textfield <?php echo esc_attr($bs_form_control);?>" title="<?php echo $site_title; ?>" id="<?php echo $field->htmlvar_name;if(wp_doing_ajax()){echo "_ajax";}?>" />
2949 <input type="hidden" id="<?php echo $field->htmlvar_name;if(wp_doing_ajax()){echo "_ajax";}?>_code" name="<?php echo $field->htmlvar_name;?>" />
2950
2951 <script>
2952 jQuery(function() {
2953 jQuery("#<?php echo $field->htmlvar_name; if(wp_doing_ajax()){echo "_ajax";}?>").countrySelect(<?php echo $select_country_options;?>);
2954 });
2955 </script>
2956
2957
2958 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2959 <?php if ($field->is_required) { ?>
2960 <span class="uwp_message_error invalid-feedback"><?php _e($field->required_msg, 'userswp'); ?></span>
2961 <?php } ?>
2962 </div>
2963
2964 <?php
2965 $html = ob_get_clean();
2966 }
2967
2968 return $html;
2969 }
2970
2971 /**
2972 * Prints the username link in "Edit Account" page
2973 *
2974 * @since 1.0.0
2975 * @package userswp
2976 *
2977 * @param string $type Page type.
2978 *
2979 * @return void
2980 */
2981 public function display_username_in_account($type) {
2982 if ($type == 'account') {
2983 $user_id = get_current_user_id();
2984 $user_info = get_userdata($user_id);
2985 $display_name = $user_info->user_login;
2986 $template = new UsersWP_Templates();
2987 $logout_url = $template->uwp_logout_url();
2988 ?>
2989 <div class="uwp_account_page_username text-center">
2990 <?php _e('Hello, ', 'userswp'); ?><a href="<?php echo uwp_build_profile_tab_url($user_id); ?>"> @<?php echo $display_name; ?> </a>
2991 <a class="uwp-account-logout-link" href="<?php echo $logout_url; ?>">(<?php _e('Logout', 'userswp'); ?>)</a>
2992 </div>
2993 <?php
2994 }
2995 }
2996
2997
2998 /**
2999 * Adds confirm password field in forms.
3000 *
3001 * @since 1.0.0
3002 * @package userswp
3003 *
3004 * @param string $html Form field html
3005 * @param object $field Field info.
3006 * @param string $value Form field default value.
3007 * @param string $form_type Form type
3008 *
3009 * @return string Modified form field html.
3010 */
3011 public function register_confirm_password_field($html, $field, $value, $form_type) {
3012 if ($form_type == 'register') {
3013 //confirm password field
3014 $extra = array();
3015 if (isset($field->extra_fields) && $field->extra_fields != '') {
3016 $extra = unserialize($field->extra_fields);
3017 }
3018
3019 $enable_confirm_password_field = isset($extra['confirm_password']) ? $extra['confirm_password'] : '0';
3020 if ($enable_confirm_password_field == '1') {
3021
3022 $design_style = uwp_get_option("design_style","bootstrap");
3023 $bs_form_group = $design_style ? "form-group" : "";
3024 $bs_sr_only = $design_style ? "sr-only" : "";
3025 $bs_form_control = $design_style ? "form-control" : "";
3026 $site_title = __("Confirm Password", 'userswp');
3027 ob_start(); // Start buffering;
3028
3029 if( $design_style ){
3030 echo aui()->input(array(
3031 'type' => 'password',
3032 'id' => 'confirm_password',
3033 'name' => 'confirm_password',
3034 'placeholder' => $site_title,
3035 'title' => $site_title,
3036 'value' => $value,
3037 'required' => $field->is_required,
3038 'help_text' => __( $field->help_text, 'userswp' ),
3039 'label' => is_admin() ? '' : $site_title
3040 ));
3041 }else{
3042 ?>
3043 <div id="uwp_account_confirm_password_row"
3044 class="<?php echo 'required_field';?> uwp_form_password_row uwp_clear <?php echo esc_attr($bs_form_group);?>">
3045
3046 <?php
3047
3048 if (!is_admin()) { ?>
3049 <label class="<?php echo esc_attr($bs_sr_only);?>">
3050 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
3051 <?php if ($field->is_required) echo '<span>*</span>';?>
3052 </label>
3053 <?php } ?>
3054
3055 <input name="confirm_password"
3056 class="uwp_textfield <?php echo esc_attr($bs_form_control);?>"
3057 id="uwp_account_confirm_password"
3058 placeholder="<?php echo $site_title; ?>"
3059 value=""
3060 title="<?php echo $site_title; ?>"
3061 <?php echo 'required="required"'; ?>
3062 type="password"
3063 />
3064 </div>
3065
3066 <?php
3067 }
3068 $confirm_html = ob_get_clean();
3069 $html = $html.$confirm_html;
3070 }
3071 }
3072 return $html;
3073 }
3074
3075 /**
3076 * Adds confirm email field in forms.
3077 *
3078 * @since 1.0.0
3079 * @package userswp
3080 *
3081 * @param string $html Form field html
3082 * @param object $field Field info.
3083 * @param string $value Form field default value.
3084 * @param string $form_type Form type
3085 *
3086 * @return string Modified form field html.
3087 */
3088 public function register_confirm_email_field($html, $field, $value, $form_type) {
3089 if ($form_type == 'register') {
3090 //confirm email field
3091 $extra = array();
3092 if (isset($field->extra_fields) && $field->extra_fields != '') {
3093 $extra = unserialize($field->extra_fields);
3094 }
3095 $enable_confirm_email_field = isset($extra['confirm_email']) ? $extra['confirm_email'] : '0';
3096 if ($enable_confirm_email_field == '1') {
3097
3098 $design_style = uwp_get_option("design_style","bootstrap");
3099 $bs_form_group = $design_style ? "form-group" : "";
3100 $bs_sr_only = $design_style ? "sr-only" : "";
3101 $bs_form_control = $design_style ? "form-control" : "";
3102
3103 ob_start(); // Start buffering;
3104 ?>
3105 <div id="uwp_account_confirm_email_row"
3106 class="<?php echo 'required_field';?> uwp_form_email_row uwp_clear <?php echo esc_attr($bs_form_group);?>">
3107
3108 <?php
3109 $site_title = __("Confirm Email", 'userswp');
3110 if (!is_admin()) { ?>
3111 <label class="<?php echo esc_attr($bs_sr_only);?>">
3112 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
3113 <?php if ($field->is_required) echo '<span>*</span>';?>
3114 </label>
3115 <?php } ?>
3116
3117 <input name="confirm_email"
3118 class="uwp_textfield <?php echo esc_attr($bs_form_control);?>"
3119 id="uwp_account_confirm_email"
3120 placeholder="<?php echo $site_title; ?>"
3121 value=""
3122 title="<?php echo $site_title; ?>"
3123 <?php echo 'required="required"'; ?>
3124 type="email"
3125 />
3126 </div>
3127
3128 <?php
3129 $confirm_html = ob_get_clean();
3130 $html = $html.$confirm_html;
3131 }
3132 }
3133 return $html;
3134 }
3135
3136
3137 /**
3138 * Handles the privacy form submission.
3139 *
3140 * @since 1.0.0
3141 * @package userswp
3142 *
3143 * @return void
3144 */
3145 public function privacy_submit_handler() {
3146 if (isset($_POST['uwp_privacy_submit'])) {
3147 if( ! isset( $_POST['uwp_privacy_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_privacy_nonce'], 'uwp-privacy-nonce' ) ) {
3148 return;
3149 }
3150
3151 // Save fields privacy settings
3152 $extra_where = "AND is_public='2'";
3153 $fields = get_account_form_fields($extra_where);
3154 $fields = apply_filters('uwp_account_privacy_fields', $fields);
3155 $user_id = get_current_user_id();
3156 global $wpdb;
3157 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
3158
3159 $user_meta_info = $wpdb->get_row( $wpdb->prepare( "SELECT user_privacy, tabs_privacy FROM $meta_table WHERE user_id = %d", $user_id ) );
3160
3161 if ($fields) {
3162
3163 foreach ($fields as $field) {
3164 $field_name = $field->htmlvar_name.'_privacy';
3165
3166 $field_value = strip_tags(esc_sql($_POST[$field_name]));
3167 $value = '';
3168
3169 if (!empty($user_meta_info->user_privacy)) {
3170 $public_fields = explode(',', $user_meta_info->user_privacy);
3171 if ($field_value == 'no') {
3172 if (!in_array($field_name, $public_fields)) {
3173 $public_fields[] = $field_name;
3174 }
3175 $value = implode(',', $public_fields);
3176 } else {
3177 if (($field_name = array_search($field_name, $public_fields)) !== false) {
3178 unset($public_fields[$field_name]);
3179 }
3180 $value = implode(',', $public_fields);
3181 }
3182 } else {
3183
3184 if ($field_value == 'no') {
3185 $public_fields = array($field_name);
3186 $value = implode(',', $public_fields);
3187 } else {
3188 // For yes values no need to update since its a public field.
3189 // We store only the private fields.
3190 }
3191 }
3192
3193 uwp_update_usermeta($user_id, 'user_privacy', $value);
3194 }
3195 }
3196
3197 // Save tabs privacy settings
3198 $tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs';
3199 $tabs = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$tabs_table_name." WHERE form_type=%s AND user_decided = 1 ORDER BY sort_order ASC", 'profile-tabs'));
3200
3201 if( $tabs ){
3202 $public_fields = maybe_unserialize($user_meta_info->tabs_privacy);
3203 // print_r( $public_fields );exit;
3204 $do_tabs_update = false;
3205 foreach ($tabs as $tab) {
3206 $field_name = $tab->tab_key . '_tab_privacy';
3207
3208 if(isset($_POST[$field_name])){
3209 $do_tabs_update = true;
3210 $field_value = $_POST[$field_name] == '' ? '' : absint($_POST[$field_name]);
3211
3212 if($field_value==='' && isset($public_fields[$field_name])){
3213 unset($public_fields[$field_name]);
3214 }else{
3215 $public_fields[$field_name] = $field_value;
3216 }
3217 }
3218
3219 }
3220
3221 if($do_tabs_update){
3222 if (!empty($user_meta_info)) {
3223 $wpdb->update(
3224 $meta_table,
3225 array('tabs_privacy' => maybe_serialize($public_fields)),
3226 array('user_id' => $user_id),
3227 array('%s'),
3228 array('%d')
3229 );
3230 } else {
3231 $wpdb->insert(
3232 $meta_table,
3233 array('user_id' => $user_id, 'tabs_privacy' => $public_fields)
3234 );
3235 }
3236 }
3237 }
3238
3239 if (isset($_POST['uwp_hide_from_listing']) && 1 == $_POST['uwp_hide_from_listing']) {
3240 update_user_meta($user_id, 'uwp_hide_from_listing', 1);
3241 } else {
3242 update_user_meta($user_id, 'uwp_hide_from_listing', 0);
3243 }
3244
3245 $make_profile_private = uwp_can_make_profile_private();
3246 if ($make_profile_private) {
3247 $field_name = 'uwp_make_profile_private';
3248 if (isset($_POST[$field_name])) {
3249 $value = strip_tags(esc_sql($_POST[$field_name]));
3250 $user_id = get_current_user_id();
3251 update_user_meta($user_id, $field_name, $value);
3252 }
3253 }
3254
3255 }
3256 }
3257
3258 /**
3259 * Get the ajax login form.
3260 *
3261 * @since 1.2.0
3262 */
3263 public function ajax_login_form(){
3264
3265 // add the modal error container
3266 add_action('uwp_template_display_notices', array($this,'modal_error_container'));
3267
3268 // get the form
3269 ob_start();
3270 uwp_locate_template("bootstrap/login");
3271 $form = ob_get_clean();
3272
3273 // send ajax response
3274 wp_send_json_success( $form );
3275 }
3276
3277 /**
3278 * Get the ajax register form.
3279 *
3280 * @since 1.2.0
3281 */
3282 public function ajax_register_form(){
3283
3284 // add the modal error container
3285 add_action('uwp_template_display_notices', array($this,'modal_error_container'));
3286
3287 global $wp_scripts;
3288 if(empty($wp_scripts)){$wp_scripts = wp_scripts();}
3289
3290 // do we need country code script in ajax?
3291 $country_field = false;
3292 $fields = get_register_form_fields();
3293 if (!empty($fields)) {
3294 foreach ($fields as $field) {
3295 if ($field->field_type_key == 'country') {
3296 $country_field = true;
3297 }
3298 }
3299 }
3300
3301 ob_start();
3302
3303 // maybe add country code JS
3304 if( $country_field ){
3305 $country_data = uwp_get_country_data();
3306 echo "<script>var uwp_country_data = ".json_encode( $country_data )."</script>";
3307 echo "<script type='text/javascript' src='".USERSWP_PLUGIN_URL . 'assets/js/countrySelect.min.js'."' ></script>";
3308 }
3309
3310 // get template
3311 uwp_locate_template("bootstrap/register");
3312
3313
3314 // only show the JS if NOT doing a block render
3315 if(isset($_REQUEST['action']) && $_REQUEST['action'] != 'super_duper_output_shortcode'){
3316
3317
3318 // load scripts
3319 $wp_scripts->do_item( 'zxcvbn-async' );
3320 $wp_scripts->do_item( 'password-strength-meter' );
3321 ?>
3322 <script>
3323 // Password strength indicator script
3324 jQuery( document ).ready( function( $ ) {
3325
3326 // Load the settings like WP does.
3327 var first, s;
3328 s = document.createElement('script');
3329 s.src = _zxcvbnSettings.src;
3330 s.type = 'text/javascript';
3331 s.async = true;
3332 first = document.getElementsByTagName('script')[0];
3333 first.parentNode.insertBefore(s, first);
3334
3335 // Enable any pass inputs.
3336 $( 'body' ).on( 'keyup', 'input[name=password], input[name=confirm_password]',
3337 function( event ) {
3338 uwp_checkPasswordStrength(
3339 $('input[name=password]'), // First password field
3340 $('input[name=confirm_password]'), // Second password field
3341 $('#uwp-password-strength'), // Strength meter
3342 $('input[type=submit]'), // Submit button
3343 ['black', 'listed', 'word'] // Blacklisted words
3344 );
3345 }
3346 );
3347 });
3348 </script>
3349 <?php
3350 }
3351 $form = ob_get_clean();
3352
3353 // send ajax response
3354 wp_send_json_success( $form );
3355 }
3356
3357 /**
3358 * Get the ajax forgot password form.
3359 *
3360 * @since 1.2.0
3361 */
3362 public function ajax_forgot_password_form(){
3363
3364 // add the modal error container
3365 add_action('uwp_template_display_notices', array($this,'modal_error_container'));
3366
3367 // get the form
3368 ob_start();
3369 uwp_locate_template("bootstrap/forgot");
3370 $form = ob_get_clean();
3371
3372 // send ajax response
3373 wp_send_json_success( $form );
3374 }
3375
3376 /**
3377 * Output the modal error container.
3378 *
3379 * @param string $type
3380 * @since 1.2.0
3381 */
3382 public function modal_error_container($type = ''){
3383 echo '<div class="form-group"><div class="modal-error"></div></div>';
3384 }
3385
3386 public function get_register_redirect_url($data, $user){
3387 if(is_int($user)){
3388 $user = get_userdata($user);
3389 }
3390
3391 $redirect_page_id = uwp_get_option('register_redirect_to', '');
3392
3393 if (isset($_REQUEST['redirect_to']) && !empty($_REQUEST['redirect_to'])) {
3394 $redirect_to = esc_url($_REQUEST['redirect_to']);
3395 } elseif (isset($data['redirect_to']) && !empty($data['redirect_to'])) {
3396 $redirect_to = esc_url($data['redirect_to']);
3397 } elseif (isset($redirect_page_id) && (int)$redirect_page_id > 0) {
3398 if (uwp_is_wpml()) {
3399 $wpml_page_id = uwp_wpml_object_id($redirect_page_id, 'page', true, ICL_LANGUAGE_CODE);
3400 if (!empty($wpml_page_id)) {
3401 $redirect_page_id = $wpml_page_id;
3402 }
3403 }
3404 $redirect_to = get_permalink($redirect_page_id);
3405 } elseif (isset($redirect_page_id) && (int)$redirect_page_id == -2 && uwp_get_option('register_redirect_custom_url' ) ) {
3406 $redirect_to = uwp_get_option('register_redirect_custom_url' );
3407 } else {
3408 if ( isset($user) && $user->has_cap('manage_options') ) {
3409 $redirect_to = admin_url();
3410 } else {
3411 $redirect_to = home_url('/');
3412 }
3413
3414 $redirect_to = apply_filters( 'registration_redirect', $redirect_to );
3415 }
3416
3417 return apply_filters('uwp_register_redirect', $redirect_to, $redirect_page_id, $data);
3418
3419 }
3420
3421 public function get_login_redirect_url($data, $user){
3422 if(is_int($user)){
3423 $user = get_userdata($user);
3424 }
3425
3426 $redirect_page_id = uwp_get_option('login_redirect_to', -1);
3427
3428 if (isset($_REQUEST['redirect_to']) && !empty($_REQUEST['redirect_to'])) {
3429 $redirect_to = esc_url($_REQUEST['redirect_to']);
3430 } elseif (isset($data['redirect_to']) && !empty($data['redirect_to'])) {
3431 $redirect_to = esc_url($data['redirect_to']);
3432 } elseif (isset($redirect_page_id) && (int)$redirect_page_id > 0) {
3433 if (uwp_is_wpml()) {
3434 $wpml_page_id = uwp_wpml_object_id($redirect_page_id, 'page', true, ICL_LANGUAGE_CODE);
3435 if (!empty($wpml_page_id)) {
3436 $redirect_page_id = $wpml_page_id;
3437 }
3438 }
3439 $redirect_to = get_permalink($redirect_page_id);
3440 } elseif (isset($redirect_page_id) && (int)$redirect_page_id == -2 && uwp_get_option('login_redirect_custom_url' ) ) {
3441 $redirect_to = uwp_get_option('login_redirect_custom_url' );
3442 } else {
3443 if ( isset($user) && $user->has_cap('manage_options') ) {
3444 $redirect_to = admin_url();
3445 } else {
3446 $redirect_to = home_url('/');
3447 }
3448
3449 $redirect_to = apply_filters( 'login_redirect', $redirect_to, '', $user );
3450 }
3451
3452 return apply_filters('uwp_login_redirect', $redirect_to, $redirect_page_id, $data);
3453
3454 }
3455 }