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

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

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