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

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

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