PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.12
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.12
1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 All 174 releases
userswp / includes / class-forms.php

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

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