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

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