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

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