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

2,650 lines 100.9 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>: It seems like you are using a system generated password. Please change the password in this page. If this is not a problem for you, you can remove this warning by <a href="%s">clicking here</a>.', 'userswp'), $remove_nag_url);
203 echo '<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. %sResend%s.', 'userswp'), '<a href="'.$resend_link.'"">', '</a>');
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 %shere%s.', 'userswp'), '<a href="'.$login_page_url.'">', '</a>');
440 } else {
441 return sprintf(__('Account registered successfully. Please login %shere%s', 'userswp'), '<a href="'.$login_page_url.'">', '</a>');
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 * Modifies the mail extras based on the notification type.
680 *
681 * @since 1.0.0
682 * @package userswp
683 * @subpackage userswp/includes
684 * @param string $extras Unmodified mail extras.
685 * @param string $type Notification type.
686 * @return string Modified mail extras.
687 */
688 public function init_mail_extras($extras, $type, $user_id) {
689 switch ($type) {
690 case "activate":
691 $extras = $this->generate_activate_message($user_id);
692 break;
693 case "register":
694 $extras = $this->generate_register_message($user_id);
695 break;
696 case "forgot":
697 $extras = $this->generate_forgot_message($user_id);
698 }
699 return $extras;
700 }
701
702 /**
703 * Modifies the admin mail extras based on the notification type.
704 *
705 * @since 1.0.0
706 * @package userswp
707 * @subpackage userswp/includes
708 * @param string $extras Unmodified mail extras.
709 * @param string $type Notification type.
710 * @return string Modified mail extras.
711 */
712 public function init_admin_mail_extras($extras, $type, $user_id) {
713 switch ($type) {
714 case "register_admin":
715 $user_data = get_userdata($user_id);
716 $extras = __('<p><b>' . __('User Information :', 'userswp') . '</b></p>
717 <p>' . __('First Name:', 'userswp') . ' ' . $user_data->first_name . '</p>
718 <p>' . __('Last Name:', 'userswp') . ' ' . $user_data->last_name . '</p>
719 <p>' . __('Username:', 'userswp') . ' ' . $user_data->user_login . '</p>
720 <p>' . __('Email:', 'userswp') . ' ' . $user_data->user_email . '</p>');
721 break;
722 }
723 return $extras;
724 }
725
726 /**
727 * Generates activate email message.
728 *
729 * @since 1.0.0
730 * @package userswp
731 *
732 * @param int $user_id User ID.
733 *
734 * @return bool|string Message.
735 */
736 public function generate_activate_message($user_id) {
737
738 $user_data = get_userdata($user_id);
739 global $wpdb;
740 $key = wp_generate_password( 20, false );
741 do_action( 'uwp_activation_key', $user_data->user_login, $key );
742
743 global $wp_hasher;
744 if ( empty( $wp_hasher ) ) {
745 require_once ABSPATH . 'wp-includes/class-phpass.php';
746 $wp_hasher = new PasswordHash( 8, true );
747 }
748 $hashed = $wp_hasher->HashPassword( $key );
749 $wpdb->update( $wpdb->users, array( 'user_activation_key' => time().":".$hashed ), array( 'user_login' => $user_data->user_login ) );
750 update_user_meta( $user_id, 'uwp_mod', 'email_unconfirmed' );
751 $message = __('To activate your account, visit the following address:', 'userswp') . "\r\n\r\n";
752 $act_url = add_query_arg(
753 array(
754 'uwp_activate' => 'yes',
755 'key' => $key,
756 'login' => $user_data->user_login
757 ),
758 site_url()
759 );
760
761 $message .= "<a href='".$act_url."' target='_blank'>".$act_url."</a>" . "\r\n";
762
763 $activate_message = __('<p><b>' . __('Please activate your account :', 'userswp') . '</b></p>
764 <p>' . $message . '</p>');
765
766 return apply_filters('uwp_activation_mail_message', $activate_message, $user_id);
767
768 }
769
770 /**
771 * Generates register email message.
772 *
773 * @since 1.0.0
774 * @package userswp
775 *
776 * @param int $user_id User ID.
777 *
778 * @return bool|string Message.
779 */
780 public function generate_register_message($user_id) {
781
782 $user_data = get_userdata($user_id);
783 if(isset($this->generated_password) && !empty($this->generated_password)) {
784 if(!uwp_get_option('change_disable_password_nag')) {
785 update_user_meta($user_id, 'default_password_nag', true); //Set up the Password change nag.
786 }
787 $message_pass = $this->generated_password;
788 $this->generated_password = false;
789 } else {
790 $message_pass = __("Password you entered", 'userswp');
791 }
792 $message = __('<p><b>' . __('Your login Information :', 'userswp') . '</b></p>
793 <p>' . __('Username:', 'userswp') . ' ' . $user_data->user_login . '</p>
794 <p>' . __('Password:', 'userswp') . ' ' . $message_pass . '</p>');
795
796 return apply_filters('uwp_register_mail_message', $message, $user_id, $this->generated_password);
797
798 }
799
800 /**
801 * Generates forgot password email message.
802 *
803 * @since 1.0.0
804 * @package userswp
805 *
806 * @param int $user_id User ID.
807 *
808 * @return bool|string Message.
809 */
810 public function generate_forgot_message($user_id) {
811
812 $user_data = get_userdata($user_id);
813 global $wpdb, $wp_hasher;
814
815 $allow = apply_filters('allow_password_reset', true, $user_data->ID);
816 if ( ! $allow )
817 return false;
818 else if ( is_wp_error($allow) )
819 return false;
820
821 $as_password = apply_filters('uwp_forgot_message_as_password', false);
822
823 if ($as_password) {
824 $new_pass = wp_generate_password(12, false);
825 wp_set_password($new_pass, $user_data->ID);
826 if(!uwp_get_option('change_disable_password_nag')) {
827 update_user_meta($user_data->ID, 'default_password_nag', true); //Set up the Password change nag.
828 }
829 $message = '<p><b>' . __('Your login Information :', 'userswp') . '</b></p>';
830 $message .= '<p>' . sprintf(__('Username: %s', 'userswp'), $user_data->user_login) . "</p>";
831 $message .= '<p>' . sprintf(__('Password: %s', 'userswp'), $new_pass) . "</p>";
832
833 } else {
834 $key = wp_generate_password( 20, false );
835 do_action( 'retrieve_password_key', $user_data->user_login, $key );
836
837 if ( empty( $wp_hasher ) ) {
838 require_once ABSPATH . 'wp-includes/class-phpass.php';
839 $wp_hasher = new PasswordHash( 8, true );
840 }
841 $hashed = $wp_hasher->HashPassword( $key );
842 $wpdb->update( $wpdb->users, array( 'user_activation_key' => time().":".$hashed ), array( 'user_login' => $user_data->user_login ) );
843 $message = '<p>' .__('You have requested to reset your password for the following account:', 'userswp') . "</p>";
844 $message .= home_url( '/' ) . "</p>";
845 $message .= '<p>' .sprintf(__('Username: %s', 'userswp'), $user_data->user_login) . "</p>";
846 $message .= '<p>' .__('If this was by mistake, just ignore this email and nothing will happen.', 'userswp') . "</p>";
847 $message .= '<p>' .__('To reset your password, click the following link and follow the instructions.', 'userswp') . "</p>";
848 $message = apply_filters('uwp_forgot_password_message', $message, $user_data);
849 $reset_page = uwp_get_page_id('reset_page', false);
850 if ($reset_page) {
851 $reset_link = add_query_arg( array(
852 'key' => $key,
853 'login' => rawurlencode($user_data->user_login),
854 ), get_permalink($reset_page) );
855 $message .= "<a href='".$reset_link."' target='_blank'>".$reset_link."</a>" . "\r\n";
856 } else {
857 $message .= site_url("reset?key=$key&login=" . rawurlencode($user_data->user_login), 'login') . "\r\n";
858 }
859 }
860
861
862 return $message;
863
864 }
865
866 /**
867 * Processes account form submission.
868 *
869 * @since 1.0.0
870 * @package userswp
871 *
872 * @param array $data Submitted $_POST data
873 * @param array $files Submitted $_FILES data
874 *
875 * @return bool|WP_Error|string
876 */
877 public function process_account($data = array(), $files = array()) {
878
879 $file_obj = new UsersWP_Files();
880
881 $current_user_id = get_current_user_id();
882 if (!$current_user_id) {
883 return false;
884 }
885
886 $errors = new WP_Error();
887
888 if( ! isset( $data['uwp_account_nonce'] ) || ! wp_verify_nonce( $data['uwp_account_nonce'], 'uwp-account-nonce' ) ) {
889 return false;
890 }
891
892 do_action('uwp_before_validate', 'account');
893
894 $result = uwp_validate_fields($data, 'account');
895
896 $result = apply_filters('uwp_validate_result', $result, 'account', $data);
897
898 if (is_wp_error($result)) {
899 return $result;
900 }
901
902 $uploads_result = $file_obj->uwp_validate_uploads($files, 'account');
903
904 if (is_wp_error($uploads_result)) {
905 return $uploads_result;
906 }
907
908 do_action('uwp_after_validate', 'account');
909
910 //unset if value is empty for files
911 foreach ($uploads_result as $upload_file_key => $upload_file_value) {
912 if (empty($upload_file_value)) {
913 unset($uploads_result[$upload_file_key]);
914 }
915 }
916
917 $result = array_merge( $result, $uploads_result );
918
919
920 $args = array(
921 'ID' => $current_user_id
922 );
923
924 if (isset($result['uwp_account_email'])) {
925 $args['user_email'] = $result['uwp_account_email'];
926 }
927
928 if (isset($result['uwp_account_first_name']) && isset($result['uwp_account_last_name'])) {
929 $args['display_name'] = $result['uwp_account_first_name'] . ' ' . $result['uwp_account_last_name'];
930 }
931
932 if (isset($result['uwp_account_first_name'])) {
933 $args['first_name'] = $result['uwp_account_first_name'];
934 }
935
936 if (isset($result['uwp_account_last_name'])) {
937 $args['last_name'] = $result['uwp_account_last_name'];
938 }
939
940 if (isset($result['uwp_account_bio'])) {
941 $args['description'] = $result['uwp_account_bio'];
942 }
943
944 if (isset($result['uwp_account_display_name']) && !empty($result['uwp_account_display_name'])) {
945 $args['display_name'] = $result['uwp_account_display_name'];
946 }
947
948 if (isset($result['password'])) {
949 $args['user_pass'] = $result['password'];
950 }
951
952 $user_id = wp_update_user( $args );
953
954 if (!$user_id) {
955 $errors->add('registerfail', sprintf(__('<strong>Error</strong>: Something went wrong.', 'userswp'), get_option('admin_email')));
956 return $errors;
957 }
958
959 $res = $this->uwp_save_user_extra_fields($user_id, $result, 'account');
960
961 if (!$res) {
962 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp'));
963 }
964
965 $error_code = $errors->get_error_code();
966 if (!empty($error_code)) {
967 return $errors;
968 }
969
970
971 if (uwp_get_option('enable_account_update_notification') == '1') {
972 $user_data = get_user_by('id', $user_id);
973
974 $email = new UsersWP_Mails();
975 $send_result = $email->send( 'account', $user_data->ID );
976
977 $send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors);
978 if (is_wp_error($send_result)) {
979 return $send_result;
980 }
981
982 }
983
984 return true;
985
986 }
987
988 /**
989 * Processes avatar and banner uploads form submission.
990 *
991 * @since 1.0.0
992 * @package userswp
993 *
994 * @param array $data Submitted $_POST data
995 * @param array $files Submitted $_FILES data
996 *
997 * @return bool|WP_Error|string File url to crop.
998 */
999 public function process_upload_submit($data = array(), $files = array(), $type = 'avatar') {
1000
1001 $file_obj = new UsersWP_Files();
1002
1003 $current_user_id = get_current_user_id();
1004 if (!$current_user_id) {
1005 return false;
1006 }
1007
1008 if( ! isset( $data['uwp_upload_nonce'] ) || ! wp_verify_nonce( $data['uwp_upload_nonce'], 'uwp-upload-nonce' ) ) {
1009 return false;
1010 }
1011
1012 do_action('uwp_before_validate', $type);
1013
1014 $result = $file_obj->uwp_validate_uploads($files, $type);
1015
1016 $result = apply_filters('uwp_validate_result', $result, $type, $data);
1017
1018 if (is_wp_error($result)) {
1019 return $result;
1020 }
1021
1022 $profile_url = uwp_build_profile_tab_url($current_user_id);
1023
1024 $url = add_query_arg(
1025 array(
1026 'uwp_crop' => $result['uwp_'.$type.'_file'],
1027 'type' => $type
1028 ),
1029 $profile_url);
1030
1031 return $url;
1032
1033 }
1034
1035 /**
1036 * Processes avatar and banner uploads image crop.
1037 *
1038 * @since 1.0.0
1039 * @since 1.0.12 New param $unlink_prev_img introduced.
1040 * @package userswp
1041 *
1042 * @param array $data Submitted $_POST data
1043 * @param string $type Image type. Default 'avatar'.
1044 * @param bool $unlink_prev_img True to remove previous image. Default false;
1045 *
1046 * @return bool|WP_Error|string Profile url.
1047 */
1048 public function process_image_crop($data = array(), $type = 'avatar', $unlink_prev_img = false) {
1049
1050 if (!is_user_logged_in()) {
1051 return false;
1052 }
1053
1054 // If is current user's profile (profile.php)
1055 if ( is_admin() && defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE ) {
1056 $user_id = get_current_user_id();
1057 // If is another user's profile page
1058 } elseif (is_admin() && ! empty($_GET['user_id']) && is_numeric($_GET['user_id']) ) {
1059 $user_id = $_GET['user_id'];
1060 // Otherwise something is wrong.
1061 } else {
1062 $user_id = get_current_user_id();
1063 }
1064 $image_url = $data['uwp_crop'];
1065
1066 $errors = new WP_Error();
1067 if (empty($image_url)) {
1068 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong. Please contact site admin.', 'userswp'));
1069 }
1070
1071 $error_code = $errors->get_error_code();
1072 if (!empty($error_code)) {
1073 return $errors;
1074 }
1075
1076 if ($image_url) {
1077 if ($type == 'avatar') {
1078 $full_width = apply_filters('uwp_avatar_image_width', 150);
1079 } else {
1080 $full_width = apply_filters('uwp_banner_image_width', uwp_get_option('profile_banner_width', 1000));
1081 }
1082
1083 $image_url = esc_url($image_url);
1084 add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
1085 $uploads = wp_upload_dir();
1086 remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
1087 $upload_url = $uploads['baseurl'];
1088 $upload_path = $uploads['basedir'];
1089 $image_url = str_replace($upload_url, $upload_path, $image_url);
1090 $ext = pathinfo($image_url, PATHINFO_EXTENSION); // to get extension
1091 $name =pathinfo($image_url, PATHINFO_FILENAME); //file name without extension
1092 $thumb_image_name = $name.'_uwp_'.$type.'_thumb'.'.'.$ext;
1093 $thumb_image_location = str_replace($name.'.'.$ext, $thumb_image_name, $image_url);
1094 //Get the new coordinates to crop the image.
1095 $x = $data["x"];
1096 $y = $data["y"];
1097 $w = $data["w"];
1098 $h = $data["h"];
1099 //Scale the image based on cropped width setting
1100 $scale = $full_width/$w;
1101 //$scale = 1; // no scaling
1102 $cropped = uwp_resizeThumbnailImage($thumb_image_location, $image_url,$x, $y, $w, $h,$scale);
1103 $cropped = str_replace($upload_path, $upload_url, $cropped);
1104
1105 // Remove previous avatar/banner
1106 $unlink_img = '';
1107 if ($unlink_prev_img) {
1108 if ($type == 'avatar') {
1109 $previous_img = uwp_get_usermeta($user_id, 'uwp_account_avatar_thumb');
1110 } else if ($type == 'banner') {
1111 $previous_img = uwp_get_usermeta($user_id, 'uwp_account_banner_thumb');
1112 } else {
1113 $previous_img = '';
1114 }
1115
1116 if ($previous_img) {
1117 $unlink_img = untrailingslashit($upload_path) . '/' . ltrim($previous_img, '/');
1118 }
1119 }
1120
1121 // remove the uploads path for easy migrations
1122 $cropped = str_replace($upload_url, '', $cropped);
1123 if ($type == 'avatar') {
1124 uwp_update_usermeta($user_id, 'uwp_account_avatar_thumb', $cropped);
1125 } else {
1126 uwp_update_usermeta($user_id, 'uwp_account_banner_thumb', $cropped);
1127 }
1128
1129 if ($unlink_img && $unlink_img != $thumb_image_location && is_file($unlink_img) && file_exists($unlink_img)) {
1130 @unlink($unlink_img);
1131 $unlink_ori_img = str_replace('_uwp_'.$type.'_thumb'.'.', '.', $unlink_img);
1132 if (is_file($unlink_ori_img) && file_exists($unlink_ori_img)) {
1133 @unlink($unlink_ori_img);
1134 }
1135 }
1136 }
1137
1138 if (is_admin()) {
1139 if ($user_id == get_current_user_id()) {
1140 $profile_url = admin_url( 'profile.php' );
1141 } else {
1142 $profile_url = admin_url( 'user-edit.php?user_id='.$user_id );
1143 }
1144 } else {
1145 $profile_url = uwp_build_profile_tab_url($user_id);
1146 }
1147 return $profile_url;
1148
1149 }
1150
1151 /**
1152 * Saves UsersWP related user custom fields.
1153 *
1154 * @since 1.0.0
1155 * @package userswp
1156 *
1157 * @param int $user_id User ID.
1158 * @param array $data Result array.
1159 * @param string $type Form type.
1160 *
1161 * @return bool True when success. False when failure.
1162 */
1163 public function uwp_save_user_extra_fields($user_id, $data, $type) {
1164
1165 if (empty($user_id) || empty($data) || empty($type)) {
1166 return false;
1167 }
1168
1169 // custom user fields not applicable for login and forgot
1170 if ($type == 'login' || $type == 'forgot') {
1171 return true;
1172 }
1173
1174
1175 if ($type == 'account' || $type == 'register') {
1176 if (isset($data['password'])) {
1177 unset($data['password']);
1178 }
1179 }
1180
1181 if ($type == 'register') {
1182 if (isset($data['uwp_account_username'])) {
1183 unset($data['uwp_account_username']);
1184 }
1185 if (isset($data['uwp_account_email'])) {
1186 unset($data['uwp_account_email']);
1187 }
1188 if (isset($data['uwp_account_display_name'])) {
1189 unset($data['uwp_account_display_name']);
1190 }
1191 if (isset($data['uwp_account_first_name'])) {
1192 unset($data['uwp_account_first_name']);
1193 }
1194 if (isset($data['uwp_account_last_name'])) {
1195 unset($data['uwp_account_last_name']);
1196 }
1197 if (isset($data['uwp_account_bio'])) {
1198 unset($data['uwp_account_bio']);
1199 }
1200 }
1201
1202 if (empty($data)) {
1203 // no extra fields. so just return
1204 return true;
1205 } else {
1206 foreach($data as $key => $value) {
1207 uwp_update_usermeta($user_id, $key, $value);
1208 }
1209 return true;
1210 }
1211 }
1212
1213 /**
1214 * Logs the error message.
1215 *
1216 * @since 1.0.0
1217 * @package userswp
1218 *
1219 * @param array|object|string $log Error message.
1220 *
1221 * @return void
1222 */
1223 public static function uwp_error_log($log){
1224
1225 $should_log = apply_filters( 'uwp_log_errors', WP_DEBUG);
1226 if ( true === $should_log ) {
1227 if ( is_array( $log ) || is_object( $log ) ) {
1228 error_log( print_r( $log, true ) );
1229 } else {
1230 error_log( $log );
1231 }
1232 }
1233 }
1234
1235 /**
1236 *
1237 *
1238 * @since 1.0.0
1239 * @since 1.0.12 Unlink file.
1240 * @package userswp
1241 * @return void
1242 */
1243 public function uwp_upload_file_remove() {
1244
1245 $htmlvar = strip_tags(esc_sql($_POST['htmlvar']));
1246 $user_id = (int) strip_tags(esc_sql($_POST['uid']));
1247 $permission = false;
1248 if ($user_id == get_current_user_id()) {
1249 $permission = true;
1250 } else {
1251 if (current_user_can('manage_options')) {
1252 $permission = true;
1253 }
1254 }
1255 if ($permission) {
1256 // Remove file
1257 if ($htmlvar == "uwp_account_banner_thumb") {
1258 $file = uwp_get_usermeta($user_id, 'uwp_account_banner_thumb');
1259 $type = 'banner';
1260 } elseif ($htmlvar == "uwp_account_avatar_thumb") {
1261 $file = uwp_get_usermeta($user_id, 'uwp_account_avatar_thumb');
1262 $type = 'avatar';
1263 } else {
1264 $file = '';
1265 $type = '';
1266 }
1267
1268 uwp_update_usermeta($user_id, $htmlvar, '');
1269
1270 if ($file) {
1271 $uploads = wp_upload_dir();
1272 $upload_path = $uploads['basedir'];
1273 $unlink_file = untrailingslashit($upload_path) . '/' . ltrim($file, '/');
1274
1275 if (is_file($unlink_file) && file_exists($unlink_file)) {
1276 @unlink($unlink_file);
1277 $unlink_ori_file = str_replace('_uwp_'.$type.'_thumb'.'.', '.', $unlink_file);
1278 if (is_file($unlink_ori_file) && file_exists($unlink_ori_file)) {
1279 @unlink($unlink_ori_file);
1280 }
1281 }
1282 }
1283 }
1284 die();
1285 }
1286
1287
1288 /**
1289 * Form field template for datepicker field type.
1290 *
1291 * @since 1.0.0
1292 * @package userswp
1293 *
1294 * @param string $html Form field html
1295 * @param object $field Field info.
1296 * @param string $value Form field default value.
1297 * @param string $form_type Form type
1298 *
1299 * @return string Modified form field html.
1300 */
1301 public function uwp_form_input_datepicker($html, $field, $value, $form_type){
1302
1303 // Check if there is a field specific filter.
1304 if(has_filter("uwp_form_input_html_datepicker_{$field->htmlvar_name}")){
1305 $html = apply_filters("uwp_form_input_html_datepicker_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1306 }
1307
1308 // If no html then we run the standard output.
1309 if(empty($html)) {
1310
1311 ob_start(); // Start buffering;
1312
1313 $extra_fields = unserialize($field->extra_fields);
1314
1315 if ($extra_fields['date_format'] == '')
1316 $extra_fields['date_format'] = 'yy-mm-dd';
1317
1318 $date_format = $extra_fields['date_format'];
1319 $jquery_date_format = $date_format;
1320
1321 if (!empty($value) && !is_string($value)) {
1322 $value = date('Y-m-d', $value);
1323 }
1324
1325
1326 // check if we need to change the format or not
1327 $date_format_len = strlen(str_replace(' ', '', $date_format));
1328 if($date_format_len>5){// if greater then 5 then it's the old style format.
1329
1330 $search = array('dd','d','DD','mm','m','MM','yy'); //jQuery UI datepicker format
1331 $replace = array('d','j','l','m','n','F','Y');//PHP date format
1332
1333 $date_format = str_replace($search, $replace, $date_format);
1334 }else{
1335 $jquery_date_format = uwp_date_format_php_to_jqueryui( $jquery_date_format );
1336 }
1337 if($value=='0000-00-00'){$value='';}//if date not set, then mark it empty
1338 $value = uwp_date($value, 'Y-m-d', $date_format);
1339 ?>
1340 <script type="text/javascript">
1341
1342 jQuery(function () {
1343
1344 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker({changeMonth: true, changeYear: true
1345 <?php if($field->htmlvar_name == 'uwp_account_dob'){ echo ", yearRange: '1900:+0'"; } else { echo ", yearRange: '1900:2050'"; }?>
1346 <?php echo apply_filters("uwp_datepicker_extra_{$field->htmlvar_name}",'');?>});
1347
1348 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker("option", "dateFormat", '<?php echo $jquery_date_format;?>');
1349
1350 <?php if(!empty($value)){?>
1351 var parsedDate = jQuery.datepicker.parseDate('yy-mm-dd', '<?php echo $value;?>');
1352 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker("setDate", parsedDate);
1353 <?php } ?>
1354
1355 });
1356
1357 </script>
1358 <div id="<?php echo $field->htmlvar_name;?>_row"
1359 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row clearfix uwp_clear uwp-fieldset-details">
1360
1361 <?php
1362 $site_title = uwp_get_form_label($field);
1363 if (!is_admin()) { ?>
1364 <label>
1365 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1366 <?php if ($field->is_required) echo '<span>*</span>';?>
1367 </label>
1368 <?php } ?>
1369
1370 <input name="<?php echo $field->htmlvar_name;?>"
1371 id="<?php echo $field->htmlvar_name;?>"
1372 placeholder="<?php echo $site_title; ?>"
1373 title="<?php echo $site_title; ?>"
1374 type="text"
1375 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
1376 value="<?php echo esc_attr($value);?>" class="uwp_textfield"/>
1377
1378 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1379 <?php if ($field->is_required) { ?>
1380 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1381 <?php } ?>
1382 </div>
1383
1384 <?php
1385 $html = ob_get_clean();
1386 }
1387
1388 return $html;
1389 }
1390
1391 /**
1392 * Form field template for time field type.
1393 *
1394 * @since 1.0.0
1395 * @package userswp
1396 *
1397 * @param string $html Form field html
1398 * @param object $field Field info.
1399 * @param string $value Form field default value.
1400 * @param string $form_type Form type
1401 *
1402 * @return string Modified form field html.
1403 */
1404 public function uwp_form_input_time($html, $field, $value, $form_type){
1405
1406 if(has_filter("uwp_form_input_html_time_{$field->htmlvar_name}")){
1407
1408 $html = apply_filters("uwp_form_input_html_time_{$field->htmlvar_name}",$html, $field, $value, $form_type);
1409 }
1410
1411 // If no html then we run the standard output.
1412 if(empty($html)) {
1413
1414 ob_start(); // Start buffering;
1415
1416 if ($value != '')
1417 $value = date('H:i', strtotime($value));
1418 ?>
1419 <script type="text/javascript">
1420 jQuery(document).ready(function () {
1421
1422 jQuery('#<?php echo $field->htmlvar_name;?>').timepicker({
1423 showPeriod: true,
1424 showLeadingZero: true
1425 });
1426 });
1427 </script>
1428 <div id="<?php echo $field->htmlvar_name;?>_row"
1429 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row clearfix uwp_clear uwp-fieldset-details">
1430
1431 <?php
1432 $site_title = uwp_get_form_label($field);
1433 if (!is_admin()) { ?>
1434 <label>
1435 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1436 <?php if ($field->is_required) echo '<span>*</span>';?>
1437 </label>
1438 <?php } ?>
1439
1440 <input readonly="readonly" name="<?php echo $field->htmlvar_name;?>"
1441 id="<?php echo $field->htmlvar_name;?>"
1442 value="<?php echo esc_attr($value);?>"
1443 placeholder="<?php echo $site_title; ?>"
1444 type="text"
1445 class="uwp_textfield"/>
1446
1447 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1448 <?php if ($field->is_required) { ?>
1449 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1450 <?php } ?>
1451 </div>
1452 <?php
1453 $html = ob_get_clean();
1454 }
1455
1456 return $html;
1457 }
1458
1459 /**
1460 * Form field template for select field type.
1461 *
1462 * @since 1.0.0
1463 * @package userswp
1464 *
1465 * @param string $html Form field html
1466 * @param object $field Field info.
1467 * @param string $value Form field default value.
1468 * @param string $form_type Form type
1469 *
1470 * @return string Modified form field html.
1471 */
1472 public function uwp_form_input_select($html, $field, $value, $form_type){
1473
1474 // Check if there is a field specific filter.
1475 if(has_filter("uwp_form_input_html_select_{$field->htmlvar_name}")){
1476 $html = apply_filters("uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1477 }
1478
1479 // Check if there is a field type specific filter.
1480 if(has_filter("uwp_form_input_html_select_{$field->field_type_key}")){
1481 $html = apply_filters("uwp_form_input_html_select_{$field->field_type_key}", $html, $field, $value, $form_type);
1482 }
1483
1484 // If no html then we run the standard output.
1485 if(empty($html)) {
1486
1487 ob_start(); // Start buffering;
1488
1489 ?>
1490 <div id="<?php echo $field->htmlvar_name;?>_row"
1491 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear">
1492
1493 <?php
1494 $site_title = uwp_get_form_label($field);
1495 if (!is_admin()) { ?>
1496 <label>
1497 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1498 <?php if ($field->is_required) echo '<span>*</span>';?>
1499 </label>
1500 <?php } ?>
1501
1502 <?php
1503 $option_values_arr = uwp_string_values_to_options($field->option_values, true);
1504 $select_options = '';
1505 if (!empty($option_values_arr)) {
1506 foreach ($option_values_arr as $option_row) {
1507 if (isset($option_row['optgroup']) && ($option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end')) {
1508 $option_label = isset($option_row['label']) ? $option_row['label'] : '';
1509
1510 $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
1511 } else {
1512 $option_label = isset($option_row['label']) ? $option_row['label'] : '';
1513 $option_value = isset($option_row['value']) ? $option_row['value'] : '';
1514 $selected = $option_value == $value ? 'selected="selected"' : '';
1515
1516 $select_options .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
1517 }
1518 }
1519 }
1520 ?>
1521 <select name="<?php echo $field->htmlvar_name;?>" id="<?php echo $field->htmlvar_name;?>"
1522 class="uwp_textfield"
1523 title="<?php echo $site_title; ?>"
1524 data-placeholder="<?php echo __('Choose', 'userswp') . ' ' . $site_title . '&hellip;';?>"
1525 ><?php echo $select_options;?>
1526 </select>
1527 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1528 <?php if ($field->is_required) { ?>
1529 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1530 <?php } ?>
1531 </div>
1532
1533 <?php
1534 $html = ob_get_clean();
1535 }
1536
1537 return $html;
1538 }
1539
1540 /**
1541 * Form field template for multiselect field type.
1542 *
1543 * @since 1.0.0
1544 * @package userswp
1545 *
1546 * @param string $html Form field html
1547 * @param object $field Field info.
1548 * @param string $value Form field default value.
1549 * @param string $form_type Form type
1550 *
1551 * @return string Modified form field html.
1552 */
1553 public function uwp_form_input_multiselect($html, $field, $value, $form_type){
1554
1555 // Check if there is a field specific filter.
1556 if(has_filter("uwp_form_input_html_multiselect_{$field->htmlvar_name}")){
1557 $html = apply_filters("uwp_form_input_html_multiselect_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1558 }
1559
1560
1561 if(empty($html)) {
1562
1563 ob_start(); // Start buffering;
1564
1565 $multi_display = 'select';
1566 if (!empty($field->extra_fields)) {
1567 $multi_display = unserialize($field->extra_fields);
1568 }
1569 ?>
1570 <div id="<?php echo $field->htmlvar_name;?>_row"
1571 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear">
1572
1573 <?php
1574 $site_title = uwp_get_form_label($field);
1575 if (!is_admin()) { ?>
1576 <label>
1577 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1578 <?php if ($field->is_required) echo '<span>*</span>';?>
1579 </label>
1580 <?php } ?>
1581
1582 <input type="hidden" name="<?php echo $field->htmlvar_name;?>" value=""/>
1583 <?php if ($multi_display == 'select') { ?>
1584 <div class="uwp_multiselect_list">
1585 <select name="<?php echo $field->htmlvar_name;?>[]"
1586 id="<?php echo $field->htmlvar_name;?>"
1587 title="<?php echo $site_title; ?>"
1588 multiple="multiple" class="uwp_chosen_select"
1589 data-placeholder="<?php echo $site_title; ?>"
1590 >
1591 <?php
1592 } else {
1593 ?>
1594 <ul class="uwp_multi_choice">
1595 <?php
1596 }
1597
1598 $option_values_arr = uwp_string_values_to_options($field->option_values, true);
1599 $select_options = '';
1600 if (!empty($option_values_arr)) {
1601 foreach ($option_values_arr as $option_row) {
1602 if (isset($option_row['optgroup']) && ($option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end')) {
1603 $option_label = isset($option_row['label']) ? $option_row['label'] : '';
1604
1605 if ($multi_display == 'select') {
1606 $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
1607 } else {
1608 $select_options .= $option_row['optgroup'] == 'start' ? '<li>' . $option_label . '</li>' : '';
1609 }
1610 } else {
1611 $option_label = isset($option_row['label']) ? $option_row['label'] : '';
1612 $option_value = isset($option_row['value']) ? $option_row['value'] : '';
1613 $selected = $option_value == $value ? 'selected="selected"' : '';
1614 $checked = '';
1615
1616 if ((!is_array($value) && trim($value) != '') || (is_array($value) && !empty($value))) {
1617 if (!is_array($value)) {
1618 $value_array = explode(',', $value);
1619 } else {
1620 $value_array = $value;
1621 }
1622
1623 if (is_array($value_array)) {
1624 if (in_array($option_value, $value_array)) {
1625 $selected = 'selected="selected"';
1626 $checked = 'checked="checked"';
1627 }
1628 }
1629 }
1630
1631 if ($multi_display == 'select') {
1632 $select_options .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
1633 } else {
1634 $select_options .= '<li><input name="' . $field->name . '[]" ' . $checked . ' value="' . esc_attr($option_value) . '" class="uwp-' . $multi_display . '" type="' . $multi_display . '" />&nbsp;' . $option_label . ' </li>';
1635 }
1636 }
1637 }
1638 }
1639 echo $select_options;
1640
1641 if ($multi_display == 'select') { ?></select></div>
1642 <?php } else { ?>
1643 </ul>
1644 <?php } ?>
1645 <?php if ($field->is_required) { ?>
1646 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1647 <?php } ?>
1648 </div>
1649 <?php
1650 $html = ob_get_clean();
1651 }
1652
1653 return $html;
1654 }
1655
1656 /**
1657 * Form field template for file field type.
1658 *
1659 * @since 1.0.0
1660 * @package userswp
1661 *
1662 * @param string $html Form field html
1663 * @param object $field Field info.
1664 * @param string $value Form field default value.
1665 * @param string $form_type Form type
1666 *
1667 * @return string Modified form field html.
1668 */
1669 public function uwp_form_input_file($html, $field, $value, $form_type){
1670
1671 $file_obj = new UsersWP_Files();
1672
1673 // Check if there is a field specific filter.
1674 if(has_filter("uwp_form_input_html_file_{$field->htmlvar_name}")){
1675 $html = apply_filters("uwp_form_input_html_file_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1676 }
1677
1678 // If no html then we run the standard output.
1679 if(empty($html)) {
1680
1681 ob_start(); // Start buffering;
1682
1683 ?>
1684 <div id="<?php echo $field->htmlvar_name;?>_row"
1685 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
1686
1687 <?php
1688 $site_title = uwp_get_form_label($field);
1689 if (!is_admin()) { ?>
1690 <label>
1691 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1692 <?php if ($field->is_required) echo '<span>*</span>';?>
1693 </label>
1694 <?php } ?>
1695
1696 <?php echo $file_obj->uwp_file_upload_preview($field, $value); ?>
1697 <input name="<?php echo $field->htmlvar_name; ?>"
1698 class="<?php echo $field->css_class; ?>"
1699 placeholder="<?php echo $site_title; ?>"
1700 title="<?php echo $site_title; ?>"
1701 <?php
1702 if ($field->is_required == 1 ) { echo 'data-is-required="1"'; }
1703 if ($field->is_required == 1 && !$value) { echo 'required="required"'; }
1704 ?>
1705 type="<?php echo $field->field_type; ?>">
1706 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1707 <?php if ($field->is_required) { ?>
1708 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1709 <?php } ?>
1710 </div>
1711
1712 <?php
1713 $html = ob_get_clean();
1714 }
1715
1716 return $html;
1717 }
1718
1719 /**
1720 * Form field template for checkbox field type.
1721 *
1722 * @since 1.0.0
1723 * @package userswp
1724 *
1725 * @param string $html Form field html
1726 * @param object $field Field info.
1727 * @param string $value Form field default value.
1728 * @param string $form_type Form type
1729 *
1730 * @return string Modified form field html.
1731 */
1732 public function uwp_form_input_checkbox($html, $field, $value, $form_type){
1733
1734 // Check if there is a field specific filter.
1735 if(has_filter("uwp_form_input_html_checkbox_{$field->htmlvar_name}")){
1736 $html = apply_filters("uwp_form_input_html_checkbox_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1737 }
1738
1739 // If no html then we run the standard output.
1740 if(empty($html)) {
1741
1742 ob_start(); // Start buffering;
1743 $site_title = uwp_get_form_label($field);
1744 ?>
1745 <div id="<?php echo $field->htmlvar_name;?>_row"
1746 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
1747 <input type="hidden" name="<?php echo $field->htmlvar_name; ?>" value="0" />
1748 <input name="<?php echo $field->htmlvar_name; ?>"
1749 class="<?php echo $field->css_class; ?>"
1750 placeholder="<?php echo $site_title; ?>"
1751 title="<?php echo $site_title; ?>"
1752 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
1753 <?php if ($value == '1') { echo 'checked="checked"'; } ?>
1754 type="<?php echo $field->field_type; ?>"
1755 value="1">
1756 <?php
1757 echo (trim($site_title)) ? $site_title : '&nbsp;';
1758 ?>
1759 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1760 <?php if ($field->is_required) { ?>
1761 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1762 <?php } ?>
1763 </div>
1764
1765 <?php
1766 $html = ob_get_clean();
1767 }
1768
1769 return $html;
1770 }
1771
1772 /**
1773 * Form field template for radio field type.
1774 *
1775 * @since 1.0.0
1776 * @package userswp
1777 *
1778 * @param string $html Form field html
1779 * @param object $field Field info.
1780 * @param string $value Form field default value.
1781 * @param string $form_type Form type
1782 *
1783 * @return string Modified form field html.
1784 */
1785 public function uwp_form_input_radio($html, $field, $value, $form_type){
1786
1787 // Check if there is a field specific filter.
1788 if(has_filter("uwp_form_input_html_radio_{$field->htmlvar_name}")){
1789 $html = apply_filters("uwp_form_input_html_radio_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1790 }
1791
1792 // If no html then we run the standard output.
1793 if(empty($html)) {
1794
1795 ob_start(); // Start buffering;
1796
1797 ?>
1798 <div id="<?php echo $field->htmlvar_name;?>_row"
1799 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
1800
1801 <?php
1802 $site_title = uwp_get_form_label($field);
1803 if (!is_admin()) { ?>
1804 <label>
1805 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1806 <?php if ($field->is_required) echo '<span>*</span>';?>
1807 </label>
1808 <?php } ?>
1809
1810
1811 <?php if ($field->option_values) {
1812 $option_values = uwp_string_values_to_options($field->option_values, true);
1813
1814 if (!empty($option_values)) {
1815 $count = 0;
1816 foreach ($option_values as $option_value) {
1817 if (empty($option_value['optgroup'])) {
1818 $count++;
1819 if ($count == 1) {
1820 $class = "uwp-radio-first";
1821 } else {
1822 $class = "";
1823 }
1824 ?>
1825 <span class="uwp-radios <?php echo $class; ?>">
1826 <input name="<?php echo $field->htmlvar_name; ?>"
1827 id="<?php echo $field->htmlvar_name; ?>"
1828 title="<?php echo esc_attr($option_value['label']); ?>"
1829 <?php checked($value, $option_value['value']);?>
1830 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
1831 value="<?php echo esc_attr($option_value['value']); ?>"
1832 class="uwp-radio" type="radio" />
1833 <?php echo $option_value['label']; ?>
1834 </span>
1835 <?php
1836 }
1837 }
1838 }
1839 }
1840 ?>
1841 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1842 <?php if ($field->is_required) { ?>
1843 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1844 <?php } ?>
1845 </div>
1846 <?php
1847 $html = ob_get_clean();
1848 }
1849
1850 return $html;
1851 }
1852
1853 /**
1854 * Form field template for text field type.
1855 *
1856 * @since 1.0.0
1857 * @package userswp
1858 *
1859 * @param string $html Form field html
1860 * @param object $field Field info.
1861 * @param string $value Form field default value.
1862 * @param string $form_type Form type
1863 *
1864 * @return string Modified form field html.
1865 */
1866 public function uwp_form_input_text($html, $field, $value, $form_type){
1867
1868 // Check if there is a custom field specific filter.
1869 if(has_filter("uwp_form_input_text_{$field->htmlvar_name}")){
1870 $html = apply_filters("uwp_form_input_text_{$field->htmlvar_name}",$html, $field, $value, $form_type);
1871 }
1872
1873 // If no html then we run the standard output.
1874 if(empty($html)) {
1875
1876 ob_start(); // Start buffering;
1877
1878 $type = 'text';
1879 $step = false;
1880 //number and float validation $validation_pattern
1881 if(isset($field->data_type) && $field->data_type == 'INT'){
1882 $type = 'number';
1883 } elseif(isset($field->data_type) && $field->data_type == 'FLOAT'){
1884 $dp = $field->decimal_point;
1885 switch ($dp) {
1886 case "1":
1887 $step = "0.1";
1888 break;
1889 case "2":
1890 $step = "0.01";
1891 break;
1892 case "3":
1893 $step = "0.001";
1894 break;
1895 case "4":
1896 $step = "0.0001";
1897 break;
1898 case "5":
1899 $step = "0.00001";
1900 break;
1901 case "6":
1902 $step = "0.000001";
1903 break;
1904 case "7":
1905 $step = "0.0000001";
1906 break;
1907 case "8":
1908 $step = "0.00000001";
1909 break;
1910 case "9":
1911 $step = "0.000000001";
1912 break;
1913 case "10":
1914 $step = "0.0000000001";
1915 break;
1916 default:
1917 $step = "0.01";
1918 break;
1919 }
1920 $type = 'number';
1921 }
1922
1923 ?>
1924
1925 <div id="<?php echo $field->htmlvar_name;?>_row"
1926 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
1927
1928 <?php
1929 $site_title = uwp_get_form_label($field);
1930 $manual_label = apply_filters('uwp_login_username_label_manual', true);
1931 if ($manual_label
1932 && isset($field->form_type)
1933 && $field->form_type == 'login'
1934 && $field->htmlvar_name == 'uwp_login_username') {
1935 $site_title = __("Username or Email", 'userswp');
1936 }
1937 if (!is_admin()) { ?>
1938 <label>
1939 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
1940 <?php if ($field->is_required) echo '<span>*</span>';?>
1941 </label>
1942 <?php } ?>
1943
1944 <input name="<?php echo $field->htmlvar_name;?>"
1945 class="<?php echo $field->css_class; ?> uwp_textfield"
1946 id="<?php echo $field->htmlvar_name;?>"
1947 placeholder="<?php echo $site_title; ?>"
1948 value="<?php echo esc_attr(stripslashes($value));?>"
1949 title="<?php echo $site_title; ?>"
1950 oninvalid="this.setCustomValidity('<?php _e($field->required_msg, 'userswp'); ?>')"
1951 oninput="setCustomValidity('')"
1952 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
1953 <?php if ($field->for_admin_use == 1) { echo 'readonly="readonly"'; } ?>
1954 type="<?php echo $type; ?>"
1955 <?php if ($step) { echo 'step="'.$step.'"'; } ?>
1956 />
1957 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
1958 <?php if ($field->is_required) { ?>
1959 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
1960 <?php } ?>
1961 </div>
1962
1963
1964 <?php
1965 $html = ob_get_clean();
1966 }
1967
1968 return $html;
1969 }
1970
1971 /**
1972 * Form field template for textarea field type.
1973 *
1974 * @since 1.0.0
1975 * @package userswp
1976 *
1977 * @param string $html Form field html
1978 * @param object $field Field info.
1979 * @param string $value Form field default value.
1980 * @param string $form_type Form type
1981 *
1982 * @return string Modified form field html.
1983 */
1984 public function uwp_form_input_textarea($html, $field, $value, $form_type){
1985
1986 // Check if there is a field specific filter.
1987 if(has_filter("uwp_form_input_textarea_{$field->htmlvar_name}")){
1988 $html = apply_filters("uwp_form_input_textarea_{$field->htmlvar_name}", $html, $field, $value, $form_type);
1989 }
1990
1991 // If no html then we run the standard output.
1992 if(empty($html)) {
1993
1994 ob_start(); // Start buffering;
1995
1996 ?>
1997 <div id="<?php echo $field->htmlvar_name;?>_row"
1998 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
1999
2000 <?php
2001 $site_title = uwp_get_form_label($field);
2002 if (!is_admin()) { ?>
2003 <label>
2004 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2005 <?php if ($field->is_required) echo '<span>*</span>';?>
2006 </label>
2007 <?php } ?>
2008
2009 <textarea name="<?php echo $field->htmlvar_name; ?>"
2010 class="<?php echo $field->css_class; ?>"
2011 placeholder="<?php echo $site_title; ?>"
2012 title="<?php echo $site_title; ?>"
2013 oninvalid="this.setCustomValidity('<?php _e($field->required_msg, 'userswp'); ?>')"
2014 oninput="setCustomValidity('')"
2015 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2016 type="<?php echo $field->field_type; ?>"
2017 rows="4"><?php echo stripslashes($value); ?></textarea>
2018 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2019 <?php if ($field->is_required) { ?>
2020 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2021 <?php } ?>
2022 </div>
2023
2024 <?php
2025 $html = ob_get_clean();
2026 }
2027
2028 return $html;
2029 }
2030
2031 /**
2032 * Form field template for fieldset field type.
2033 *
2034 * @since 1.0.0
2035 * @package userswp
2036 *
2037 * @param string $html Form field html
2038 * @param object $field Field info.
2039 * @param string $value Form field default value.
2040 * @param string $form_type Form type
2041 *
2042 * @return string Modified form field html.
2043 */
2044 public function uwp_form_input_fieldset($html, $field, $value, $form_type) {
2045 // Check if there is a custom field specific filter.
2046 if(has_filter("uwp_form_input_fieldset_{$field->htmlvar_name}")){
2047 $html = apply_filters("uwp_form_input_fieldset_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2048 }
2049
2050 // If no html then we run the standard output.
2051 if(empty($html)) {
2052
2053 ob_start(); // Start buffering;
2054 ?>
2055 <h3 class="uwp_input_fieldset <?php echo $field->css_class; ?>">
2056 <?php echo $field->site_title;; ?>
2057 <?php if ( $field->help_text != '' ) {
2058 echo '<small>( ' . $field->help_text . ' )</small>';
2059 } ?></h3>
2060 <?php
2061 $html = ob_get_clean();
2062 }
2063
2064 return $html;
2065 }
2066
2067 /**
2068 * Form field template for url field type.
2069 *
2070 * @since 1.0.0
2071 * @package userswp
2072 *
2073 * @param string $html Form field html
2074 * @param object $field Field info.
2075 * @param string $value Form field default value.
2076 * @param string $form_type Form type
2077 *
2078 * @return string Modified form field html.
2079 */
2080 public function uwp_form_input_url($html, $field, $value, $form_type){
2081
2082
2083 // Check if there is a custom field specific filter.
2084 if(has_filter("uwp_form_input_url_{$field->htmlvar_name}")){
2085 $html = apply_filters("uwp_form_input_url_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2086 }
2087
2088 // If no html then we run the standard output.
2089 if(empty($html)) {
2090
2091 ob_start(); // Start buffering;
2092 ?>
2093 <div id="<?php echo $field->htmlvar_name;?>_row"
2094 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
2095
2096 <?php
2097 $site_title = uwp_get_form_label($field);
2098 if (!is_admin()) { ?>
2099 <label>
2100 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2101 <?php if ($field->is_required) echo '<span>*</span>';?>
2102 </label>
2103 <?php } ?>
2104
2105 <input name="<?php echo $field->htmlvar_name;?>"
2106 class="<?php echo $field->css_class; ?> uwp_textfield"
2107 id="<?php echo $field->htmlvar_name;?>"
2108 placeholder="<?php echo $site_title; ?>"
2109 value="<?php echo esc_attr(stripslashes($value));?>"
2110 title="<?php echo $site_title; ?>"
2111 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2112 type="url"
2113 oninvalid="setCustomValidity('<?php _e('Please enter a valid URL including http://', 'userswp'); ?>')"
2114 onchange="try{setCustomValidity('')}catch(e){}"
2115 />
2116 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2117 <?php if ($field->is_required) { ?>
2118 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2119 <?php } ?>
2120 </div>
2121
2122 <?php
2123 $html = ob_get_clean();
2124 }
2125
2126 return $html;
2127 }
2128
2129 /**
2130 * Form field template for email field type.
2131 *
2132 * @since 1.0.0
2133 * @package userswp
2134 *
2135 * @param string $html Form field html
2136 * @param object $field Field info.
2137 * @param string $value Form field default value.
2138 * @param string $form_type Form type
2139 *
2140 * @return string Modified form field html.
2141 */
2142 public function uwp_form_input_email($html, $field, $value, $form_type){
2143
2144
2145 // Check if there is a custom field specific filter.
2146 if(has_filter("uwp_form_input_email_{$field->htmlvar_name}")){
2147 $html = apply_filters("uwp_form_input_email_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2148 }
2149
2150 // If no html then we run the standard output.
2151 if(empty($html)) {
2152
2153 ob_start(); // Start buffering;
2154 ?>
2155 <div id="<?php echo $field->htmlvar_name;?>_row"
2156 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
2157
2158 <?php
2159 $site_title = uwp_get_form_label($field);
2160 if (!is_admin()) { ?>
2161 <label>
2162 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2163 <?php if ($field->is_required) echo '<span>*</span>';?>
2164 </label>
2165 <?php } ?>
2166
2167 <input name="<?php echo $field->htmlvar_name;?>"
2168 class="<?php echo $field->css_class; ?> uwp_textfield"
2169 id="<?php echo $field->htmlvar_name;?>"
2170 placeholder="<?php echo $site_title; ?>"
2171 value="<?php echo esc_attr(stripslashes($value));?>"
2172 title="<?php echo $site_title; ?>"
2173 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2174 type="email"
2175 />
2176 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2177 <?php if ($field->is_required) { ?>
2178 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2179 <?php } ?>
2180 </div>
2181
2182
2183 <?php
2184 $html = ob_get_clean();
2185 }
2186
2187 if(has_filter("uwp_form_input_email_{$field->htmlvar_name}_after")){
2188 $html = apply_filters("uwp_form_input_email_{$field->htmlvar_name}_after",$html, $field, $value, $form_type);
2189 }
2190
2191 return $html;
2192 }
2193
2194 /**
2195 * Form field template for password field type.
2196 *
2197 * @since 1.0.0
2198 * @package userswp
2199 *
2200 * @param string $html Form field html
2201 * @param object $field Field info.
2202 * @param string $value Form field default value.
2203 * @param string $form_type Form type
2204 *
2205 * @return string Modified form field html.
2206 */
2207 public function uwp_form_input_password($html, $field, $value, $form_type){
2208
2209
2210 // Check if there is a custom field specific filter.
2211 if(has_filter("uwp_form_input_password_{$field->htmlvar_name}")){
2212 $html = apply_filters("uwp_form_input_password_{$field->htmlvar_name}",$html, $field, $value, $form_type);
2213 }
2214
2215 // If no html then we run the standard output.
2216 if(empty($html)) {
2217
2218 ob_start(); // Start buffering;
2219 ?>
2220 <div id="<?php echo $field->htmlvar_name;?>_row"
2221 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear">
2222
2223 <?php
2224 $site_title = uwp_get_form_label($field);
2225 if (!is_admin()) { ?>
2226 <label>
2227 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2228 <?php if ($field->is_required) echo '<span>*</span>';?>
2229 </label>
2230 <?php } ?>
2231
2232 <input name="<?php echo $field->htmlvar_name;?>"
2233 class="<?php echo $field->css_class; ?> uwp_textfield"
2234 id="<?php echo $field->htmlvar_name;?>"
2235 placeholder="<?php echo $site_title; ?>"
2236 value="<?php echo esc_attr(stripslashes($value));?>"
2237 title="<?php echo $site_title; ?>"
2238 <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
2239 type="password"
2240 />
2241 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2242 <?php if ($field->is_required) { ?>
2243 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2244 <?php } ?>
2245 </div>
2246
2247
2248 <?php
2249 $html = ob_get_clean();
2250 }
2251
2252 if(has_filter("uwp_form_input_password_{$field->htmlvar_name}_after")){
2253 $html = apply_filters("uwp_form_input_password_{$field->htmlvar_name}_after",$html, $field, $value, $form_type);
2254 }
2255
2256 return $html;
2257 }
2258
2259
2260
2261 /**
2262 * Adds enctype tag in form for file fields.
2263 *
2264 * @since 1.0.0
2265 * @package userswp
2266 *
2267 * @return void
2268 */
2269 function add_multipart_to_admin_edit_form() {
2270 global $wpdb;
2271 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2272 $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");
2273 if ($fields) {
2274 echo 'enctype="multipart/form-data"';
2275 }
2276 }
2277
2278 /**
2279 * Handles UsersWP custom field requests from admin.
2280 *
2281 * @since 1.0.0
2282 * @package userswp
2283 *
2284 * @param int $user_id User ID.
2285 *
2286 * @return void
2287 */
2288 public function update_profile_extra_admin_edit($user_id) {
2289 global $wpdb;
2290 $file_obj = new UsersWP_Files();
2291 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2292 //Normal fields
2293 $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");
2294 if ($fields) {
2295 $_POST['uwp_account_first_name'] = $_POST['first_name'];
2296 $_POST['uwp_account_last_name'] = $_POST['last_name'];
2297 $_POST['uwp_account_display_name'] = $_POST['nickname'];
2298 $_POST['uwp_account_email'] = $_POST['email'];
2299 $_POST['uwp_account_bio'] = $_POST['description'];
2300 $result = uwp_validate_fields($_POST, 'account', $fields);
2301 if (isset($result['uwp_account_display_name']) && !empty($result['uwp_account_display_name'])) {
2302 $display_name = $result['uwp_account_display_name'];
2303 } else {
2304 if (!empty($first_name) || !empty($last_name)) {
2305 $display_name = $result['uwp_account_first_name'] . ' ' . $result['uwp_account_last_name'];
2306 } else {
2307 $user_info = get_userdata($user_id);
2308 $display_name = $user_info->user_login;
2309 }
2310 }
2311 $result['uwp_account_display_name'] = $display_name;
2312 if (!is_wp_error($result)) {
2313 foreach ($fields as $field) {
2314 $value = isset($result[$field->htmlvar_name]) ? $result[$field->htmlvar_name] : '';
2315 if ($value == '0' || !empty($value)) {
2316 uwp_update_usermeta($user_id, $field->htmlvar_name, $value);
2317 }
2318 }
2319 }
2320 }
2321
2322 //File fields
2323 $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");
2324 if ($fields) {
2325 $result = $file_obj->uwp_validate_uploads($_FILES, 'account', true, $fields);
2326 if (!is_wp_error($result)) {
2327 foreach ($fields as $field) {
2328 $value = $result[$field->htmlvar_name];
2329 if ($value == '0' || !empty($value)) {
2330 uwp_update_usermeta($user_id, $field->htmlvar_name, $value);
2331 }
2332 }
2333 }
2334 }
2335 }
2336
2337
2338 /**
2339 * Adds search form keyword input html.
2340 *
2341 * @since 1.0.0
2342 * @package userswp
2343 *
2344 * @param string $keyword Search keyword.
2345 *
2346 * @return void
2347 */
2348 public function uwp_users_search_form_text_field($keyword) {
2349 ?>
2350 <input placeholder="Search For" name="uwps" value="<?php echo $keyword; ?>" class="s search-input" type="text">
2351 <?php
2352 }
2353
2354 /**
2355 * Adds search form submit button html.
2356 *
2357 * @since 1.0.0
2358 * @package userswp
2359 *
2360 * @return void
2361 */
2362 public function uwp_users_search_form_submit() {
2363 ?>
2364 <input class="uwp-searchsubmit uwp-search-submit" value="Search" type="submit">
2365 <?php
2366 }
2367
2368 /**
2369 * Checks for errors in mail submission.
2370 *
2371 * @since 1.0.0
2372 * @package userswp
2373 *
2374 * @param array $res Result array.
2375 * @param object $user_data User object.
2376 * @param WP_Error $errors Error object
2377 *
2378 * @return WP_Error|array Error object when error. Result array when success.
2379 */
2380 public function uwp_forms_check_for_send_mail_errors($res, $user_data, $errors) {
2381 if (!$res) {
2382 if (get_option('admin_email') == $user_data->user_email) {
2383 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong when sending email. Please check your site error log for more details.', 'userswp'));
2384 } else {
2385 $errors->add('something_wrong', __('<strong>Error</strong>: Something went wrong when sending email. Please contact site admin.', 'userswp'));
2386 }
2387 }
2388
2389 $error_code = $errors->get_error_code();
2390 if (!empty($error_code)) {
2391 return $errors;
2392 } else {
2393 return $res;
2394 }
2395
2396 }
2397
2398 /**
2399 * Form field template for country field.
2400 *
2401 * @since 1.0.0
2402 * @package userswp
2403 *
2404 * @param string $html Form field html
2405 * @param object $field Field info.
2406 * @param string $value Form field default value.
2407 * @param string $form_type Form type
2408 *
2409 * @return string Modified form field html.
2410 */
2411 public function uwp_form_input_select_country($html, $field, $value, $form_type){
2412
2413 // Check if there is a field specific filter.
2414 if(has_filter("uwp_form_input_html_select_{$field->htmlvar_name}")){
2415 $html = apply_filters("uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type);
2416 }
2417
2418 //print_r($field);
2419
2420 // If no html then we run the standard output.
2421 if(empty($html)) {
2422
2423 ob_start(); // Start buffering;
2424
2425 ?>
2426 <div id="<?php echo $field->htmlvar_name;?>_row"
2427 class="<?php if ($field->is_required) echo 'required_field';?> uwp_form_row uwp_clear">
2428
2429 <?php
2430 $site_title = uwp_get_form_label($field);
2431 if (!is_admin()) { ?>
2432 <label>
2433 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2434 <?php if ($field->is_required) echo '<span>*</span>';?>
2435 </label>
2436 <?php } ?>
2437
2438 <?php
2439 // if value empty set the default
2440 if($value=='' && isset($field->default_value) && $field->default_value){
2441 $value = $field->default_value;
2442 }
2443 $select_country_options = apply_filters('uwp_form_input_select_country',"{defaultCountry: '$value'}",$field, $value, $form_type);
2444 ?>
2445
2446 <input type="text" class="uwp_textfield" title="<?php echo $site_title; ?>" id="<?php echo $field->htmlvar_name;?>" />
2447 <input type="hidden" id="<?php echo $field->htmlvar_name;?>_code" name="<?php echo $field->htmlvar_name;?>" />
2448
2449 <script>
2450 jQuery("#<?php echo $field->htmlvar_name;?>").countrySelect(<?php echo $select_country_options;?>);
2451 </script>
2452
2453
2454 <span class="uwp_message_note"><?php _e($field->help_text, 'userswp');?></span>
2455 <?php if ($field->is_required) { ?>
2456 <span class="uwp_message_error"><?php _e($field->required_msg, 'userswp'); ?></span>
2457 <?php } ?>
2458 </div>
2459
2460 <?php
2461 $html = ob_get_clean();
2462 }
2463
2464 return $html;
2465 }
2466
2467 /**
2468 * Prints the username link in "Edit Account" page
2469 *
2470 * @since 1.0.0
2471 * @package userswp
2472 *
2473 * @param string $type Page type.
2474 *
2475 * @return void
2476 */
2477 public function uwp_display_username_in_account($type) {
2478 if ($type == 'account') {
2479 $user_id = get_current_user_id();
2480 $user_info = get_userdata($user_id);
2481 $display_name = $user_info->user_login;
2482 ?>
2483 <span class="uwp_account_page_username">
2484 <a href="<?php echo uwp_build_profile_tab_url($user_id); ?>">( @<?php echo $display_name; ?> )</a>
2485 </span>
2486 <?php
2487 }
2488 }
2489
2490
2491 /**
2492 * Adds confirm password field in forms.
2493 *
2494 * @since 1.0.0
2495 * @package userswp
2496 *
2497 * @param string $html Form field html
2498 * @param object $field Field info.
2499 * @param string $value Form field default value.
2500 * @param string $form_type Form type
2501 *
2502 * @return string Modified form field html.
2503 */
2504 public function uwp_register_confirm_password_field($html, $field, $value, $form_type) {
2505 if ($form_type == 'register') {
2506 //confirm password field
2507 $extra = array();
2508 if (isset($field->extra_fields) && $field->extra_fields != '') {
2509 $extra = unserialize($field->extra_fields);
2510 }
2511 $enable_confirm_password_field = isset($extra['confirm_password']) ? $extra['confirm_password'] : '0';
2512 if ($enable_confirm_password_field == '1') {
2513 ob_start(); // Start buffering;
2514 ?>
2515 <div id="uwp_account_confirm_password_row"
2516 class="<?php echo 'required_field';?> uwp_form_password_row uwp_clear">
2517
2518 <?php
2519 $site_title = __("Confirm Password", 'userswp');
2520 if (!is_admin()) { ?>
2521 <label>
2522 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2523 <?php echo '<span>*</span>'; ?>
2524 </label>
2525 <?php } ?>
2526
2527 <input name="uwp_account_confirm_password"
2528 class="uwp_textfield"
2529 id="uwp_account_confirm_password"
2530 placeholder="<?php echo $site_title; ?>"
2531 value=""
2532 title="<?php echo $site_title; ?>"
2533 <?php echo 'required="required"'; ?>
2534 type="password"
2535 />
2536 </div>
2537
2538 <?php
2539 $confirm_html = ob_get_clean();
2540 $html = $html.$confirm_html;
2541 }
2542 }
2543 return $html;
2544 }
2545
2546 /**
2547 * Adds confirm email field in forms.
2548 *
2549 * @since 1.0.0
2550 * @package userswp
2551 *
2552 * @param string $html Form field html
2553 * @param object $field Field info.
2554 * @param string $value Form field default value.
2555 * @param string $form_type Form type
2556 *
2557 * @return string Modified form field html.
2558 */
2559 public function uwp_register_confirm_email_field($html, $field, $value, $form_type) {
2560 if ($form_type == 'register') {
2561 //confirm email field
2562 $extra = array();
2563 if (isset($field->extra_fields) && $field->extra_fields != '') {
2564 $extra = unserialize($field->extra_fields);
2565 }
2566 $enable_confirm_email_field = isset($extra['confirm_email']) ? $extra['confirm_email'] : '0';
2567 if ($enable_confirm_email_field == '1') {
2568 ob_start(); // Start buffering;
2569 ?>
2570 <div id="uwp_account_confirm_email_row"
2571 class="<?php echo 'required_field';?> uwp_form_email_row uwp_clear">
2572
2573 <?php
2574 $site_title = __("Confirm Email", 'userswp');
2575 if (!is_admin()) { ?>
2576 <label>
2577 <?php echo (trim($site_title)) ? $site_title : '&nbsp;'; ?>
2578 <?php echo '<span>*</span>'; ?>
2579 </label>
2580 <?php } ?>
2581
2582 <input name="uwp_account_confirm_email"
2583 class="uwp_textfield"
2584 id="uwp_account_confirm_email"
2585 placeholder="<?php echo $site_title; ?>"
2586 value=""
2587 title="<?php echo $site_title; ?>"
2588 <?php echo 'required="required"'; ?>
2589 type="email"
2590 />
2591 </div>
2592
2593 <?php
2594 $confirm_html = ob_get_clean();
2595 $html = $html.$confirm_html;
2596 }
2597 }
2598 return $html;
2599 }
2600
2601
2602 /**
2603 * Handles the privacy form submission.
2604 *
2605 * @since 1.0.0
2606 * @package userswp
2607 *
2608 * @return void
2609 */
2610 public function uwp_privacy_submit_handler() {
2611 if (isset($_POST['uwp_privacy_submit'])) {
2612 if( ! isset( $_POST['uwp_privacy_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_privacy_nonce'], 'uwp-privacy-nonce' ) ) {
2613 return;
2614 }
2615
2616 $extra_where = "AND is_public='2'";
2617 $fields = get_account_form_fields($extra_where);
2618 $fields = apply_filters('uwp_account_privacy_fields', $fields);
2619 if ($fields) {
2620 foreach ($fields as $field) {
2621 $field_name = $field->htmlvar_name.'_privacy';
2622 if (isset($_POST[$field_name])) {
2623 $value = strip_tags(esc_sql($_POST[$field_name]));
2624 $user_id = get_current_user_id();
2625 uwp_update_usermeta($user_id, $field_name, $value);
2626 }
2627 }
2628 }
2629
2630 $user_id = get_current_user_id();
2631 if (isset($_POST['uwp_hide_from_listing']) && 1 == $_POST['uwp_hide_from_listing']) {
2632 update_user_meta($user_id, 'uwp_hide_from_listing', 1);
2633 } else {
2634 update_user_meta($user_id, 'uwp_hide_from_listing', 0);
2635 }
2636
2637 $make_profile_private = uwp_can_make_profile_private();
2638 if ($make_profile_private) {
2639 $field_name = 'uwp_make_profile_private';
2640 if (isset($_POST[$field_name])) {
2641 $value = strip_tags(esc_sql($_POST[$field_name]));
2642 $user_id = get_current_user_id();
2643 update_user_meta($user_id, $field_name, $value);
2644 }
2645 }
2646
2647 }
2648 }
2649
2650 }