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

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