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

4,539 lines 146.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Form related functions
5 *
6 * This class defines all code necessary to handle UsersWP forms like login. register etc.
7 *
8 * @since 1.0.0
9 * @author GeoDirectory Team <info@wpgeodirectory.com>
10 */
11 class UsersWP_Forms {
12
13 protected $generated_password;
14
15 /**
16 * Logs the error message.
17 *
18 * @param array|object|string $log Error message.
19 *
20 * @return void
21 * @since 1.0.0
22 * @package userswp
23 *
24 */
25 public static function uwp_error_log( $log ) {
26 uwp_error_log( $log );
27 }
28
29 /**
30 * Initialize UsersWP notices.
31 *
32 * @return void
33 * @package userswp
34 *
35 * @since 1.0.0
36 */
37 public function init_notices() {
38 global $uwp_notices;
39 $uwp_notices = array();
40 }
41
42 /**
43 * Handles all UsersWP forms.
44 *
45 * @return void
46 * @package userswp
47 *
48 * @since 1.0.0
49 */
50 public function handler() {
51 global $uwp_notices;
52
53 ob_start();
54
55 $errors = null;
56 $message = null;
57 $redirect = false;
58 $processed = false;
59 $type = null;
60
61 if ( isset( $_POST['uwp_avatar_submit'] ) ) {
62 $errors = $this->process_upload_submit( $_POST, $_FILES, 'avatar' );
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_submit'] ) ) {
69 $errors = $this->process_upload_submit( $_POST, $_FILES, 'banner' );
70 if ( ! is_wp_error( $errors ) ) {
71 $redirect = $errors;
72 }
73 $message = __( 'Banner cropped successfully.', 'userswp' );
74 $processed = true;
75 } elseif ( isset( $_POST['uwp_avatar_crop'] ) ) {
76 $errors = $this->process_image_crop( $_POST, 'avatar', true );
77 if ( ! is_wp_error( $errors ) ) {
78 $redirect = $errors;
79 }
80 $message = __( 'Avatar cropped successfully.', 'userswp' );
81 $processed = true;
82 } elseif ( isset( $_POST['uwp_banner_crop'] ) ) {
83 $errors = $this->process_image_crop( $_POST, 'banner', true );
84 if ( ! is_wp_error( $errors ) ) {
85 $redirect = $errors;
86 }
87 $message = __( 'Banner cropped successfully.', 'userswp' );
88 $processed = true;
89 } elseif ( isset( $_POST['uwp_avatar_reset'] ) ) {
90 $errors = $this->process_image_reset( 'avatar' );
91 if ( ! is_wp_error( $errors ) ) {
92 $redirect = $errors;
93 }
94 $message = __( 'Avatar reset successfully.', 'userswp' );
95 $processed = true;
96 } elseif ( isset( $_POST['uwp_banner_reset'] ) ) {
97 $errors = $this->process_image_reset( 'banner' );
98 if ( ! is_wp_error( $errors ) ) {
99 $redirect = $errors;
100 }
101 $message = __( 'Banner reset successfully.', 'userswp' );
102 $processed = true;
103 }
104
105 if ( $processed ) {
106 if ( is_wp_error( $errors ) ) {
107 echo aui()->alert( array(
108 'type' => 'error',
109 'class' => 'text-center',
110 'content' => $errors->get_error_message()
111 ) );
112 } else {
113 if ( $redirect ) {
114 wp_safe_redirect( $redirect );
115 exit();
116 } else {
117 echo aui()->alert( array(
118 'type' => 'success',
119 'class' => 'text-center',
120 'content' => $message
121 ) );
122 }
123 }
124 }
125
126 if ( $type ) {
127 $uwp_notices[] = array( $type => ob_get_contents() );
128 } else {
129 $uwp_notices[] = ob_get_contents();
130 }
131
132 ob_end_clean();
133
134 }
135
136 /**
137 * Processes avatar and banner uploads form submission.
138 *
139 * @param array $data Submitted $_POST data
140 * @param array $files Submitted $_FILES data
141 *
142 * @return bool|WP_Error|string File url to crop.
143 * @package userswp
144 *
145 * @since 1.0.0
146 */
147 public function process_upload_submit( $data = array(), $files = array(), $type = 'avatar' ) {
148
149 $file_obj = new UsersWP_Files();
150
151 $current_user_id = get_current_user_id();
152 if ( ! $current_user_id ) {
153 return false;
154 }
155
156 if ( ! isset( $data['uwp_upload_nonce'] ) || ! wp_verify_nonce( $data['uwp_upload_nonce'], 'uwp-upload-nonce' ) ) {
157 return false;
158 }
159
160 do_action( 'uwp_before_validate', $type );
161
162 $result = $file_obj->validate_uploads( $files, $type );
163
164 $result = apply_filters( 'uwp_validate_result', $result, $type, $data );
165
166 if ( is_wp_error( $result ) ) {
167 return $result;
168 }
169
170 $profile_url = uwp_build_profile_tab_url( $current_user_id );
171
172 $url = add_query_arg(
173 array(
174 'uwp_crop' => $result[ 'uwp_' . $type . '_file' ],
175 'type' => $type
176 ),
177 $profile_url );
178
179 return $url;
180
181 }
182
183 /**
184 * Processes avatar and banner uploads image crop.
185 *
186 * @param array $data Submitted $_POST data
187 * @param string $type Image type. Default 'avatar'.
188 * @param bool $unlink_prev_img True to remove previous image. Default false;
189 *
190 * @return bool|WP_Error|string Profile url.
191 * @since 1.0.12 New param $unlink_prev_img introduced.
192 * @package userswp
193 *
194 * @since 1.0.0
195 */
196 public function process_image_crop( $data = array(), $type = 'avatar', $unlink_prev_img = false ) {
197
198 if ( ! is_user_logged_in() ) {
199 return false;
200 }
201
202 if ( empty( $_POST['uwp_crop_nonce'] ) || !wp_verify_nonce( $_POST['uwp_crop_nonce'], 'uwp_crop_nonce_'.$type ) ) {
203 return;
204 }
205
206 // If is current user's profile (profile.php)
207 if ( is_admin() && defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) {
208 $user_id = get_current_user_id();
209 // If is another user's profile page
210 } elseif ( is_admin() && ! empty( $_GET['user_id'] ) && is_numeric( $_GET['user_id'] ) ) {
211 $user_id = absint($_GET['user_id']);
212 // Otherwise something is wrong.
213 } else {
214 $user_id = get_current_user_id();
215 }
216 $image_url = $data['uwp_crop'];
217
218 $errors = new WP_Error();
219 if ( empty( $image_url ) ) {
220 $errors->add( 'something_wrong', __( 'Something went wrong. Please contact site admin.', 'userswp' ) );
221 }
222
223 $error_code = $errors->get_error_code();
224 if ( ! empty( $error_code ) ) {
225 return $errors;
226 }
227
228 if ( $image_url ) {
229 if ( $type == 'avatar' ) {
230 $avatar_size = uwp_get_upload_image_size();
231 $full_width = $avatar_size['width'];
232 } else {
233 $banner_size = uwp_get_upload_image_size('banner');
234 $full_width = $banner_size['width'];
235 }
236
237 $image_url = esc_url( $image_url );
238 add_filter( 'upload_dir', 'uwp_handle_multisite_profile_image', 10, 1 );
239 $uploads = wp_upload_dir();
240 remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image' );
241 $upload_url = $uploads['baseurl'];
242 $upload_path = $uploads['basedir'];
243 $image_url = str_replace( $upload_url, $upload_path, $image_url );
244 $ext = pathinfo( $image_url, PATHINFO_EXTENSION ); // to get extension
245 $name = pathinfo( $image_url, PATHINFO_FILENAME ); //file name without extension
246 $thumb_image_name = $name . '_uwp_' . $type . '_thumb' . '.' . $ext;
247 $thumb_image_location = str_replace( $name . '.' . $ext, $thumb_image_name, $image_url );
248 //Get the new coordinates to crop the image.
249 $x = $data["x"];
250 $y = $data["y"];
251 $w = $data["w"];
252 $h = $data["h"];
253 //Scale the image based on cropped width setting
254 $scale = $full_width / $w;
255 //$scale = 1; // no scaling
256 $cropped = uwp_resizeThumbnailImage( $thumb_image_location, $image_url, $x, $y, $w, $h, $scale );
257 $cropped = str_replace( $upload_path, $upload_url, $cropped );
258
259 // Remove previous avatar/banner
260 $unlink_img = '';
261 if ( $unlink_prev_img ) {
262 if ( $type == 'avatar' ) {
263 $previous_img = uwp_get_usermeta( $user_id, 'avatar_thumb' );
264 } else if ( $type == 'banner' ) {
265 $previous_img = uwp_get_usermeta( $user_id, 'banner_thumb' );
266 } else {
267 $previous_img = '';
268 }
269
270 if ( $previous_img ) {
271 $unlink_img = untrailingslashit( $upload_path ) . '/' . ltrim( $previous_img, '/' );
272 }
273 }
274
275 // remove the uploads path for easy migrations
276 $cropped = str_replace( $upload_url, '', $cropped );
277 if ( $type == 'avatar' ) {
278 uwp_update_usermeta( $user_id, 'avatar_thumb', $cropped );
279 } else {
280 uwp_update_usermeta( $user_id, 'banner_thumb', $cropped );
281 }
282
283 if ( $unlink_img && $unlink_img != $thumb_image_location && is_file( $unlink_img ) && file_exists( $unlink_img ) ) {
284 @unlink( $unlink_img );
285 $unlink_ori_img = str_replace( '_uwp_' . $type . '_thumb' . '.', '.', $unlink_img );
286 if ( is_file( $unlink_ori_img ) && file_exists( $unlink_ori_img ) ) {
287 @unlink( $unlink_ori_img );
288 }
289 }
290 }
291
292 if ( is_admin() ) {
293 if ( $user_id == get_current_user_id() ) {
294 $redirect_url = admin_url( 'profile.php' );
295 } else {
296 $redirect_url = admin_url( 'user-edit.php?user_id=' . $user_id );
297 }
298 } elseif ( uwp_current_page_url() ) {
299 $redirect_url = uwp_current_page_url();
300 } else {
301 $redirect_url = uwp_build_profile_tab_url( $user_id );
302 }
303
304 return $redirect_url;
305
306 }
307
308 /**
309 * Processes avatar and banner image reset.
310 *
311 * @param string $type Image type. Default 'avatar'.
312 *
313 * @return bool|WP_Error|string Profile url.
314 * @package userswp
315 *
316 */
317 public function process_image_reset( $type ) {
318 if ( ! is_user_logged_in() ) {
319 return false;
320 }
321
322 if ( empty( $_POST['uwp_reset_nonce'] ) || !wp_verify_nonce( $_POST['uwp_reset_nonce'], 'uwp_reset_nonce_'.$type ) ) {
323 return;
324 }
325
326 if ( is_admin() && defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) {
327 $user_id = get_current_user_id();
328 // If is another user's profile page
329 } elseif ( is_admin() && ! empty( $_GET['user_id'] ) && is_numeric( $_GET['user_id'] ) ) {
330 $user_id = absint($_GET['user_id']);
331 // Otherwise something is wrong.
332 } else {
333 $user_id = get_current_user_id();
334 }
335
336 $errors = new WP_Error();
337 if ( empty( $user_id ) ) {
338 $errors->add( 'something_wrong', __( 'Something went wrong. Please try again.', 'userswp' ) );
339 }
340
341 $error_code = $errors->get_error_code();
342 if ( ! empty( $error_code ) ) {
343 return $errors;
344 }
345
346 if ( $type == 'avatar' ) {
347 uwp_update_usermeta( $user_id, 'avatar_thumb', '' );
348 } elseif ( $type == 'banner' ) {
349 uwp_update_usermeta( $user_id, 'banner_thumb', '' );
350 } else {
351 // Do nothing
352 }
353
354 if ( is_admin() ) {
355 if ( $user_id == get_current_user_id() ) {
356 $redirect_url = admin_url( 'profile.php' );
357 } else {
358 $redirect_url = admin_url( 'user-edit.php?user_id=' . $user_id );
359 }
360 } elseif ( uwp_current_page_url() ) {
361 $redirect_url = uwp_current_page_url();
362 } else {
363 $redirect_url = uwp_build_profile_tab_url( $user_id );
364 }
365
366 return $redirect_url;
367 }
368
369 /**
370 * Displays links in a dropdown
371 *
372 * @param $options
373 *
374 * @package userswp
375 *
376 * @since 1.0.0
377 */
378 public function output_dashboard_links( $options ) {
379 if ( ! empty( $options ) ) {
380 $class = uwp_get_option( "design_style", 'bootstrap' ) == 'bootstrap' ? 'form-control' : 'aui-select2';
381 echo "<select class='$class' onchange='window.location = jQuery(this).val();'>";
382 $this->output_options( $options );
383 echo "</select>";
384 }
385 }
386
387 /**
388 * Displays options for the dashboard links
389 *
390 * @param $options
391 *
392 * @package userswp
393 *
394 * @since 1.0.0
395 */
396 public function output_options( $options ) {
397 if ( ! empty( $options ) ) {
398 foreach ( $options as $key => $link ) {
399
400 if ( ! isset( $link['text'] ) && isset( $link[0] ) && is_array( $link[0] ) ) {
401 $this->output_options( $link );
402 } else {
403 if ( ! empty( $link['optgroup'] ) && $link['optgroup'] == 'open' ) {
404 echo "<optgroup label='" . esc_attr( $link['text'] ) . "'>";
405 } elseif ( ! empty( $link['optgroup'] ) && $link['optgroup'] == 'close' ) {
406 echo "</optgroup>";
407 } elseif ( ! empty( $link['text'] ) ) {
408 $disabled = ! empty( $link['disabled'] ) ? 'disabled' : '';
409 $selected = ! empty( $link['selected'] ) ? 'selected' : '';
410 $value = ! empty( $link['url'] ) ? esc_url( $link['url'] ) : '';
411 $display_none = ! empty( $link['display_none'] ) ? 'style="display:none;"' : '';
412 echo "<option $disabled $selected value='$value' $display_none>";
413 echo esc_attr__( $link['text'], 'userswp' );
414 echo "</option>";
415 }
416 }
417 }
418 }
419 }
420
421 /**
422 * Displays UsersWP notices in forms.
423 *
424 * @param string $type Form type
425 *
426 * @return void
427 * @since 1.0.0
428 * @package userswp
429 *
430 */
431 public function display_notices( $type ) {
432 global $uwp_notices;
433
434 if ( is_array( $uwp_notices ) ) {
435 foreach ( $uwp_notices as $notice ) {
436
437 // If the notification is type specific then only output on that type
438 if ( is_array( $notice ) ) {
439 foreach ( $notice as $key => $val ) {
440 if ( $key == $type ) {
441 echo $val;
442 }
443 }
444 } else {
445 if ( ! empty( $notice ) ) {
446 echo $notice;
447 }
448 }
449
450 }
451
452 }
453
454 if ( $type == 'change' ) {
455 $user_id = get_current_user_id();
456 $password_nag = get_user_option( 'default_password_nag', $user_id );
457
458 if ( $password_nag ) {
459 $change_page = uwp_get_page_id( 'change_page', false );
460 $remove_nag_url = add_query_arg( 'uwp_remove_nag', 'yes', get_permalink( $change_page ) );
461
462 if ( isset( $_GET['uwp_remove_nag'] ) && $_GET['uwp_remove_nag'] == 'yes' ) {
463 delete_user_meta( $user_id, 'default_password_nag' );
464 $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( '/' ) );
465 echo aui()->alert( array(
466 'class' => 'text-center',
467 'type' => 'success',
468 'content' => $message
469 ) );
470 } else {
471 $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 );
472 echo aui()->alert( array(
473 'class' => 'text-center',
474 'type' => 'warning',
475 'content' => $message
476 ) );
477 }
478 }
479 }
480 }
481
482 /**
483 * Processes register form submission.
484 *
485 * @since 1.0.0
486 * @package userswp
487 *
488 */
489 public function process_register() {
490
491 $data = $_POST;
492
493 if ( ! isset( $data['uwp_register_nonce'] ) ) {
494 return;
495 }
496
497 global $uwp_notices;
498
499 if ( isset( $data['uwp_register_hp'] ) && '' != $data['uwp_register_hp'] ) {
500 wp_die( __( 'No spam please!', 'userswp' ) );
501 }
502
503 if ( ! isset( $data['uwp_register_nonce'] ) || ! wp_verify_nonce( $data['uwp_register_nonce'], 'uwp-register-nonce' ) ) {
504 $message = aui()->alert( array(
505 'type' => 'error',
506 'content' => __( 'Security verification failed. Try again.', 'userswp' )
507 )
508 );
509 if ( wp_doing_ajax() ) {
510 wp_send_json_error( $message );
511 } else {
512 $uwp_notices[] = array( 'register' => $message );
513
514 return;
515 }
516 }
517
518 $hash = substr( hash( 'SHA256', AUTH_KEY . site_url() ), 0, 25 );
519 if ( empty( $data['uwp_register_hash'] ) || $hash != $data['uwp_register_hash'] ) {
520 $message = aui()->alert( array(
521 'type' => 'error',
522 'content' => __( 'Security hash failed. Try again.', 'userswp' )
523 )
524 );
525 if ( wp_doing_ajax() ) {
526 wp_send_json_error( $message );
527 } else {
528 $uwp_notices[] = array( 'register' => $message );
529
530 return;
531 }
532 }
533
534 if ( ! get_option( 'users_can_register' ) ) {
535 $message = aui()->alert( array(
536 'type' => 'error',
537 'content' => __( 'User registration is currently not allowed. Please check settings of your site.', 'userswp' )
538 )
539 );
540 if ( wp_doing_ajax() ) {
541 wp_send_json_error( $message );
542 } else {
543 $uwp_notices[] = array( 'register' => $message );
544
545 return;
546 }
547 }
548
549 $files = $_FILES;
550 $errors = new WP_Error();
551 $file_obj = new UsersWP_Files();
552
553 do_action( 'uwp_before_validate', 'register' );
554
555 $result = uwp_validate_fields( $data, 'register' );
556
557 $result = apply_filters( 'uwp_validate_result', $result, 'register', $data );
558
559 if ( is_wp_error( $result ) ) {
560 $message = aui()->alert( array(
561 'type' => 'error',
562 'content' => $result->get_error_message()
563 )
564 );
565 if ( wp_doing_ajax() ) {
566 wp_send_json_error( $message );
567 } else {
568 $uwp_notices[] = array( 'register' => $message );
569
570 return;
571 }
572 }
573
574 $uploads_result = $file_obj->validate_uploads( $files, 'register' );
575
576 if ( is_wp_error( $uploads_result ) ) {
577 $message = aui()->alert( array(
578 'type' => 'error',
579 'content' => $uploads_result->get_error_message()
580 )
581 );
582 if ( wp_doing_ajax() ) {
583 wp_send_json_error( $message );
584 } else {
585 $uwp_notices[] = array( 'register' => $message );
586
587 return;
588 }
589 }
590
591 do_action( 'uwp_after_validate', 'register' );
592
593 $result = array_merge( $result, $uploads_result );
594
595 if ( isset( $result['password'] ) && ! empty( $result['password'] ) ) {
596 $password = $result['password'];
597 $generated_password = false;
598 } else {
599 $password = wp_generate_password();
600 $this->generated_password = $password;
601 $generated_password = true;
602 }
603
604 $first_name = "";
605 if ( isset( $result['first_name'] ) && ! empty( $result['first_name'] ) ) {
606 $first_name = $result['first_name'];
607 }
608
609 $last_name = "";
610 if ( isset( $result['last_name'] ) && ! empty( $result['last_name'] ) ) {
611 $last_name = $result['last_name'];
612 }
613
614 if ( isset( $result['display_name'] ) && ! empty( $result['display_name'] ) ) {
615 $display_name = $result['display_name'];
616 } else {
617 if ( ! empty( $first_name ) || ! empty( $last_name ) ) {
618 $display_name = $first_name . ' ' . $last_name;
619 } else {
620 $display_name = ! empty( $result['username'] ) ? $result['username'] : '';
621 }
622 }
623
624 $user_url = "";
625 if ( isset( $result['user_url'] ) && ! empty( $result['user_url'] ) ) {
626 $user_url = esc_url_raw( $result['user_url'] );
627 }
628
629 $user_login = ! empty( $result['username'] ) ? $result['username'] : '';
630 $email = ! empty( $result['email'] ) ? sanitize_email( $result['email'] ) : '';
631
632 if ( empty( $user_login ) ) {
633 $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
634 if ( ! ( validate_username( $user_login ) && ! username_exists( $user_login ) ) ) {
635 $new_user_login = strstr( $email, '@', true );
636 if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
637 $user_login = sanitize_user( $new_user_login, true );
638 }
639 if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
640 $user_append_text = rand( 10, 1000 );
641 $user_login = sanitize_user( $new_user_login . $user_append_text, true );
642 }
643
644 if ( ! ( validate_username( $user_login ) && ! username_exists( $user_login ) ) ) {
645 $user_login = $email;
646 }
647 }
648 } else {
649 if ( ! validate_username( $user_login ) ) {
650 $message = aui()->alert( array(
651 'type' => 'error',
652 'content' => __( 'Sorry, that username is not allowed.', 'userswp' )
653 )
654 );
655 if ( wp_doing_ajax() ) {
656 wp_send_json_error( $message );
657 } else {
658 $uwp_notices[] = array( 'register' => $message );
659
660 return;
661 }
662 }
663 }
664
665 $args = array(
666 'user_login' => sanitize_user( $user_login ),
667 'user_email' => sanitize_email( $email ),
668 'user_pass' => $password,
669 'display_name' => sanitize_text_field( $display_name ),
670 'first_name' => esc_attr( $first_name ),
671 'last_name' => esc_attr( $last_name ),
672 'user_url' => esc_url_raw($user_url),
673 );
674
675 $user_id = wp_insert_user( $args );
676
677 if ( is_wp_error( $user_id ) ) {
678 $message = aui()->alert( array(
679 'type' => 'error',
680 'content' => $user_id->get_error_message()
681 )
682 );
683 if ( wp_doing_ajax() ) {
684 wp_send_json_error( $message );
685 } else {
686 $uwp_notices[] = array( 'register' => $message );
687
688 return;
689 }
690 }
691
692 $result = apply_filters( 'uwp_before_extra_fields_save', $result, 'register', $user_id );
693
694 $form_id = 1;
695
696 if ( isset( $data['uwp_register_form_id'] ) && ! empty( $data['uwp_register_form_id'] ) ) {
697 update_user_meta( $user_id, '_uwp_register_form_id', (int) $data['uwp_register_form_id'] );
698 $form_id = (int) $data['uwp_register_form_id'];
699 }
700
701 $user_role = uwp_get_register_form_by($form_id, 'user_role');
702
703 if ( isset( $user_role ) && ! empty( $user_role ) ) {
704 $user_roles = uwp_get_user_roles();
705 $chosen_role = strtolower( $user_role );
706 if ( ! empty( $user_roles ) ) {
707 $wp_roles = wp_roles();
708 if ( $wp_roles->is_role( $chosen_role ) && in_array( $chosen_role, array_keys( $user_roles ) ) ) {
709 $new_user = get_userdata( $user_id );
710 if($new_user){
711 $new_user->set_role( $chosen_role );
712 }
713 }
714 }
715 }
716
717 $save_result = $this->save_user_extra_fields( $user_id, $result, 'register' );
718
719 $save_result = apply_filters( 'uwp_after_extra_fields_save', $save_result, $result, 'register', $user_id );
720
721 if ( is_wp_error( $save_result ) ) {
722 $message = aui()->alert( array(
723 'type' => 'error',
724 'content' => $save_result->get_error_message()
725 )
726 );
727 if ( wp_doing_ajax() ) {
728 wp_send_json_error( $message );
729 } else {
730 $uwp_notices[] = array( 'register' => $message );
731
732 return;
733 }
734 }
735
736 if ( ! $save_result ) {
737 $message = aui()->alert( array(
738 'type' => 'error',
739 'content' => __( 'Something went wrong. Please contact site admin.', 'userswp' )
740 )
741 );
742 if ( wp_doing_ajax() ) {
743 wp_send_json_error( $message );
744 } else {
745 $uwp_notices[] = array( 'register' => $message );
746
747 return;
748 }
749 }
750
751 //updating bio field after saving extra fields to reflect the points in mycred add on.
752 if ( isset( $result['bio'] ) && ! empty( $result['bio'] ) ) {
753 $args = array(
754 'ID' => $user_id,
755 'description' => $result['bio'],
756 );
757 wp_update_user( $args );
758 }
759
760 do_action( 'uwp_after_custom_fields_save', 'register', $data, $result, $user_id );
761
762 // Unset post data to empty the form on submit
763 $excluded_post_data = apply_filters('uwp_register_excluded_post_reset_fields', array('uwp_register_nonce'));
764 foreach($data as $key=>$value){
765 if(isset($key) && !in_array($key, $excluded_post_data)){
766 unset($_POST[$key]);
767 }
768 }
769
770 $reg_action = uwp_get_register_form_by($form_id, 'reg_action');
771 if(!$reg_action){
772 $reg_action = uwp_get_option( 'uwp_registration_action', false );
773 }
774
775 $form_fields = apply_filters( 'uwp_send_mail_form_fields', "", 'register', $user_id );
776
777 if ( $reg_action == 'require_email_activation' && ! $generated_password ) {
778
779 $user_data = get_userdata( $user_id );
780 $activation_link = uwp_get_activation_link( $user_id );
781
782 $message = __( 'To activate your account, visit the following address:', 'userswp' ) . "\r\n\r\n";
783
784 $message .= "<a href='" . esc_url_raw( $activation_link ) . "' target='_blank'>" . esc_url_raw( $activation_link ) . "</a>" . "\r\n";
785
786 $activate_message = '<p><b>' . __( 'Please activate your account :', 'userswp' ) . '</b></p><p>' . $message . '</p>';
787
788 $activate_message = apply_filters( 'uwp_activation_mail_message', $activate_message, $user_id );
789
790 $email_vars = array(
791 'user_id' => $user_id,
792 'login_details' => $activate_message,
793 'activation_link' => $activation_link,
794 );
795
796 UsersWP_Mails::send( $user_data->user_email, 'registration_activate', $email_vars );
797
798 } else {
799
800 if ( $reg_action != 'require_admin_review' ) {
801
802 $user_data = get_userdata( $user_id );
803
804 if ( isset( $this->generated_password ) && ! empty( $this->generated_password ) ) {
805 if ( ! uwp_get_option( 'change_disable_password_nag' ) ) {
806 update_user_meta( $user_id, 'default_password_nag', true ); //Set up the Password change nag.
807 }
808 $message_pass = $this->generated_password;
809 $this->generated_password = false;
810 } else {
811 $message_pass = __( "Password you entered during registration.", 'userswp' );
812 }
813
814 $message = '<p><b>' . __( 'Your login Information :', 'userswp' ) . '</b></p>
815 <p>' . __( 'Username:', 'userswp' ) . ' ' . $user_data->user_login . '</p>
816 <p>' . __( 'Password:', 'userswp' ) . ' ' . $message_pass . '</p>';
817
818 $message = apply_filters( 'uwp_register_mail_message', $message, $user_id, $this->generated_password );
819
820 $email_vars = array(
821 'user_id' => $user_id,
822 'login_details' => $message,
823 'form_fields' => $form_fields,
824 );
825
826 UsersWP_Mails::send( $user_data->user_email, 'registration_success', $email_vars );
827 }
828 }
829
830 $error_code = $errors->get_error_code();
831 if ( ! empty( $error_code ) ) {
832 $message = aui()->alert( array(
833 'type' => 'error',
834 'content' => $result->get_error_message()
835 )
836 );
837 if ( wp_doing_ajax() ) {
838 wp_send_json_error( $message );
839 } else {
840 $uwp_notices[] = array( 'register' => $message );
841 return;
842 }
843 }
844
845 if ( $reg_action != 'require_admin_review' ) {
846
847 $user_data = get_userdata( $user_id );
848 $extras = '<p><b>' . __( 'User Information :', 'userswp' ) . '</b></p>
849 <p>' . __( 'First Name:', 'userswp' ) . ' ' . $user_data->first_name . '</p>
850 <p>' . __( 'Last Name:', 'userswp' ) . ' ' . $user_data->last_name . '</p>
851 <p>' . __( 'Username:', 'userswp' ) . ' ' . $user_data->user_login . '</p>
852 <p>' . __( 'Email:', 'userswp' ) . ' ' . $user_data->user_email . '</p>';
853
854 $extras = apply_filters( 'uwp_admin_mail_extras', $extras, 'register_admin', $user_id );
855
856 $email_vars = array(
857 'user_id' => $user_id,
858 'extras' => $extras,
859 'form_fields' => $form_fields,
860 );
861
862 UsersWP_Mails::send( get_option( 'admin_email' ), 'registration_success', $email_vars, true );
863
864 }
865
866 if ( $reg_action == 'auto_approve_login' ) {
867 $res = wp_signon(
868 array(
869 'user_login' => $user_login,
870 'user_password' => $password,
871 'remember' => false
872 )
873 );
874
875 if ( is_wp_error( $res ) ) {
876 $message = aui()->alert( array(
877 'type' => 'error',
878 'content' => $res->get_error_message()
879 )
880 );
881
882 if ( wp_doing_ajax() ) {
883 wp_send_json_error( $message );
884 } else {
885 $uwp_notices[] = array( 'register' => $message );
886 }
887 } else {
888 $redirect_to = $this->get_register_redirect_url( $data, $user_id );
889 do_action( 'uwp_after_process_register', $result, $user_id );
890
891 if ( wp_doing_ajax() ) {
892 $message = aui()->alert( array(
893 'type' => 'success',
894 'content' => __( 'Account registered successfully. Redirecting...', 'userswp' )
895 )
896 );
897 $response = array(
898 'message' => $message,
899 'redirect' => $redirect_to,
900 );
901 wp_send_json_success( $response );
902 } else {
903 wp_safe_redirect( $redirect_to );
904 }
905 exit();
906 }
907 } else {
908 if ( $reg_action == 'require_email_activation' ) {
909 $resend_link = uwp_get_register_page_url();
910 $resend_link = add_query_arg(
911 array(
912 'user_id' => $user_id,
913 'action' => 'uwp_resend',
914 '_nonce' => wp_create_nonce( 'uwp_resend' ),
915 ),
916 $resend_link
917 );
918
919 $message = aui()->alert( array(
920 'type' => 'success',
921 'content' => 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>' )
922 )
923 );
924
925 } elseif ( $reg_action == 'require_admin_review' && defined( 'UWP_MOD_VERSION' ) ) {
926
927 update_user_meta( $user_id, 'uwp_mod', '1' );
928
929 do_action( 'uwp_require_admin_review', $user_id, $result );
930
931 $message = aui()->alert( array(
932 'type' => 'success',
933 'content' => __( 'Your account is under moderation. We will email you once its approved.', 'userswp' )
934 )
935 );
936 } else {
937
938 $login_page_url = wp_login_url();
939
940 if ( $generated_password ) {
941 $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>' );
942 } else {
943 $msg = sprintf( __( 'Account registered successfully. Please login %shere%s', 'userswp' ), '<a href="' . $login_page_url . '">', '</a>' );
944 }
945
946 $message = aui()->alert( array(
947 'type' => 'success',
948 'content' => $msg
949 )
950 );
951 }
952
953 do_action( 'uwp_after_process_register', $result, $user_id );
954
955 if ( wp_doing_ajax() ) {
956 wp_send_json_success( $message );
957 } else {
958 $uwp_notices[] = array( 'register' => $message );
959 }
960
961 }
962
963 if ( wp_doing_ajax() ) {
964 wp_send_json_error();
965 } // if we got this far there is a problem
966
967 }
968
969 /**
970 * Saves UsersWP related user custom fields.
971 *
972 * @param int $user_id User ID.
973 * @param array $data Result array.
974 * @param string $type Form type.
975 *
976 * @return bool True when success. False when failure.
977 * @since 1.0.0
978 * @package userswp
979 *
980 */
981 public function save_user_extra_fields( $user_id, $data, $type ) {
982
983 if ( empty( $user_id ) || empty( $data ) || empty( $type ) ) {
984 return false;
985 }
986
987 // custom user fields not applicable for login and forgot
988 if ( $type == 'login' || $type == 'forgot' ) {
989 return true;
990 }
991
992
993 if ( $type == 'account' || $type == 'register' ) {
994 if ( isset( $data['password'] ) ) {
995 unset( $data['password'] );
996 }
997 }
998
999 if ( $type == 'register' ) {
1000 if ( isset( $data['username'] ) ) {
1001 unset( $data['username'] );
1002 }
1003 if ( isset( $data['email'] ) ) {
1004 unset( $data['email'] );
1005 }
1006 }
1007
1008 if ( empty( $data ) ) {
1009 // no extra fields. so just return
1010 return true;
1011 } else {
1012 foreach ( $data as $key => $value ) {
1013 uwp_update_usermeta( $user_id, $key, $value );
1014 }
1015
1016 return true;
1017 }
1018 }
1019
1020 public function get_register_redirect_url( $data, $user ) {
1021 if ( is_int( $user ) ) {
1022 $user = get_userdata( $user );
1023 }
1024
1025 $redirect_page_id = $custom_url = '';
1026 if ( isset( $data['uwp_register_form_id'] ) && ! empty( $data['uwp_register_form_id'] ) ) {
1027 $form_id = (int) $data['uwp_register_form_id'];
1028 $redirect_page_id = uwp_get_register_form_by($form_id, 'redirect_to');
1029 $custom_url = uwp_get_register_form_by($form_id, 'custom_url');
1030 }
1031
1032 if(!$redirect_page_id){
1033 $redirect_page_id = uwp_get_option( 'register_redirect_to', '' );
1034 $custom_url = uwp_get_option( 'register_redirect_custom_url' );
1035 }
1036
1037 if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
1038 $redirect_to = esc_url_raw( $_REQUEST['redirect_to'] );
1039 } elseif ( isset( $data['redirect_to'] ) && ! empty( $data['redirect_to'] ) ) {
1040 $redirect_to = esc_url_raw( $data['redirect_to'] );
1041 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) {
1042 if ( uwp_is_wpml() ) {
1043 $wpml_page_id = uwp_wpml_object_id( $redirect_page_id, 'page', true, ICL_LANGUAGE_CODE );
1044 if ( ! empty( $wpml_page_id ) ) {
1045 $redirect_page_id = $wpml_page_id;
1046 }
1047 }
1048 $redirect_to = get_permalink( $redirect_page_id );
1049 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 1 && wp_get_referer() ) {
1050 $redirect_to = esc_url( wp_get_referer() );
1051 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 2 && $custom_url ) {
1052 $redirect_to = $custom_url;
1053 } else {
1054 if ( $user && $user->has_cap( 'manage_options' ) ) {
1055 $redirect_to = admin_url();
1056 } else {
1057 $redirect_to = home_url( '/' );
1058 }
1059
1060 $redirect_to = apply_filters( 'registration_redirect', $redirect_to );
1061 }
1062
1063 return apply_filters( 'uwp_register_redirect', $redirect_to, $redirect_page_id, $data );
1064
1065 }
1066
1067 /**
1068 * Processes login form submission.
1069 *
1070 * @since 1.0.0
1071 * @package userswp
1072 *
1073 */
1074 public function process_login() {
1075
1076 $data = $_POST;
1077
1078 if ( ! isset( $data['uwp_login_nonce'] ) ) {
1079 return;
1080 }
1081
1082 if ( ! isset( $data['uwp_login_nonce'] ) || ! wp_verify_nonce( $data['uwp_login_nonce'], 'uwp-login-nonce' ) ) {
1083 $message = aui()->alert( array(
1084 'type' => 'error',
1085 'content' => __( 'Security verification failed. Try again.', 'userswp' )
1086 )
1087 );
1088 if ( wp_doing_ajax() ) {
1089 wp_send_json_error( $message );
1090 } else {
1091 return;
1092 }
1093 }
1094
1095 global $uwp_notices;
1096
1097 do_action( 'uwp_before_validate', 'login' );
1098
1099 $result = uwp_validate_fields( $data, 'login' );
1100
1101 $result = apply_filters( 'uwp_validate_result', $result, 'login', $data );
1102
1103 if ( is_wp_error( $result ) ) {
1104 $message = aui()->alert( array(
1105 'type' => 'error',
1106 'content' => $result->get_error_message()
1107 )
1108 );
1109 if ( wp_doing_ajax() ) {
1110 wp_send_json_error( $message );
1111 } else {
1112 $uwp_notices[] = array( 'login' => $message );
1113
1114 return;
1115 }
1116 }
1117
1118 do_action( 'uwp_after_validate', 'login' );
1119
1120 if ( isset( $data['remember_me'] ) && $data['remember_me'] == 'forever' ) {
1121 $remember_me = true;
1122 } else {
1123 $remember_me = false;
1124 }
1125
1126 remove_action( 'authenticate', 'gglcptch_login_check', 21 );
1127
1128 global $wp2fa;
1129 if ( wp_doing_ajax() && isset( $wp2fa ) && ! empty( $wp2fa ) ) {
1130 remove_action( 'wp_login', array( $wp2fa->login, 'wp_login' ), 20 );
1131 }
1132
1133 $user = wp_signon(
1134 array(
1135 'user_login' => $result['username'],
1136 'user_password' => $result['password'],
1137 'remember' => $remember_me
1138 )
1139 );
1140
1141 add_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
1142
1143 if ( wp_doing_ajax() && ! is_wp_error( $user ) && isset( $wp2fa ) && ! empty( $wp2fa ) ) {
1144
1145 $two_fa = $this->check_2fa( $user );
1146 if ( isset( $two_fa ) && ! empty( $two_fa ) ) {
1147 if ( is_wp_error( $two_fa ) ) {
1148 $message = aui()->alert( array(
1149 'type' => 'error',
1150 'content' => $two_fa->get_error_message()
1151 )
1152 );
1153 wp_send_json_error( $message );
1154 } else {
1155 wp_send_json_success( array( 'html' => $two_fa, 'is_2fa' => true ) );
1156 }
1157 }
1158 }
1159
1160 if ( is_wp_error( $user ) ) {
1161 $message = aui()->alert( array(
1162 'type' => 'error',
1163 'content' => $user->get_error_message()
1164 )
1165 );
1166 if ( wp_doing_ajax() ) {
1167 wp_send_json_error( $message );
1168 } else {
1169 $uwp_notices[] = array( 'login' => $message );
1170
1171 return;
1172 }
1173 } else {
1174 do_action( 'uwp_after_process_login', $data );
1175 $message = aui()->alert( array(
1176 'type' => 'success',
1177 'content' => __( 'Login successful. Redirecting...', 'userswp' )
1178 )
1179 );
1180 if ( wp_doing_ajax() ) {
1181 wp_send_json_success( $message );
1182 } else {
1183 $redirect_to = $this->get_login_redirect_url( $data, $user );
1184 wp_safe_redirect( $redirect_to );
1185 exit();
1186 }
1187
1188 }
1189
1190 }
1191
1192 public function check_2fa( $user ) {
1193 if ( 1 == uwp_get_option( 'disable_wp_2fa' ) ) {
1194 return;
1195 }
1196
1197 if ( ! $user ) {
1198 $user = wp_get_current_user();
1199 }
1200
1201 global $wp2fa;
1202 $errors = new WP_Error();
1203
1204 if ( ! $wp2fa->login->is_user_using_two_factor( $user->ID ) ) {
1205 return;
1206 }
1207 // Invalidate the current login session to prevent from being re-used.
1208 $wp2fa->login->destroy_current_session_for_user( $user );
1209
1210 // Also clear the cookies which are no longer valid.
1211 wp_clear_auth_cookie();
1212
1213 $login_nonce = $wp2fa->login->create_login_nonce( $user->ID );
1214 if ( ! $login_nonce ) {
1215 $errors->add( 'failed_login_nonce', __( 'Failed to create a login nonce.', 'userswp' ) );
1216
1217 return $errors;
1218 }
1219
1220 $provider = $wp2fa->login->get_available_providers_for_user( $user );
1221
1222 ob_start();
1223 ?>
1224
1225 <div class="uwp-2fa-methods-wrap">
1226 <form name="validate_2fa_form" id="validate_2fa_form" class="validate_2fa_form" action="" method="post"
1227 autocomplete="off">
1228 <input type="hidden" name="provider" id="provider" value="<?php echo esc_attr( $provider ); ?>"/>
1229 <input type="hidden" name="wp-auth-id" id="wp-auth-id" value="<?php echo esc_attr( $user->ID ); ?>"/>
1230 <input type="hidden" name="wp-auth-nonce" id="wp-auth-nonce"
1231 value="<?php echo esc_attr( $login_nonce['key'] ); ?>"/>
1232 <?php
1233
1234 // Check to see what provider is set and give the relevant authentication page.
1235 if ( 'totp' === $provider ) {
1236 ?>
1237 <p><?php esc_html_e( 'Please enter the authentication code from your 2FA authentication app below to login:', 'userswp' ); ?></p>
1238 <?php
1239
1240 echo aui()->input( array(
1241 'type' => 'tel',
1242 'id' => 'authcode',
1243 'name' => 'authcode',
1244 'placeholder' => __( 'Authentication Code', 'userswp' ),
1245 'value' => '',
1246 'label' => __( 'Authentication Code', 'userswp' ),
1247 ) );
1248
1249 echo aui()->button( array(
1250 'type' => 'submit',
1251 'class' => 'btn btn-primary btn-block text-uppercase uwp-2fa-submit',
1252 'name' => 'submit',
1253 'icon' => '',
1254 'content' => __( 'Log In', 'userswp' ),
1255 ) );
1256
1257 } elseif ( 'email' === $provider ) {
1258 $has_token = $wp2fa->authentication->user_has_token( $user->ID );
1259 if ( empty( $has_token ) || ! $has_token ) {
1260 //\WP2FA\Admin\SetupWizard::send_authentication_setup_email( $user->ID );
1261 $wp2fa->wizard->send_authentication_setup_email( $user->ID );
1262 }
1263 ?>
1264 <p><?php esc_html_e( 'Please enter the 2FA verification code sent to your email address to login:', 'userswp' ); ?></p>
1265 <?php
1266 echo aui()->input( array(
1267 'type' => 'tel',
1268 'id' => 'authcode',
1269 'name' => 'wp-2fa-email-code',
1270 'placeholder' => __( 'Verification Code', 'userswp' ),
1271 'value' => '',
1272 'label' => __( 'Verification Code', 'userswp' ),
1273 'extra_attributes' => array( 'size' => 20, 'pattern' => "[0-9]*" ),
1274 ) );
1275
1276 echo aui()->button( array(
1277 'type' => 'submit',
1278 'class' => 'btn btn-primary text-uppercase uwp-2fa-submit',
1279 'name' => 'submit',
1280 'icon' => '',
1281 'content' => __( 'Log In', 'userswp' ),
1282 ) );
1283
1284 echo aui()->button( array(
1285 'type' => 'button',
1286 'class' => 'btn btn-secondary text-uppercase uwp-2fa-email-resend',
1287 'name' => 'wp-2fa-email-code-resend',
1288 'icon' => '',
1289 'content' => __( 'Resend Code', 'userswp' ),
1290 ) );
1291
1292 }
1293 ?>
1294 </form>
1295 </div>
1296
1297 <?php
1298 $codes_remaining = $wp2fa->backupcodes->codes_remaining_for_user( $user );
1299 if ( isset( $codes_remaining ) && $codes_remaining > 0 ) {
1300 ?>
1301 <div class="uwp-2fa-methods-wrap" style="display:none;">
1302 <form name="validate_2fa_backup_codes_form" id="validate_2fa_backup_codes_form"
1303 class="validate_2fa_backup_codes_form" action="" method="post" autocomplete="off">
1304 <input type="hidden" name="provider" id="provider" value="backup_codes"/>
1305 <input type="hidden" name="wp-auth-id" id="wp-auth-id"
1306 value="<?php echo esc_attr( $user->ID ); ?>"/>
1307 <input type="hidden" name="wp-auth-nonce" id="wp-auth-nonce"
1308 value="<?php echo esc_attr( $login_nonce['key'] ); ?>"/>
1309 <div class="uwp-backup-fields">
1310 <?php
1311 echo aui()->input( array(
1312 'type' => 'tel',
1313 'id' => 'authcode',
1314 'name' => 'wp-2fa-backup-code',
1315 'placeholder' => __( 'Enter backup code', 'userswp' ),
1316 'value' => '',
1317 'label' => __( 'Backup Code', 'userswp' ),
1318 'extra_attributes' => array( 'size' => 20, 'pattern' => "[0-9]*" ),
1319 ) );
1320
1321 echo aui()->button( array(
1322 'type' => 'submit',
1323 'class' => 'btn btn-primary btn-block text-uppercase uwp-2fa-submit',
1324 'name' => 'submit',
1325 'icon' => '',
1326 'content' => __( 'Log In', 'userswp' ),
1327 ) );
1328 ?>
1329 </div>
1330 </form>
1331 </div>
1332 <a href="#" class="uwp-switch-2fa-methods text-center d-block"><?php esc_html_e( 'Or, use a backup code.', 'userswp' ); ?></a>
1333 <script type="text/javascript">
1334 jQuery('.uwp-switch-2fa-methods').on('click',
1335 function (e) {
1336 e.preventDefault();
1337 jQuery('.uwp-auth-modal .modal-content .modal-error').html('');
1338 jQuery('.uwp-2fa-methods-wrap').toggle();
1339 return false;
1340 }
1341 );
1342 </script>
1343 <?php
1344 }
1345
1346 return ob_get_clean();
1347 }
1348
1349 public function process_login_2fa() {
1350 if ( ! isset( $_POST['wp-auth-id'], $_POST['wp-auth-nonce'] ) ) {
1351 return;
1352 }
1353
1354 $auth_id = (int) $_POST['wp-auth-id'];
1355 $user = get_userdata( $auth_id );
1356 if ( ! $user ) {
1357 $message = aui()->alert( array(
1358 'type' => 'error',
1359 'content' => __( 'Invalid user data. Please try again.', 'userswp' )
1360 )
1361 );
1362
1363 wp_send_json_error( $message );
1364 }
1365
1366 global $wp2fa;
1367
1368 $nonce = ( isset( $_POST['wp-auth-nonce'] ) ) ? sanitize_textarea_field( wp_unslash( $_POST['wp-auth-nonce'] ) ) : '';
1369 if ( true !== $wp2fa->login->verify_login_nonce( $user->ID, $nonce ) ) {
1370
1371 $message = aui()->alert( array(
1372 'type' => 'error',
1373 'content' => __( 'Invalid request! Please try again.', 'userswp' )
1374 )
1375 );
1376
1377 wp_send_json_error( $message );
1378 }
1379
1380 if ( isset( $_POST['provider'] ) ) {
1381 $provider = sanitize_textarea_field( wp_unslash( $_POST['provider'] ) );
1382 $providers = $wp2fa->login->get_available_providers_for_user( $user );
1383 if ( isset( $providers[ $provider ] ) ) {
1384 $provider = $providers[ $provider ];
1385 } elseif ( isset( $provider ) ) {
1386 $provider = $provider;
1387 } else {
1388 $provider = $provider;
1389 }
1390 }
1391
1392 // If this is an email login, or if the user failed validation previously, lets send the code to the user.
1393 if ( 'email' === $provider && true !== $wp2fa->login->pre_process_email_authentication( $user ) ) {
1394
1395 }
1396
1397 // Validate TOTP.
1398 if ( 'totp' === $provider && true !== $wp2fa->login->validate_totp_authentication( $user ) ) {
1399
1400 do_action( 'wp_login_failed', $user->user_login );
1401
1402 $message = aui()->alert( array(
1403 'type' => 'error',
1404 'content' => __( 'Invalid verification code.', 'userswp' )
1405 )
1406 );
1407
1408 wp_send_json_error( $message );
1409 }
1410
1411 // Validate Email.
1412 if ( 'email' === $provider && true !== $wp2fa->login->validate_email_authentication( $user ) ) {
1413
1414 do_action( 'wp_login_failed', $user->user_login );
1415
1416 if ( isset( $_REQUEST['wp-2fa-email-code-resend'] ) && 1 == $_REQUEST['wp-2fa-email-code-resend'] ) {
1417 $message = aui()->alert( array(
1418 'type' => 'info',
1419 'content' => __( 'A new code has been sent.', 'userswp' )
1420 )
1421 );
1422
1423 wp_send_json_error( $message );
1424 } else {
1425 $message = aui()->alert( array(
1426 'type' => 'error',
1427 'content' => __( 'Invalid verification code.', 'userswp' )
1428 )
1429 );
1430
1431 wp_send_json_error( $message );
1432 }
1433 }
1434
1435 // Backup Codes.
1436 if ( 'backup_codes' === $provider && true !== $wp2fa->login->validate_backup_codes( $user ) ) {
1437
1438 do_action( 'wp_login_failed', $user->user_login );
1439
1440 $message = aui()->alert( array(
1441 'type' => 'error',
1442 'content' => __( 'Invalid backup code.', 'userswp' )
1443 )
1444 );
1445
1446 wp_send_json_error( $message );
1447 }
1448
1449 $wp2fa->login->delete_login_nonce( $user->ID );
1450
1451 $rememberme = false;
1452 $remember = ( isset( $_REQUEST['rememberme'] ) ) ? filter_var( $_REQUEST['rememberme'], FILTER_VALIDATE_BOOLEAN ) : '';
1453 if ( ! empty( $remember ) ) {
1454 $rememberme = true;
1455 }
1456
1457 wp_set_auth_cookie( $user->ID, $rememberme );
1458
1459 do_action( 'two_factor_user_authenticated', $user );
1460
1461 $message = aui()->alert( array(
1462 'type' => 'success',
1463 'content' => __( 'Validation successful. Redirecting...', 'userswp' )
1464 )
1465 );
1466
1467 wp_send_json_success( $message );
1468 }
1469
1470 public function get_login_redirect_url( $data, $user ) {
1471 if ( is_int( $user ) ) {
1472 $user = get_userdata( $user );
1473 }
1474
1475 $redirect_page_id = uwp_get_option( 'login_redirect_to', - 1 );
1476 $custom_url = uwp_get_option( 'login_redirect_custom_url' );
1477
1478 if($user && isset($user->roles[0])){
1479 $user_role = $user->roles[0];
1480 $redirect_page_id = uwp_get_option( 'login_redirect_to_'.$user_role, $redirect_page_id );
1481 $custom_url = uwp_get_option( 'login_redirect_custom_url_'.$user_role );
1482 }
1483
1484 if ( $user && $user->has_cap( 'manage_options' ) ) {
1485 $redirect_to = admin_url();
1486 } elseif ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
1487 $redirect_to = esc_url_raw( $_REQUEST['redirect_to'] );
1488 } elseif ( isset( $data['redirect_to'] ) && ! empty( $data['redirect_to'] ) ) {
1489 $redirect_to = esc_url_raw( $data['redirect_to'] );
1490 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) {
1491 if ( uwp_is_wpml() ) {
1492 $wpml_page_id = uwp_wpml_object_id( $redirect_page_id, 'page', true, ICL_LANGUAGE_CODE );
1493 if ( ! empty( $wpml_page_id ) ) {
1494 $redirect_page_id = $wpml_page_id;
1495 }
1496 }
1497 $redirect_to = get_permalink( $redirect_page_id );
1498 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 1 && wp_get_referer() ) {
1499 $redirect_to = esc_url( wp_get_referer() );
1500 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 2 && !empty($custom_url) ) {
1501 $redirect_to = $custom_url;
1502 } else {
1503 $redirect_to = home_url( '/' );
1504 $redirect_to = apply_filters( 'login_redirect', $redirect_to, '', $user );
1505 }
1506
1507 return apply_filters( 'uwp_login_redirect', $redirect_to, $redirect_page_id, $data, $user );
1508
1509 }
1510
1511 /**
1512 * Processes forgot password form submission.
1513 *
1514 * @since 1.0.0
1515 * @package userswp
1516 *
1517 */
1518 public function process_forgot() {
1519
1520 $data = $_POST;
1521
1522 if ( ! isset( $data['uwp_forgot_nonce'] ) ) {
1523 return;
1524 }
1525
1526 if ( ! isset( $data['uwp_forgot_nonce'] ) || ! wp_verify_nonce( $data['uwp_forgot_nonce'], 'uwp-forgot-nonce' ) ) {
1527 $message = aui()->alert( array(
1528 'type' => 'error',
1529 'content' => __( 'Security verification failed. Try again.', 'userswp' )
1530 )
1531 );
1532 if ( wp_doing_ajax() ) {
1533 wp_send_json_error( $message );
1534 } else {
1535 return;
1536 }
1537 }
1538
1539 global $uwp_notices;
1540
1541 do_action( 'uwp_before_validate', 'forgot' );
1542
1543 $result = uwp_validate_fields( $data, 'forgot' );
1544
1545 $result = apply_filters( 'uwp_validate_result', $result, 'forgot', $data );
1546
1547 if ( is_wp_error( $result ) ) {
1548 $message = aui()->alert( array(
1549 'type' => 'error',
1550 'content' => $result->get_error_message()
1551 )
1552 );
1553 if ( wp_doing_ajax() ) {
1554 wp_send_json_error( $message );
1555 } else {
1556 $uwp_notices[] = array( 'forgot' => $message );
1557
1558 return;
1559 }
1560 }
1561
1562 do_action( 'uwp_after_validate', 'forgot' );
1563
1564
1565 $user_data = get_user_by( 'email', $data['email'] );
1566
1567 // if no user we fake it and bail
1568 if ( ! $user_data ) {
1569 $args = apply_filters('uwp_forgot_error_message', array(
1570 'type' => 'error',
1571 'content' => __( 'Invalid email or user doesn\'t exists.', 'userswp' )
1572 ));
1573
1574 $message = aui()->alert( $args );
1575 if ( wp_doing_ajax() ) {
1576 wp_send_json_success( $message );
1577 } else {
1578 $uwp_notices[] = array( 'forgot' => $message );
1579
1580 return;
1581 }
1582 }
1583
1584 // make sure user account is active before account reset
1585 $mod_value = get_user_meta( $user_data->ID, 'uwp_mod', true );
1586 if ( $mod_value == 'email_unconfirmed' ) {
1587 $message = aui()->alert( array(
1588 'type' => 'error',
1589 'content' => __( 'Your account is not activated yet. Please activate your account first.', 'userswp' )
1590 )
1591 );
1592 if ( wp_doing_ajax() ) {
1593 wp_send_json_error( $message );
1594 } else {
1595 $uwp_notices[] = array( 'forgot' => $message );
1596
1597 return;
1598 }
1599 }
1600
1601 $user_data = get_userdata( $user_data->ID );
1602
1603 $allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
1604
1605 if ( ! $allow ) {
1606 return false;
1607 } else if ( is_wp_error( $allow ) ) {
1608 return false;
1609 }
1610
1611 $as_password = apply_filters( 'uwp_forgot_message_as_password', false );
1612
1613 global $wpdb, $wp_hasher;
1614 $reset_link = '';
1615
1616 if ( $as_password ) {
1617 $new_pass = wp_generate_password( 12, false );
1618 wp_set_password( $new_pass, $user_data->ID );
1619 if ( ! uwp_get_option( 'change_disable_password_nag' ) ) {
1620 update_user_meta( $user_data->ID, 'default_password_nag', true ); //Set up the Password change nag.
1621 }
1622 $message = '<p><b>' . __( 'Your login Information :', 'userswp' ) . '</b></p>';
1623 $message .= '<p>' . sprintf( __( 'Username: %s', 'userswp' ), $user_data->user_login ) . "</p>";
1624 $message .= '<p>' . sprintf( __( 'Password: %s', 'userswp' ), $new_pass ) . "</p>";
1625
1626 } else {
1627 $key = wp_generate_password( 20, false );
1628 do_action( 'retrieve_password_key', $user_data->user_login, $key );
1629
1630 if ( empty( $wp_hasher ) ) {
1631 require_once ABSPATH . 'wp-includes/class-phpass.php';
1632 $wp_hasher = new PasswordHash( 8, true );
1633 }
1634 $hashed = $wp_hasher->HashPassword( $key );
1635 $wpdb->update( $wpdb->users, array( 'user_activation_key' => time() . ":" . $hashed ), array( 'user_login' => $user_data->user_login ) );
1636 $message = '<p>' . __( 'You have requested to reset your password for the following account:', 'userswp' ) . "</p>";
1637 $message .= home_url( '/' ) . "</p>";
1638 $message .= '<p>' . sprintf( __( 'Username: %s', 'userswp' ), $user_data->user_login ) . "</p>";
1639 $message .= '<p>' . __( 'If this was by mistake, just ignore this email and nothing will happen.', 'userswp' ) . "</p>";
1640 $message .= '<p>' . __( 'To reset your password, click the following link and follow the instructions.', 'userswp' ) . "</p>";
1641 $reset_page = uwp_get_page_id( 'reset_page', false );
1642 if ( $reset_page ) {
1643 $reset_link = add_query_arg( array(
1644 'key' => $key,
1645 'login' => rawurlencode( $user_data->user_login ),
1646 ), get_permalink( $reset_page ) );
1647 $message .= "<a href='" . $reset_link . "' target='_blank'>" . $reset_link . "</a>" . "\r\n";
1648 } else {
1649 $reset_link = home_url( "reset?key=$key&login=" . rawurlencode( $user_data->user_login ), 'login' );
1650 $message .= "<a href='" . $reset_link . "' target='_blank'>" . $reset_link . "</a>" . "\r\n";
1651 }
1652 $message = apply_filters( 'uwp_forgot_password_message', $message, $user_data, $reset_link );
1653 }
1654
1655 $message = apply_filters( 'uwp_forgot_mail_message', $message, $user_data->ID );
1656
1657 $email_vars = array(
1658 'user_id' => $user_data->ID,
1659 'login_details' => $message,
1660 'reset_link' => $reset_link,
1661 );
1662
1663 UsersWP_Mails::send( $user_data->user_email, 'forgot_password', $email_vars );
1664
1665 do_action( 'uwp_after_process_forgot', $data );
1666
1667 $message = aui()->alert( array(
1668 'type' => 'success',
1669 'content' => apply_filters( 'uwp_change_password_success_message', __( 'Please check your email.', 'userswp' ), $data )
1670 )
1671 );
1672 if ( wp_doing_ajax() ) {
1673 wp_send_json_success( $message );
1674 } else {
1675 $uwp_notices[] = array( 'forgot' => $message );
1676 }
1677 }
1678
1679 /**
1680 * Processes change password form submission.
1681 *
1682 * @since 1.0.0
1683 * @package userswp
1684 *
1685 */
1686 public function process_change() {
1687
1688 $data = $_POST;
1689
1690 if ( ! isset( $data['uwp_change_nonce'] ) || ! wp_verify_nonce( $data['uwp_change_nonce'], 'uwp-change-nonce' ) ) {
1691 return;
1692 }
1693
1694 global $uwp_notices;
1695
1696 if ( is_uwp_account_page() ) {
1697 $notice_type = 'account';
1698 } else {
1699 $notice_type = 'change';
1700 }
1701
1702 do_action( 'uwp_before_validate', 'change' );
1703
1704 $result = uwp_validate_fields( $data, 'change' );
1705
1706 $result = apply_filters( 'uwp_validate_result', $result, 'change', $data );
1707
1708 if ( is_wp_error( $result ) ) {
1709 $message = aui()->alert( array(
1710 'type' => 'error',
1711 'content' => $result->get_error_message()
1712 )
1713 );
1714 $uwp_notices[] = array( $notice_type => $message );
1715
1716 return;
1717 }
1718
1719 do_action( 'uwp_after_validate', 'change' );
1720
1721 $user_data = get_user_by( 'id', get_current_user_id() );
1722
1723 if ( ! $user_data ) {
1724 $message = aui()->alert( array(
1725 'type' => 'error',
1726 'content' => $user_data->get_error_message()
1727 )
1728 );
1729 $uwp_notices[] = array( $notice_type => $message );
1730
1731 return;
1732 }
1733
1734 $email_vars = array(
1735 'user_id' => $user_data->ID,
1736 );
1737
1738 UsersWP_Mails::send( $user_data->user_email, 'change_password', $email_vars );
1739
1740 wp_set_password( $result['password'], $user_data->ID );
1741
1742 $password_nag = get_user_option( 'default_password_nag', $user_data->ID );
1743 if ( $password_nag ) {
1744 delete_user_meta( $user_data->ID, 'default_password_nag' );
1745 }
1746
1747 $message = aui()->alert( array(
1748 'type' => 'success',
1749 'content' => apply_filters( 'uwp_change_password_success_message', __( 'Password changed successfully.', 'userswp' ), $data )
1750 )
1751 );
1752
1753 $uwp_notices[] = array( $notice_type => $message );
1754
1755 do_action( 'uwp_after_process_change', $data );
1756
1757 wp_logout();
1758 exit();
1759 }
1760
1761 /**
1762 * Processes reset password form submission.
1763 *
1764 * @since 1.0.0
1765 * @package userswp
1766 *
1767 */
1768 public function process_reset() {
1769
1770 $data = $_POST;
1771
1772 if ( isset( $data['uwp_reset_hp'] ) && '' != $data['uwp_reset_hp'] ) {
1773 wp_die( __( 'No spam please!', 'userswp' ) );
1774 }
1775
1776 if ( ! isset( $data['uwp_reset_nonce'] ) || ! wp_verify_nonce( $data['uwp_reset_nonce'], 'uwp-reset-nonce' ) ) {
1777 return;
1778 }
1779
1780 global $uwp_notices;
1781
1782 do_action( 'uwp_before_validate', 'reset' );
1783
1784 $result = uwp_validate_fields( $data, 'reset' );
1785
1786 $result = apply_filters( 'uwp_validate_result', $result, 'reset', $data );
1787
1788 if ( is_wp_error( $result ) ) {
1789 $message = aui()->alert( array(
1790 'type' => 'error',
1791 'content' => $result->get_error_message()
1792 )
1793 );
1794 $uwp_notices[] = array( 'reset' => $message );
1795
1796 return;
1797 }
1798
1799 do_action( 'uwp_after_validate', 'reset' );
1800
1801 $login = sanitize_text_field( $data['uwp_reset_username'] );
1802 $key = sanitize_text_field( $data['uwp_reset_key'] );
1803
1804 $user = get_user_by( 'login', $login );
1805 if ( ! $user ) {
1806 $message = aui()->alert( array(
1807 'type' => 'error',
1808 'content' => __( 'Invalid username.', 'userswp' )
1809 )
1810 );
1811 $uwp_notices[] = array( 'reset' => $message );
1812
1813 return;
1814 }
1815
1816 clean_user_cache( $user );
1817
1818 $user_data = check_password_reset_key( $key, $login );
1819
1820 if ( is_wp_error( $user_data ) ) {
1821 $message = aui()->alert( array(
1822 'type' => 'error',
1823 'content' => $user_data->get_error_message()
1824 )
1825 );
1826 $uwp_notices[] = array( 'reset' => $message );
1827
1828 return;
1829 }
1830
1831 $email_vars = array(
1832 'user_id' => $user_data->ID,
1833 );
1834
1835 UsersWP_Mails::send( $user_data->user_email, 'reset_password', $email_vars );
1836
1837 wp_set_password( $data['password'], $user_data->ID );
1838
1839 $login_page_url = uwp_get_login_page_url();
1840 $message = sprintf( __( 'Password updated successfully. Please <a href="%s">login</a> with your new password.', 'userswp' ), $login_page_url );
1841 $message = apply_filters( 'uwp_reset_password_success_message', $message, $data );
1842 $message = aui()->alert( array(
1843 'type' => 'success',
1844 'content' => $message
1845 )
1846 );
1847 $uwp_notices[] = array( 'reset' => $message );
1848
1849 do_action( 'uwp_after_process_reset', $data );
1850 }
1851
1852 /**
1853 * Processes account form submission.
1854 *
1855 * @since 1.0.0
1856 * @package userswp
1857 *
1858 */
1859 public function process_account() {
1860
1861 $data = wp_unslash( $_POST );
1862 $files = $_FILES;
1863
1864 if ( ! isset( $data['uwp_account_nonce'] ) || ! wp_verify_nonce( $data['uwp_account_nonce'], 'uwp-account-nonce' ) ) {
1865 return;
1866 }
1867
1868 if ( ! is_user_logged_in() ) {
1869 return;
1870 }
1871
1872 global $uwp_notices;
1873 $file_obj = new UsersWP_Files();
1874
1875 do_action( 'uwp_before_validate', 'account' );
1876
1877 $result = uwp_validate_fields( $data, 'account' );
1878
1879 $result = apply_filters( 'uwp_validate_result', $result, 'account', $data );
1880
1881 if ( is_wp_error( $result ) ) {
1882 $message = aui()->alert( array(
1883 'type' => 'error',
1884 'content' => $result->get_error_message()
1885 )
1886 );
1887 $uwp_notices[] = array( 'account' => $message );
1888
1889 return;
1890 }
1891
1892 $uploads_result = $file_obj->validate_uploads( $files, 'account' );
1893
1894 if ( is_wp_error( $uploads_result ) ) {
1895 $message = aui()->alert( array(
1896 'type' => 'error',
1897 'content' => $uploads_result->get_error_message()
1898 )
1899 );
1900 $uwp_notices[] = array( 'account' => $message );
1901
1902 return;
1903 }
1904
1905 do_action( 'uwp_after_validate', 'account' );
1906
1907 //unset if value is empty for files
1908 foreach ( $uploads_result as $upload_file_key => $upload_file_value ) {
1909 if ( empty( $upload_file_value ) ) {
1910 unset( $uploads_result[ $upload_file_key ] );
1911 }
1912 }
1913
1914 $result = array_merge( $result, $uploads_result );
1915
1916
1917 $args = array(
1918 'ID' => get_current_user_id()
1919 );
1920
1921 if ( isset( $result['first_name'] ) && isset( $result['last_name'] ) ) {
1922 $args['display_name'] = $result['first_name'] . ' ' . $result['last_name'];
1923 }
1924
1925 if ( isset( $result['first_name'] ) ) {
1926 $args['first_name'] = $result['first_name'];
1927 }
1928
1929 if ( isset( $result['last_name'] ) ) {
1930 $args['last_name'] = $result['last_name'];
1931 }
1932
1933 if ( isset( $result['user_url'] ) ) {
1934 $args['user_url'] = $result['user_url'];
1935 }
1936
1937 if ( isset( $result['display_name'] ) && ! empty( $result['display_name'] ) ) {
1938 $args['display_name'] = $result['display_name'];
1939 }
1940
1941 if ( isset( $result['password'] ) ) {
1942 $args['user_pass'] = $result['password'];
1943 }
1944
1945 $user_id = wp_update_user( $args );
1946
1947 if ( is_wp_error( $user_id ) ) {
1948 $message = aui()->alert( array(
1949 'type' => 'error',
1950 'content' => sprintf( __( '%s', 'userswp' ), $user_id->get_error_message() )
1951 )
1952 );
1953 $uwp_notices[] = array( 'account' => $message );
1954
1955 return;
1956 }
1957
1958 $res = $this->save_user_extra_fields( $user_id, $result, 'account' );
1959
1960 if ( ! $res ) {
1961 $message = aui()->alert( array(
1962 'type' => 'error',
1963 'content' => __( 'Something went wrong. Please contact site admin.', 'userswp' )
1964 )
1965 );
1966 $uwp_notices[] = array( 'account' => $message );
1967
1968 return;
1969 }
1970
1971 //updating bio field after saving extra fields to reflect the points in mycred add on.
1972 if ( isset( $result['bio'] ) && ! empty( $result['bio'] ) ) {
1973 $args = array(
1974 'ID' => $user_id,
1975 'description' => $result['bio'],
1976 );
1977 wp_update_user( $args );
1978 }
1979
1980 $user_data = get_userdata( $user_id );
1981
1982 $form_fields = apply_filters( 'uwp_send_mail_form_fields', "", 'account', $user_id );
1983
1984 if ( isset( $result['email'] ) && $user_data->user_email !== trim($result['email']) ) {
1985
1986 $hash = md5( $result['email'] . time() . wp_rand() );
1987 $new_admin_email = array(
1988 'hash' => $hash,
1989 'newemail' => $result['email'],
1990 );
1991
1992 update_user_meta(get_current_user_id(), 'uwp_update_email_hash', $new_admin_email);
1993
1994 $new_email_link = add_query_arg(
1995 array(
1996 'uwp_new_email' => 'yes',
1997 'key' => $hash,
1998 'login' => $user_data->user_login
1999 ),
2000 uwp_get_account_page_url()
2001 );
2002
2003 $email_vars = array(
2004 'user_id' => $user_id,
2005 'new_email' => $result['email'],
2006 'new_email_link' => esc_url( $new_email_link ),
2007 );
2008
2009 UsersWP_Mails::send( $user_data->user_email, 'account_new_email_activation', $email_vars );
2010
2011 $message = apply_filters( 'uwp_account_pending_new_email_activation_message', __( 'Account updated successfully. The new address will become active once you confirm via activation link sent to your new email.', 'userswp' ), $data );
2012 $message = aui()->alert( array(
2013 'type' => 'success',
2014 'content' => $message
2015 )
2016 );
2017
2018 $uwp_notices[] = array( 'account' => $message );
2019
2020 } else {
2021 $email_vars = array(
2022 'user_id' => $user_id,
2023 'form_fields' => $form_fields,
2024 );
2025
2026 UsersWP_Mails::send( $user_data->user_email, 'account_update', $email_vars );
2027
2028 $message = apply_filters( 'uwp_account_update_success_message', __( 'Account updated successfully.', 'userswp' ), $data );
2029 $message = aui()->alert( array(
2030 'type' => 'success',
2031 'content' => $message
2032 )
2033 );
2034
2035 $uwp_notices[] = array( 'account' => $message );
2036 }
2037
2038 do_action( 'uwp_after_process_account', $data );
2039
2040 }
2041
2042 /**
2043 * Modifies the forms field in email based on the form type.
2044 *
2045 * @param string $form_fields Form fields.
2046 * @param string $type Form type.
2047 * @param int $user_id User ID.
2048 *
2049 * @return string Modified mail field.
2050 * @package userswp
2051 * @subpackage userswp/includes
2052 *
2053 */
2054 public function init_mail_form_fields( $form_fields, $type, $user_id ) {
2055 switch ( $type ) {
2056 case "register":
2057 $form_id = get_user_meta( $user_id, '_uwp_register_form_id', true );
2058 $fields = get_register_form_fields($form_id);
2059 $user_data = get_userdata( $user_id );
2060 if ( ! empty( $fields ) && is_array( $fields ) ) {
2061 $form_fields = '<p><b>' . __( 'User Information:', 'userswp' ) . '</b></p>';
2062 $excluded = uwp_get_excluded_fields();
2063 foreach ( $fields as $key => $field ) {
2064 if ( $field->is_active != '1' || in_array( $field->htmlvar_name, $excluded ) ) {
2065 continue;
2066 }
2067 if ( $field->htmlvar_name == 'email' && isset( $user_data->user_email ) ) {
2068 $field_value = $user_data->user_email;
2069 } elseif ( $field->htmlvar_name == 'display_name' && isset( $user_data->user_login ) ) {
2070 $field_value = $user_data->user_login;
2071 } elseif ( $field->htmlvar_name == 'bio' ) {
2072 $field_value = get_user_meta( $user_id, 'description', true );
2073 } else {
2074 $field_value = uwp_get_usermeta( $user_id, $field->htmlvar_name );
2075 }
2076
2077 if ( is_array( $field_value ) && count( $field_value ) > 0 ) {
2078 $field_value = uwp_maybe_serialize( $field->htmlvar_name, $field_value );
2079 }
2080
2081 if ( isset( $field->site_title ) && ! empty( $field_value ) ) {
2082 $form_fields .= '<p><b>' . __( $field->site_title, 'userswp' ) . '</b>:&nbsp;' . $field_value . '</p>';
2083 }
2084 }
2085 }
2086 break;
2087 case "account":
2088 $fields = get_account_form_fields();
2089 $user_data = get_userdata( $user_id );
2090 if ( ! empty( $fields ) && is_array( $fields ) ) {
2091 $form_fields = '<p><b>' . __( 'User Information:', 'userswp' ) . '</b></p>';
2092 foreach ( $fields as $key => $field ) {
2093 if ( $field->is_active != '1' ) {
2094 continue;
2095 }
2096 if ( $field->htmlvar_name == 'email' && isset( $user_data->user_email ) ) {
2097 $field_value = $user_data->user_email;
2098 } elseif ( $field->htmlvar_name == 'display_name' && isset( $user_data->user_login ) ) {
2099 $field_value = $user_data->user_login;
2100 } elseif ( $field->htmlvar_name == 'bio' ) {
2101 $field_value = get_user_meta( $user_id, 'description', true );
2102 } else {
2103 $field_value = uwp_get_usermeta( $user_id, $field->htmlvar_name );
2104 }
2105
2106 if ( is_array( $field_value ) && count( $field_value ) > 0 ) {
2107 $field_value = uwp_maybe_serialize( $field->htmlvar_name, $field_value );
2108 }
2109
2110 if ( isset( $field->site_title ) && ! empty( $field_value ) ) {
2111 $form_fields .= '<p><b>' . __( $field->site_title, 'userswp' ) . '</b>:&nbsp;' . $field_value . '</p>';
2112 }
2113 }
2114 }
2115 break;
2116 }
2117
2118 return apply_filters( 'uwp_mail_form_fields', $form_fields, $type, $user_id );
2119 }
2120
2121 /**
2122 *
2123 *
2124 * @return void
2125 * @since 1.0.12 Unlink file.
2126 * @package userswp
2127 * @since 1.0.0
2128 */
2129 public function upload_file_remove() {
2130
2131 $htmlvar = strip_tags( esc_sql( $_POST['htmlvar'] ) );
2132 $user_id = (int) strip_tags( esc_sql( $_POST['uid'] ) );
2133 $permission = false;
2134 if ( $user_id == get_current_user_id() ) {
2135 $permission = true;
2136 } else {
2137 if ( current_user_can( 'manage_options' ) ) {
2138 $permission = true;
2139 }
2140 }
2141 if ( $permission ) {
2142 // Remove file
2143 if ( $htmlvar == "banner_thumb" ) {
2144 $file = uwp_get_usermeta( $user_id, 'banner_thumb' );
2145 $type = 'banner';
2146 } elseif ( $htmlvar == "avatar_thumb" ) {
2147 $file = uwp_get_usermeta( $user_id, 'avatar_thumb' );
2148 $type = 'avatar';
2149 } else {
2150 $file = '';
2151 $type = '';
2152 }
2153
2154 uwp_update_usermeta( $user_id, $htmlvar, '' );
2155
2156 if ( $file ) {
2157 $uploads = wp_upload_dir();
2158 $upload_path = $uploads['basedir'];
2159 $unlink_file = untrailingslashit( $upload_path ) . '/' . ltrim( $file, '/' );
2160
2161 if ( is_file( $unlink_file ) && file_exists( $unlink_file ) ) {
2162 @unlink( $unlink_file );
2163 $unlink_ori_file = str_replace( '_uwp_' . $type . '_thumb' . '.', '.', $unlink_file );
2164 if ( is_file( $unlink_ori_file ) && file_exists( $unlink_ori_file ) ) {
2165 @unlink( $unlink_ori_file );
2166 }
2167 }
2168 }
2169 }
2170 die();
2171 }
2172
2173 /**
2174 * Form field template for datepicker field type.
2175 *
2176 * @param string $html Form field html
2177 * @param object $field Field info.
2178 * @param string $value Form field default value.
2179 * @param string $form_type Form type
2180 *
2181 * @return string Modified form field html.
2182 * @package userswp
2183 *
2184 * @since 1.0.0
2185 */
2186 public function form_input_datepicker( $html, $field, $value, $form_type ) {
2187
2188 // Check if there is a field specific filter.
2189 if ( has_filter( "uwp_form_input_html_datepicker_{$field->htmlvar_name}" ) ) {
2190 $html = apply_filters( "uwp_form_input_html_datepicker_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2191 }
2192
2193 // If no html then we run the standard output.
2194 if ( empty( $html ) ) {
2195
2196 $design_style = uwp_get_option( "design_style", "bootstrap" );
2197 $bs_form_group = $design_style ? "form-group" : "";
2198 $bs_sr_only = $design_style ? "sr-only" : "";
2199 $bs_form_control = $design_style ? "form-control" : "";
2200 $extra_attributes = array();
2201 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
2202 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
2203
2204 ob_start(); // Start buffering;
2205
2206 $extra_fields = unserialize( $field->extra_fields );
2207
2208 if ( $extra_fields['date_format'] == '' ) {
2209 $extra_fields['date_format'] = 'yy-mm-dd';
2210 }
2211
2212 $date_format = $extra_fields['date_format'];
2213 $jquery_date_format = $date_format;
2214
2215
2216 // check if we need to change the format or not
2217 $date_format_len = strlen( str_replace( ' ', '', $date_format ) );
2218 if ( $date_format_len > 5 ) {// if greater then 5 then it's the old style format.
2219
2220 $search = array( 'dd', 'd', 'DD', 'mm', 'm', 'MM', 'yy' ); //jQuery UI datepicker format
2221 $replace = array( 'd', 'j', 'l', 'm', 'n', 'F', 'Y' );//PHP date format
2222
2223 $date_format = str_replace( $search, $replace, $date_format );
2224 } else {
2225 $jquery_date_format = uwp_date_format_php_to_jqueryui( $jquery_date_format );
2226 }
2227
2228 if ( ! empty( $value ) && ! is_string( $value ) ) {
2229 $value = date( 'Y-m-d', $value );
2230 }
2231
2232 if ( $value == '0000-00-00' ) {
2233 $value = '';
2234 }//if date not set, then mark it empty
2235 $value = uwp_date( $value, 'Y-m-d', $date_format );
2236 $site_title = uwp_get_form_label( $field );
2237
2238 // bootstrap
2239 if ( $design_style ) {
2240 // flatpickr attributes
2241 $extra_attributes['data-alt-input'] = 'true';
2242 $extra_attributes['data-alt-format'] = $date_format;
2243 $extra_attributes['data-date-format'] = 'Y-m-d';
2244
2245 if ( 'dob' == $field->htmlvar_name ) {
2246 $extra_attributes['data-max-date'] = 'today';
2247 }
2248
2249 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
2250
2251 echo aui()->input(
2252 array(
2253 'id' => $field->htmlvar_name,
2254 'name' => $field->htmlvar_name,
2255 'required' => ! empty( $field->is_required ) ? true : false,
2256 'label' => $site_title . $required,
2257 'label_show' => true,
2258 'label_type' => 'hidden',
2259 'type' => 'datepicker',
2260 'title' => $site_title,
2261 'placeholder' => uwp_get_field_placeholder( $field ),
2262 'class' => '',
2263 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
2264 'value' => $value,
2265 'help_text' => uwp_get_field_description( $field ),
2266 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
2267 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
2268 'extra_attributes' => $extra_attributes
2269 )
2270 );
2271 } else {
2272 ?>
2273 <script type="text/javascript">
2274
2275 jQuery(function () {
2276
2277 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker({
2278 changeMonth: true, changeYear: true
2279 <?php if ( $field->htmlvar_name == 'dob' ) {
2280 echo ", yearRange: '1900:+0'";
2281 } else {
2282 echo ", yearRange: '1900:2050'";
2283 }?>
2284 <?php echo apply_filters( "uwp_datepicker_extra_{$field->htmlvar_name}", '' );?>});
2285
2286 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker("option", "dateFormat", '<?php echo $jquery_date_format;?>');
2287
2288 <?php if(! empty( $value )){?>
2289 var parsedDate = jQuery.datepicker.parseDate('yy-mm-dd', '<?php echo $value;?>');
2290 jQuery("#<?php echo $field->htmlvar_name;?>").datepicker("setDate", parsedDate);
2291 <?php } ?>
2292
2293 });
2294
2295 </script>
2296 <div id="<?php echo $field->htmlvar_name; ?>_row"
2297 class="<?php if ( $field->is_required ) {
2298 echo 'required_field';
2299 } ?> clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2300
2301 <?php
2302
2303 if ( ! is_admin() ) { ?>
2304 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2305 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
2306 <?php if ( $field->is_required ) {
2307 echo '<span>*</span>';
2308 } ?>
2309 </label>
2310 <?php } ?>
2311
2312 <input name="<?php echo $field->htmlvar_name; ?>"
2313 id="<?php echo $field->htmlvar_name; ?>"
2314 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
2315 title="<?php echo $site_title; ?>"
2316 type="text"
2317 <?php if ( $field->is_required == 1 ) {
2318 echo 'required="required"';
2319 } ?>
2320 value="<?php echo esc_attr( $value ); ?>"
2321 class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"/>
2322
2323 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
2324 <?php if ( $field->is_required ) { ?>
2325 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
2326 <?php } ?>
2327 </div>
2328
2329 <?php
2330 }
2331
2332 $html = ob_get_clean();
2333 }
2334
2335 return $html;
2336 }
2337
2338 /**
2339 * Form field template for time field type.
2340 *
2341 * @param string $html Form field html
2342 * @param object $field Field info.
2343 * @param string $value Form field default value.
2344 * @param string $form_type Form type
2345 *
2346 * @return string Modified form field html.
2347 * @package userswp
2348 *
2349 * @since 1.0.0
2350 */
2351 public function form_input_time( $html, $field, $value, $form_type ) {
2352
2353 if ( has_filter( "uwp_form_input_html_time_{$field->htmlvar_name}" ) ) {
2354
2355 $html = apply_filters( "uwp_form_input_html_time_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2356 }
2357
2358 // If no html then we run the standard output.
2359 if ( empty( $html ) ) {
2360
2361 $design_style = uwp_get_option( "design_style", "bootstrap" );
2362 $bs_form_group = $design_style ? "form-group" : "";
2363 $bs_sr_only = $design_style ? "sr-only" : "";
2364 $bs_form_control = $design_style ? "form-control bg-white" : "";
2365 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
2366 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
2367
2368 ob_start(); // Start buffering;
2369
2370 if ( $value != '' ) {
2371 $value = date( 'H:i', strtotime( $value ) );
2372 }
2373
2374 // flatpickr attributes
2375 $extra_attributes['data-enable-time'] = 'true';
2376 $extra_attributes['data-no-calendar'] = 'true';
2377 $extra_attributes['data-date-format'] = 'H:i';
2378 $site_title = uwp_get_form_label( $field );
2379 $label_type = is_admin() ? '' : 'top';
2380
2381 if ( $design_style ) {
2382 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
2383
2384 echo aui()->input(
2385 array(
2386 'id' => $field->htmlvar_name,
2387 'name' => $field->htmlvar_name,
2388 'required' => ! empty( $field->is_required ) ? true : false,
2389 'label' => $site_title . $required,
2390 'label_show' => true,
2391 'label_type' => $label_type,
2392 'type' => 'timepicker',
2393 'title' => $site_title,
2394 'placeholder' => uwp_get_field_placeholder( $field ),
2395 'class' => '',
2396 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
2397 'value' => $value,
2398 'help_text' => uwp_get_field_description( $field ),
2399 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
2400 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
2401 'extra_attributes' => $extra_attributes,
2402 'input_group_right' => '<div class="input-group-text px-2 bg-transparent border-0x" onclick="jQuery(this).parent().parent().find(\'input\').val(\'\');"><i class="fas fa-times uwp-search-input-label-clear text-muted c-pointer" title="' . __( 'Clear field', 'uwp-search' ) . '" ></i></div>',
2403 )
2404 );
2405 } else {
2406 ?>
2407 <script type="text/javascript">
2408 jQuery(document).ready(function () {
2409
2410 jQuery('#<?php echo $field->htmlvar_name;?>').timepicker({
2411 showPeriod: true,
2412 showLeadingZero: true
2413 });
2414 });
2415 </script>
2416 <div id="<?php echo $field->htmlvar_name; ?>_row"
2417 class="<?php if ( $field->is_required ) {
2418 echo 'required_field';
2419 } ?> clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2420
2421 <?php
2422 $site_title = uwp_get_form_label( $field );
2423 if ( ! is_admin() ) { ?>
2424 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2425 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
2426 <?php if ( $field->is_required ) {
2427 echo '<span>*</span>';
2428 } ?>
2429 </label>
2430 <?php } ?>
2431
2432 <input readonly="readonly" name="<?php echo $field->htmlvar_name; ?>"
2433 id="<?php echo $field->htmlvar_name; ?>"
2434 value="<?php echo esc_attr( $value ); ?>"
2435 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
2436 type="text"
2437 class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"/>
2438
2439 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
2440 <?php if ( $field->is_required ) { ?>
2441 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
2442 <?php } ?>
2443 </div>
2444 <?php
2445 }
2446 $html = ob_get_clean();
2447 }
2448
2449 return $html;
2450 }
2451
2452 /**
2453 * Form field template for select field type.
2454 *
2455 * @param string $html Form field html
2456 * @param object $field Field info.
2457 * @param string $value Form field default value.
2458 * @param string $form_type Form type
2459 *
2460 * @return string Modified form field html.
2461 * @package userswp
2462 *
2463 * @since 1.0.0
2464 */
2465 public function form_input_select( $html, $field, $value, $form_type ) {
2466
2467 // Check if there is a field specific filter.
2468 if ( has_filter( "uwp_form_input_html_select_{$field->htmlvar_name}" ) ) {
2469 $html = apply_filters( "uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2470 }
2471
2472 // Check if there is a field type specific filter.
2473 if ( has_filter( "uwp_form_input_html_select_{$field->field_type_key}" ) ) {
2474 $html = apply_filters( "uwp_form_input_html_select_{$field->field_type_key}", $html, $field, $value, $form_type );
2475 }
2476
2477 // If no html then we run the standard output.
2478 if ( empty( $html ) ) {
2479
2480 $design_style = uwp_get_option( "design_style", "bootstrap" );
2481 $bs_form_group = $design_style ? "form-group" : "";
2482 $bs_sr_only = $design_style ? "sr-only" : "";
2483 $bs_form_control = $design_style ? "form-control" : "";
2484 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
2485 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
2486
2487 ob_start(); // Start buffering;
2488 $option_values_arr = uwp_string_values_to_options( $field->option_values, true );
2489 $site_title = uwp_get_form_label( $field );
2490
2491 // bootstrap
2492 if ( $design_style ) {
2493
2494 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
2495
2496 echo aui()->select( array(
2497 'id' => $field->htmlvar_name,
2498 'name' => $field->htmlvar_name,
2499 'placeholder' => uwp_get_field_placeholder( $field ),
2500 'title' => $site_title,
2501 'value' => $value,
2502 'required' => $field->is_required,
2503 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
2504 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
2505 'help_text' => uwp_get_field_description( $field ),
2506 'label' => $site_title . $required,
2507 'options' => $option_values_arr,
2508 'select2' => true,
2509 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
2510 ) );
2511 } else {
2512 ?>
2513 <div id="<?php echo $field->htmlvar_name; ?>_row"
2514 class="<?php if ( $field->is_required ) {
2515 echo 'required_field';
2516 } ?> uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2517
2518 <?php
2519 if ( ! is_admin() ) { ?>
2520 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2521 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
2522 <?php if ( $field->is_required ) {
2523 echo '<span>*</span>';
2524 } ?>
2525 </label>
2526 <?php } ?>
2527
2528 <?php
2529
2530 $select_options = '';
2531 if ( ! empty( $option_values_arr ) ) {
2532 foreach ( $option_values_arr as $option_row ) {
2533 if ( isset( $option_row['optgroup'] ) && ( $option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end' ) ) {
2534 $option_label = isset( $option_row['label'] ) ? $option_row['label'] : '';
2535
2536 $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
2537 } else {
2538 $option_label = isset( $option_row['label'] ) ? $option_row['label'] : '';
2539 $option_value = isset( $option_row['value'] ) ? $option_row['value'] : '';
2540 $selected = $option_value == $value ? 'selected="selected"' : '';
2541
2542 $select_options .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . '>' . $option_label . '</option>';
2543 }
2544 }
2545 }
2546 ?>
2547 <select name="<?php echo $field->htmlvar_name; ?>" id="<?php echo $field->htmlvar_name; ?>"
2548 class="uwp_textfield aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
2549 title="<?php echo $site_title; ?>"
2550 data-placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
2551 ><?php echo $select_options; ?>
2552 </select>
2553 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
2554 <?php if ( $field->is_required ) { ?>
2555 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
2556 <?php } ?>
2557 </div>
2558
2559 <?php
2560 }
2561 $html = ob_get_clean();
2562 }
2563
2564 return $html;
2565 }
2566
2567 /**
2568 * Form field template for multiselect field type.
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 * @package userswp
2577 *
2578 * @since 1.0.0
2579 */
2580 public function form_input_multiselect( $html, $field, $value, $form_type ) {
2581
2582 // Check if there is a field specific filter.
2583 if ( has_filter( "uwp_form_input_html_multiselect_{$field->htmlvar_name}" ) ) {
2584 $html = apply_filters( "uwp_form_input_html_multiselect_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2585 }
2586
2587 if ( empty( $html ) ) {
2588
2589 $design_style = uwp_get_option( "design_style", "bootstrap" );
2590 $bs_form_group = $design_style ? "form-group" : "";
2591 $bs_sr_only = $design_style ? "sr-only" : "";
2592 $bs_form_control = $design_style ? "form-control" : "";
2593 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
2594 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
2595
2596 ob_start(); // Start buffering;
2597
2598 $multi_display = 'select';
2599 if ( ! empty( $field->extra_fields ) ) {
2600 $multi_display = unserialize( $field->extra_fields );
2601 }
2602
2603 $option_values_arr = uwp_string_values_to_options( $field->option_values, true );
2604 $site_title = uwp_get_form_label( $field );
2605 // bootstrap
2606 if ( $design_style ) {
2607
2608 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
2609
2610 echo aui()->select( array(
2611 'id' => $field->htmlvar_name,
2612 'name' => $field->htmlvar_name,
2613 'placeholder' => uwp_get_field_placeholder( $field ),
2614 'title' => $site_title,
2615 'value' => $value,
2616 'required' => $field->is_required,
2617 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
2618 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
2619 'help_text' => uwp_get_field_description( $field ),
2620 'label' => $site_title . $required,
2621 'options' => $option_values_arr,
2622 'select2' => true,
2623 'multiple' => true,
2624 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
2625 ) );
2626 } else {
2627 ?>
2628 <div id="<?php echo $field->htmlvar_name; ?>_row"
2629 class="<?php if ( $field->is_required ) {
2630 echo 'required_field';
2631 } ?> uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2632
2633 <?php
2634 if ( ! is_admin() ) { ?>
2635 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2636 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
2637 <?php if ( $field->is_required ) {
2638 echo '<span>*</span>';
2639 } ?>
2640 </label>
2641 <?php } ?>
2642
2643 <input type="hidden" name="<?php echo $field->htmlvar_name; ?>" value=""/>
2644 <?php if ( $multi_display == 'select' ) { ?>
2645 <div class="uwp_multiselect_list">
2646 <select name="<?php echo $field->htmlvar_name; ?>[]"
2647 id="<?php echo $field->htmlvar_name; ?>"
2648 title="<?php echo $site_title; ?>"
2649 data-placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
2650 class="aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
2651 >
2652 <?php
2653 } else {
2654 ?>
2655 <ul class="uwp_multi_choice">
2656 <?php
2657 }
2658
2659 $option_values_arr = uwp_string_values_to_options( $field->option_values, true );
2660 $select_options = '';
2661 if ( ! empty( $option_values_arr ) ) {
2662 foreach ( $option_values_arr as $option_row ) {
2663 if ( isset( $option_row['optgroup'] ) && ( $option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end' ) ) {
2664 $option_label = isset( $option_row['label'] ) ? $option_row['label'] : '';
2665
2666 if ( $multi_display == 'select' ) {
2667 $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
2668 } else {
2669 $select_options .= $option_row['optgroup'] == 'start' ? '<li>' . $option_label . '</li>' : '';
2670 }
2671 } else {
2672 $option_label = isset( $option_row['label'] ) ? $option_row['label'] : '';
2673 $option_value = isset( $option_row['value'] ) ? $option_row['value'] : '';
2674 $selected = $option_value == $value ? 'selected="selected"' : '';
2675 $checked = '';
2676
2677 if ( ( ! is_array( $value ) && trim( $value ) != '' ) || ( is_array( $value ) && ! empty( $value ) ) ) {
2678 if ( ! is_array( $value ) ) {
2679 $value_array = explode( ',', $value );
2680 } else {
2681 $value_array = $value;
2682 }
2683
2684 if ( is_array( $value_array ) ) {
2685 if ( in_array( $option_value, $value_array ) ) {
2686 $selected = 'selected="selected"';
2687 $checked = 'checked="checked"';
2688 }
2689 }
2690 }
2691
2692 if ( $multi_display == 'select' ) {
2693 $select_options .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . '>' . $option_label . '</option>';
2694 } else {
2695 $select_options .= '<li><input name="' . $field->name . '[]" ' . $checked . ' value="' . esc_attr( $option_value ) . '" class="uwp-' . $multi_display . '" type="' . $multi_display . '" />&nbsp;' . $option_label . ' </li>';
2696 }
2697 }
2698 }
2699 }
2700 echo $select_options;
2701
2702 if ( $multi_display == 'select' ) { ?></select></div>
2703 <?php } else { ?>
2704 </ul>
2705 <?php } ?>
2706 <?php if ( $field->is_required ) { ?>
2707 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
2708 <?php } ?>
2709 </div>
2710 <?php
2711 }
2712 $html = ob_get_clean();
2713 }
2714
2715 return $html;
2716 }
2717
2718 /**
2719 * Form field template for file field type.
2720 *
2721 * @param string $html Form field html
2722 * @param object $field Field info.
2723 * @param string $value Form field default value.
2724 * @param string $form_type Form type
2725 *
2726 * @return string Modified form field html.
2727 * @package userswp
2728 *
2729 * @since 1.0.0
2730 */
2731 public function form_input_file( $html, $field, $value, $form_type ) {
2732
2733 $file_obj = new UsersWP_Files();
2734
2735 // Check if there is a field specific filter.
2736 if ( has_filter( "uwp_form_input_html_file_{$field->htmlvar_name}" ) ) {
2737 $html = apply_filters( "uwp_form_input_html_file_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2738 }
2739
2740 // If no html then we run the standard output.
2741 if ( empty( $html ) ) {
2742
2743 $design_style = uwp_get_option( "design_style", "bootstrap" );
2744 $wrap_class = isset( $field->css_class ) ? $field->css_class : '';
2745 $bs_form_group = $design_style ? "form-group" : "";
2746 $bs_sr_only = $design_style ? "sr-only" : "";
2747 $bs_form_control = $design_style ? "form-control" : "";
2748
2749 ob_start(); // Start buffering;
2750
2751 ?>
2752 <div id="<?php echo $field->htmlvar_name; ?>_row"
2753 class="<?php if ( $field->is_required ) {
2754 echo 'required_field';
2755 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group . $wrap_class ); ?>">
2756
2757 <?php
2758 $site_title = uwp_get_form_label( $field );
2759 if ( ! is_admin() && !wp_doing_ajax() ) { ?>
2760 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2761 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
2762 <?php if ( $field->is_required ) {
2763 echo ' <span class="text-danger">*</span>';
2764 } ?>
2765 </label>
2766 <?php } ?>
2767
2768 <?php echo $file_obj->file_upload_preview( $field, $value ); ?>
2769 <input name="<?php echo $field->htmlvar_name; ?>"
2770 class="<?php echo $field->css_class; ?> <?php echo esc_attr( $bs_form_control ); ?>"
2771 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
2772 title="<?php echo $site_title; ?>"
2773 <?php
2774 if ( $field->is_required == 1 ) {
2775 echo 'data-is-required="1"';
2776 }
2777 if ( $field->is_required == 1 && ! $value ) {
2778 echo 'required="required"';
2779 }
2780 ?>
2781 type="<?php echo $field->field_type; ?>">
2782 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
2783 <?php if ( $field->is_required ) { ?>
2784 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
2785 <?php } ?>
2786 </div>
2787
2788 <?php
2789 $html = ob_get_clean();
2790 }
2791
2792 return $html;
2793 }
2794
2795 /**
2796 * Form field template for checkbox field type.
2797 *
2798 * @param string $html Form field html
2799 * @param object $field Field info.
2800 * @param string $value Form field default value.
2801 * @param string $form_type Form type
2802 *
2803 * @return string Modified form field html.
2804 * @package userswp
2805 *
2806 * @since 1.0.0
2807 */
2808 public function form_input_checkbox( $html, $field, $value, $form_type ) {
2809
2810 // Check if there is a field specific filter.
2811 if ( has_filter( "uwp_form_input_html_checkbox_{$field->htmlvar_name}" ) ) {
2812 $html = apply_filters( "uwp_form_input_html_checkbox_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2813 }
2814
2815 // If no html then we run the standard output.
2816 if ( empty( $html ) ) {
2817
2818 $design_style = uwp_get_option( "design_style", "bootstrap" );
2819 $bs_form_group = $design_style ? "form-group form-check" : "";
2820 $bs_sr_only = $design_style ? "form-check-label" : "";
2821 $bs_form_control = $design_style ? "form-check-input" : "";
2822
2823 ob_start(); // Start buffering;
2824 $site_title = uwp_get_form_label( $field );
2825
2826 $design_style = uwp_get_option( "design_style", "bootstrap" );
2827 $id = wp_doing_ajax() ? $field->htmlvar_name . "_ajax" : $field->htmlvar_name;
2828
2829 $checked = $value == '1' ? true : false;
2830
2831 // bootstrap
2832 if ( $design_style ) {
2833 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
2834
2835 echo '<input type="hidden" name="' . $field->htmlvar_name . '" id="checkbox_' . $id . '" value="0"/>';
2836
2837 echo aui()->input(
2838 array(
2839 'id' => $id,
2840 'name' => $field->htmlvar_name,
2841 'type' => "checkbox",
2842 'value' => '1',
2843 'title' => $site_title,
2844 'label' => $site_title . $required,
2845 'label_show' => true,
2846 'required' => ! empty( $field->is_required ) ? true : false,
2847 'checked' => $checked,
2848 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
2849 'help_text' => uwp_get_field_description( $field ),
2850 'validation_text' => ! empty( $field->is_required ) ? __( $field->required_msg, 'userswp' ) : '',
2851 )
2852 );
2853
2854 } else {
2855 ?>
2856 <div id="<?php echo $field->htmlvar_name; ?>_row"
2857 class="<?php if ( $field->is_required ) {
2858 echo 'required_field';
2859 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2860 <?php if ( ! empty( $design_style ) ){ ?>
2861 <label class="<?php echo $bs_sr_only; ?>">
2862 <?php } ?>
2863 <input type="hidden" name="<?php echo $field->htmlvar_name; ?>" value="0"/>
2864 <input name="<?php echo $field->htmlvar_name; ?>"
2865 class="<?php echo $field->css_class; ?> <?php echo esc_attr( $bs_form_control ); ?>"
2866 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
2867 title="<?php echo $site_title; ?>"
2868 <?php if ( $field->is_required == 1 ) {
2869 echo 'required="required"';
2870 } ?>
2871 <?php if ( $value == '1' ) {
2872 echo 'checked="checked"';
2873 } ?>
2874 type="<?php echo $field->field_type; ?>"
2875 value="1">
2876 <?php
2877 echo ( trim( $site_title ) ) ? $site_title : '&nbsp;';
2878 ?>
2879 <?php if ( ! empty( $design_style ) ){ ?>
2880 </label>
2881 <?php } ?>
2882 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
2883 <?php if ( $field->is_required ) { ?>
2884 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
2885 <?php } ?>
2886 </div>
2887
2888 <?php
2889
2890 }
2891
2892 $html = ob_get_clean();
2893
2894 }
2895
2896 return $html;
2897 }
2898
2899 /**
2900 * Form field template for radio field type.
2901 *
2902 * @param string $html Form field html
2903 * @param object $field Field info.
2904 * @param string $value Form field default value.
2905 * @param string $form_type Form type
2906 *
2907 * @return string Modified form field html.
2908 * @package userswp
2909 *
2910 * @since 1.0.0
2911 */
2912 public function form_input_radio( $html, $field, $value, $form_type ) {
2913
2914 // Check if there is a field specific filter.
2915 if ( has_filter( "uwp_form_input_html_radio_{$field->htmlvar_name}" ) ) {
2916 $html = apply_filters( "uwp_form_input_html_radio_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2917 }
2918
2919 // If no html then we run the standard output.
2920 if ( empty( $html ) ) {
2921
2922 $design_style = uwp_get_option( "design_style", "bootstrap" );
2923 $bs_form_group = $design_style ? "form-group form-check-inline" : "";
2924 $bs_sr_only = $design_style ? "sr-only" : "";
2925 $bs_label_class = $design_style ? "form-check-label" : "";
2926 $bs_form_control = $design_style ? "form-check-input" : "";
2927
2928 ob_start(); // Start buffering;
2929
2930 if ( $design_style ) {
2931
2932 $option_values_deep = uwp_string_values_to_options( $field->option_values, true );
2933 $option_values = array();
2934 if ( ! empty( $option_values_deep ) ) {
2935 foreach ( $option_values_deep as $option ) {
2936 $option_values[ $option['value'] ] = $option['label'];
2937 }
2938 }
2939
2940 $site_title = uwp_get_form_label( $field );
2941
2942 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
2943
2944 echo aui()->radio(
2945 array(
2946 'id' => $field->htmlvar_name,
2947 'name' => $field->htmlvar_name,
2948 'type' => "radio",
2949 'title' => $site_title,
2950 'label' => is_admin() && !wp_doing_ajax() ? '' : $site_title . $required,
2951 'label_type' => 'top',
2952 'class' => '',
2953 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
2954 'value' => $value,
2955 'options' => $option_values
2956 )
2957 );
2958
2959 } else {
2960
2961 ?>
2962 <div id="<?php echo $field->htmlvar_name; ?>_row"
2963 class="<?php if ( $field->is_required ) {
2964 echo 'required_field';
2965 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2966
2967 <?php
2968 $site_title = uwp_get_form_label( $field );
2969 if ( ! is_admin() ) { ?>
2970 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2971 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
2972 <?php if ( $field->is_required ) {
2973 echo '<span>*</span>';
2974 } ?>
2975 </label>
2976 <?php } ?>
2977
2978 <?php if ( $field->option_values ) {
2979 $option_values = uwp_string_values_to_options( $field->option_values, true );
2980
2981 if ( ! empty( $option_values ) ) {
2982 $count = 0;
2983 foreach ( $option_values as $option_value ) {
2984 if ( empty( $option_value['optgroup'] ) ) {
2985 $count ++;
2986 if ( $count == 1 ) {
2987 $class = "uwp-radio-first";
2988 } else {
2989 $class = "";
2990 }
2991 ?>
2992 <?php if ( ! empty( $design_style ) ) { ?>
2993 <label class="<?php echo $bs_label_class; ?>">
2994 <?php } else { ?>
2995 <span class="uwp-radios <?php echo $class; ?>">
2996 <?php } ?>
2997 <input name="<?php echo $field->htmlvar_name; ?>"
2998 id="<?php echo $field->htmlvar_name; ?>"
2999 title="<?php echo esc_attr( $option_value['label'] ); ?>"
3000 <?php checked( $value, $option_value['value'] ); ?>
3001 <?php if ( $field->is_required == 1 ) {
3002 echo 'required="required"';
3003 } ?>
3004 value="<?php echo esc_attr( $option_value['value'] ); ?>"
3005 class="uwp-radio <?php echo esc_attr( $bs_form_control ); ?>" type="radio"/>
3006 <?php echo $option_value['label']; ?>
3007 <?php if ( ! empty( $design_style ) ) { ?>
3008 </label>
3009 <?php } else { ?>
3010 </span>
3011 <?php
3012 }
3013 }
3014 }
3015 }
3016 }
3017 ?>
3018 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
3019 <?php if ( $field->is_required ) { ?>
3020 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
3021 <?php } ?>
3022 </div>
3023 <?php
3024 }
3025
3026 $html = ob_get_clean();
3027 }
3028
3029 return $html;
3030 }
3031
3032 /**
3033 * Form field template for text field type.
3034 *
3035 * @param string $html Form field html
3036 * @param object $field Field info.
3037 * @param string $value Form field default value.
3038 * @param string $form_type Form type
3039 *
3040 * @return string Modified form field html.
3041 * @package userswp
3042 *
3043 * @since 1.0.0
3044 */
3045 public function form_input_text( $html, $field, $value, $form_type ) {
3046
3047 // Check if there is a custom field specific filter.
3048 if ( has_filter( "uwp_form_input_text_{$field->htmlvar_name}" ) ) {
3049 $html = apply_filters( "uwp_form_input_text_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3050 }
3051
3052 // If no html then we run the standard output.
3053 if ( empty( $html ) ) {
3054
3055 ob_start(); // Start buffering;
3056
3057 $type = 'text';
3058 $step = false;
3059 //number and float validation $validation_pattern
3060 if ( isset( $field->data_type ) && $field->data_type == 'INT' ) {
3061 $type = 'number';
3062 } elseif ( isset( $field->data_type ) && $field->data_type == 'FLOAT' ) {
3063 $dp = $field->decimal_point;
3064 switch ( $dp ) {
3065 case "1":
3066 $step = "0.1";
3067 break;
3068 case "2":
3069 $step = "0.01";
3070 break;
3071 case "3":
3072 $step = "0.001";
3073 break;
3074 case "4":
3075 $step = "0.0001";
3076 break;
3077 case "5":
3078 $step = "0.00001";
3079 break;
3080 case "6":
3081 $step = "0.000001";
3082 break;
3083 case "7":
3084 $step = "0.0000001";
3085 break;
3086 case "8":
3087 $step = "0.00000001";
3088 break;
3089 case "9":
3090 $step = "0.000000001";
3091 break;
3092 case "10":
3093 $step = "0.0000000001";
3094 break;
3095 default:
3096 $step = "0.01";
3097 break;
3098 }
3099 $type = 'number';
3100 }
3101
3102
3103 $site_title = uwp_get_form_label( $field );
3104 $placeholder = uwp_get_field_placeholder( $field );
3105 $manual_label = apply_filters( 'uwp_login_username_label_manual', true );
3106 if ( $manual_label
3107 && isset( $field->form_type )
3108 && $field->form_type == 'login'
3109 && $field->htmlvar_name == 'username' ) {
3110 $site_title = __( "Username or Email", 'userswp' );
3111 $required = ! empty( $field->is_required ) ? ' *' : '';
3112 $placeholder = $site_title . $required;
3113 $placeholder = apply_filters( 'uwp_get_field_placeholder', stripslashes( $placeholder ), $field );
3114 }
3115
3116 $design_style = uwp_get_option( "design_style", "bootstrap" );
3117 $bs_form_group = $design_style ? "form-group" : "";
3118 $bs_sr_only = $design_style ? "sr-only" : "";
3119 $bs_form_control = $design_style ? "form-control" : "";
3120
3121 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
3122 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
3123
3124 // bootstrap
3125 if ( $design_style ) {
3126 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3127
3128 echo aui()->input( array(
3129 'type' => $type,
3130 'id' => $field->htmlvar_name,
3131 'name' => $field->htmlvar_name,
3132 'placeholder' => $placeholder,
3133 'title' => $site_title,
3134 'value' => wp_unslash( $value ),
3135 'required' => $field->is_required,
3136 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
3137 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
3138 'help_text' => uwp_get_field_description( $field ),
3139 'label' => is_admin() && !wp_doing_ajax() ? '' : $site_title . $required,
3140 'step' => $step,
3141 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
3142 ) );
3143 } else {
3144 ?>
3145 <div id="<?php echo $field->htmlvar_name; ?>_row" class="<?php if ( $field->is_required ) {
3146 echo 'required_field';
3147 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3148 <?php
3149
3150 if ( ! is_admin() ) { ?>
3151 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3152 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
3153 <?php if ( $field->is_required ) {
3154 echo '<span>*</span>';
3155 } ?>
3156 </label>
3157 <?php }
3158 ?>
3159
3160 <input name="<?php echo $field->htmlvar_name; ?>"
3161 class="<?php echo $field->css_class; ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
3162 id="<?php echo $field->htmlvar_name; ?>"
3163 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
3164 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
3165 title="<?php echo $site_title; ?>"
3166 oninvalid="this.setCustomValidity('<?php _e( $field->required_msg, 'userswp' ); ?>')"
3167 oninput="setCustomValidity('')"
3168 <?php if ( $field->is_required == 1 ) {
3169 echo 'required="required"';
3170 } ?>
3171 <?php if ( $field->for_admin_use == 1 ) {
3172 echo 'readonly="readonly"';
3173 } ?>
3174 type="<?php echo $type; ?>"
3175 <?php if ( $step ) {
3176 echo 'step="' . $step . '"';
3177 } ?>
3178 />
3179 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
3180 <?php if ( $field->is_required ) { ?>
3181 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
3182 <?php } ?>
3183 </div>
3184
3185
3186 <?php
3187 }
3188 $html = ob_get_clean();
3189 }
3190
3191 return $html;
3192 }
3193
3194 /**
3195 * Form field template for textarea field type.
3196 *
3197 * @param string $html Form field html
3198 * @param object $field Field info.
3199 * @param string $value Form field default value.
3200 * @param string $form_type Form type
3201 *
3202 * @return string Modified form field html.
3203 * @package userswp
3204 *
3205 * @since 1.0.0
3206 */
3207 public function form_input_textarea( $html, $field, $value, $form_type ) {
3208
3209 // Check if there is a field specific filter.
3210 if ( has_filter( "uwp_form_input_textarea_{$field->htmlvar_name}" ) ) {
3211 $html = apply_filters( "uwp_form_input_textarea_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3212 }
3213
3214 // If no html then we run the standard output.
3215 if ( empty( $html ) ) {
3216
3217 $design_style = uwp_get_option( "design_style", "bootstrap" );
3218 $bs_form_group = $design_style ? "form-group" : "";
3219 $bs_sr_only = $design_style ? "sr-only" : "";
3220 $bs_form_control = $design_style ? "form-control" : "";
3221 $site_title = uwp_get_form_label( $field );
3222
3223 ob_start(); // Start buffering;
3224
3225 // bootstrap
3226 if ( $design_style ) {
3227 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3228
3229 echo aui()->textarea( array(
3230 'id' => $field->htmlvar_name,
3231 'name' => $field->htmlvar_name,
3232 'placeholder' => uwp_get_field_placeholder( $field ),
3233 'title' => $site_title,
3234 'value' => stripslashes( $value ),
3235 'required' => $field->is_required,
3236 'validation_text' => ! empty( $field->is_required ) ? __( $field->required_msg, 'userswp' ) : '',
3237 'help_text' => uwp_get_field_description( $field ),
3238 'label' => is_admin() && !wp_doing_ajax() ? '' : $site_title . $required,
3239 'rows' => '4',
3240 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
3241 ) );
3242 } else {
3243 ?>
3244
3245 <div id="<?php echo $field->htmlvar_name; ?>_row"
3246 class="<?php if ( $field->is_required ) {
3247 echo 'required_field';
3248 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3249
3250 <?php
3251
3252 if ( ! is_admin() ) { ?>
3253 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3254 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
3255 <?php if ( $field->is_required ) {
3256 echo '<span>*</span>';
3257 } ?>
3258 </label>
3259 <?php } ?>
3260
3261 <textarea name="<?php echo $field->htmlvar_name; ?>"
3262 class="<?php echo $field->css_class; ?> <?php echo esc_attr( $bs_form_control ); ?>"
3263 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
3264 title="<?php echo $site_title; ?>"
3265 oninvalid="this.setCustomValidity('<?php _e( $field->required_msg, 'userswp' ); ?>')"
3266 oninput="setCustomValidity('')"
3267 <?php if ( $field->is_required == 1 ) {
3268 echo 'required="required"';
3269 } ?>
3270 type="<?php echo $field->field_type; ?>"
3271 rows="4"><?php echo stripslashes( $value ); ?></textarea>
3272 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
3273 <?php if ( $field->is_required ) { ?>
3274 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
3275 <?php } ?>
3276 </div>
3277
3278 <?php
3279 }
3280 $html = ob_get_clean();
3281 }
3282
3283 return $html;
3284 }
3285
3286 public function form_input_editor( $html, $field, $value, $form_type ) {
3287
3288 // Check if there is a field specific filter.
3289 if ( has_filter( "uwp_form_input_editor_{$field->htmlvar_name}" ) ) {
3290 $html = apply_filters( "uwp_form_input_editor_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3291 }
3292
3293 if ( empty( $html ) ) {
3294
3295 ob_start();
3296
3297 $design_style = uwp_get_option( "design_style", "bootstrap" );
3298 $bs_form_group = $design_style ? "form-group" : "";
3299 $bs_sr_only = $design_style ? "sr-only" : "";
3300 $site_title = uwp_get_form_label( $field );
3301
3302 $content = stripslashes( $value );
3303 $editor_id = $field->htmlvar_name;
3304 $args = array(
3305 'textarea_rows' => 5,
3306 'media_buttons' => false,
3307 'quicktags' => false,
3308 );
3309
3310 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
3311 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
3312
3313 // bootstrap
3314 if ( $design_style ) {
3315 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3316
3317 echo aui()->textarea( array(
3318 'id' => $field->htmlvar_name,
3319 'name' => $field->htmlvar_name,
3320 'placeholder' => uwp_get_field_placeholder( $field ),
3321 'title' => $site_title,
3322 'value' => stripslashes( $value ),
3323 'required' => $field->is_required,
3324 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
3325 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
3326 'help_text' => uwp_get_field_description( $field ),
3327 'label' => is_admin() && !wp_doing_ajax() ? '' : $site_title . $required,
3328 'rows' => 5,
3329 'wysiwyg' => true,
3330 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
3331 ) );
3332 } else {
3333 ?>
3334 <div id="<?php echo $field->htmlvar_name; ?>_row"
3335 class="<?php if ( $field->is_required ) {
3336 echo 'required_field';
3337 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3338
3339 <?php
3340
3341 if ( ! is_admin() ) { ?>
3342 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3343 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
3344 <?php if ( $field->is_required ) {
3345 echo '<span>*</span>';
3346 } ?>
3347 </label>
3348 <?php } ?>
3349
3350 <?php wp_editor( $content, $editor_id, $args ); ?>
3351
3352 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
3353 <?php if ( $field->is_required ) { ?>
3354 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
3355 <?php } ?>
3356 </div>
3357 <?php
3358 }
3359 $html = ob_get_clean();
3360 }
3361
3362 return $html;
3363 }
3364
3365 /**
3366 * Form field template for fieldset field type.
3367 *
3368 * @param string $html Form field html
3369 * @param object $field Field info.
3370 * @param string $value Form field default value.
3371 * @param string $form_type Form type
3372 *
3373 * @return string Modified form field html.
3374 * @package userswp
3375 *
3376 * @since 1.0.0
3377 */
3378 public function form_input_fieldset( $html, $field, $value, $form_type ) {
3379 // Check if there is a custom field specific filter.
3380 if ( has_filter( "uwp_form_input_fieldset_{$field->htmlvar_name}" ) ) {
3381 $html = apply_filters( "uwp_form_input_fieldset_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3382 }
3383
3384 // If no html then we run the standard output.
3385 if ( empty( $html ) ) {
3386
3387 ob_start(); // Start buffering;
3388 $site_title = uwp_get_form_label( $field );
3389 ?>
3390 <h3 class="uwp_input_fieldset <?php echo $field->css_class; ?>">
3391 <?php echo $site_title; ?>
3392 <?php if ( $field->help_text != '' ) {
3393 echo '<small>( ' . $field->help_text . ' )</small>';
3394 } ?></h3>
3395 <?php
3396 $html = ob_get_clean();
3397 }
3398
3399 return $html;
3400 }
3401
3402 /**
3403 * Form field template for url field type.
3404 *
3405 * @param string $html Form field html
3406 * @param object $field Field info.
3407 * @param string $value Form field default value.
3408 * @param string $form_type Form type
3409 *
3410 * @return string Modified form field html.
3411 * @package userswp
3412 *
3413 * @since 1.0.0
3414 */
3415 public function form_input_url( $html, $field, $value, $form_type ) {
3416
3417
3418 // Check if there is a custom field specific filter.
3419 if ( has_filter( "uwp_form_input_url_{$field->htmlvar_name}" ) ) {
3420 $html = apply_filters( "uwp_form_input_url_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3421 }
3422
3423 // If no html then we run the standard output.
3424 if ( empty( $html ) ) {
3425
3426 $design_style = uwp_get_option( "design_style", "bootstrap" );
3427 $bs_form_group = $design_style ? "form-group" : "";
3428 $bs_sr_only = $design_style ? "sr-only" : "";
3429 $bs_form_control = $design_style ? "form-control" : "";
3430
3431 ob_start(); // Start buffering;
3432 $site_title = uwp_get_form_label( $field );
3433 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : __( 'Please enter a valid URL including https://', 'userswp' );
3434 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
3435
3436 // bootstrap
3437 if ( $design_style ) {
3438 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3439
3440 echo aui()->input( array(
3441 'type' => 'url',
3442 'id' => $field->htmlvar_name,
3443 'name' => $field->htmlvar_name,
3444 'placeholder' => uwp_get_field_placeholder( $field ),
3445 'title' => $site_title,
3446 'value' => $value,
3447 'required' => $field->is_required,
3448 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
3449 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
3450 'help_text' => uwp_get_field_description( $field ),
3451 'label' => is_admin() && !wp_doing_ajax() ? '' : $site_title . $required,
3452 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
3453 ) );
3454 } else {
3455 ?>
3456 <div id="<?php echo $field->htmlvar_name; ?>_row"
3457 class="<?php if ( $field->is_required ) {
3458 echo 'required_field';
3459 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3460
3461 <?php
3462 if ( ! is_admin() ) { ?>
3463 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3464 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
3465 <?php if ( $field->is_required ) {
3466 echo '<span>*</span>';
3467 } ?>
3468 </label>
3469 <?php } ?>
3470
3471 <input name="<?php echo $field->htmlvar_name; ?>"
3472 class="<?php //echo $field->css_class;
3473 ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
3474 id="<?php echo $field->htmlvar_name; ?>"
3475 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
3476 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
3477 title="<?php echo $site_title; ?>"
3478 <?php if ( $field->is_required == 1 ) {
3479 echo 'required="required"';
3480 } ?>
3481 type="url"
3482 oninvalid="setCustomValidity('<?php _e( 'Please enter a valid URL including http://', 'userswp' ); ?>')"
3483 onchange="try{setCustomValidity('')}catch(e){}"
3484 />
3485 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
3486 <?php if ( $field->is_required ) { ?>
3487 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
3488 <?php } ?>
3489 </div>
3490
3491 <?php
3492 }
3493
3494 $html = ob_get_clean();
3495 }
3496
3497 return $html;
3498 }
3499
3500 /**
3501 * Form field template for email field type.
3502 *
3503 * @param string $html Form field html
3504 * @param object $field Field info.
3505 * @param string $value Form field default value.
3506 * @param string $form_type Form type
3507 *
3508 * @return string Modified form field html.
3509 * @package userswp
3510 *
3511 * @since 1.0.0
3512 */
3513 public function form_input_email( $html, $field, $value, $form_type ) {
3514
3515
3516 // Check if there is a custom field specific filter.
3517 if ( has_filter( "uwp_form_input_email_{$field->htmlvar_name}" ) ) {
3518 $html = apply_filters( "uwp_form_input_email_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3519 }
3520
3521 // If no html then we run the standard output.
3522 if ( empty( $html ) ) {
3523
3524 $design_style = uwp_get_option( "design_style", "bootstrap" );
3525 $bs_form_group = $design_style ? "form-group" : "";
3526 $bs_sr_only = $design_style ? "sr-only" : "";
3527 $bs_form_control = $design_style ? "form-control" : "";
3528
3529 ob_start(); // Start buffering;
3530 $site_title = uwp_get_form_label( $field );
3531 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
3532 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
3533
3534 if ( $design_style ) {
3535 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3536
3537 echo aui()->input( array(
3538 'type' => 'email',
3539 'id' => $field->htmlvar_name,
3540 'name' => $field->htmlvar_name,
3541 'placeholder' => uwp_get_field_placeholder( $field ),
3542 'title' => $site_title,
3543 'value' => wp_unslash( $value ),
3544 'required' => $field->is_required,
3545 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
3546 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
3547 'help_text' => uwp_get_field_description( $field ),
3548 'label' => is_admin() && !wp_doing_ajax() ? '' : $site_title . $required,
3549 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
3550 ) );
3551 } else {
3552 ?>
3553 <div id="<?php echo $field->htmlvar_name; ?>_row"
3554 class="<?php if ( $field->is_required ) {
3555 echo 'required_field';
3556 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3557
3558 <?php
3559 if ( ! is_admin() ) { ?>
3560 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3561 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
3562 <?php if ( $field->is_required ) {
3563 echo '<span>*</span>';
3564 } ?>
3565 </label>
3566 <?php } ?>
3567
3568 <input name="<?php echo $field->htmlvar_name; ?>"
3569 class="<?php echo $field->css_class; ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
3570 id="<?php echo $field->htmlvar_name; ?>"
3571 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
3572 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
3573 title="<?php echo $site_title; ?>"
3574 <?php if ( $field->is_required == 1 ) {
3575 echo 'required="required"';
3576 } ?>
3577 type="email"
3578 />
3579 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
3580 <?php if ( $field->is_required ) { ?>
3581 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
3582 <?php } ?>
3583 </div>
3584
3585
3586 <?php
3587 }
3588 $html = ob_get_clean();
3589
3590 }
3591
3592 if ( has_filter( "uwp_form_input_email_{$field->htmlvar_name}_after" ) ) {
3593 $html = apply_filters( "uwp_form_input_email_{$field->htmlvar_name}_after", $html, $field, $value, $form_type );
3594 }
3595
3596 return $html;
3597 }
3598
3599 /**
3600 * Form field template for password field type.
3601 *
3602 * @param string $html Form field html
3603 * @param object $field Field info.
3604 * @param string $value Form field default value.
3605 * @param string $form_type Form type
3606 *
3607 * @return string Modified form field html.
3608 * @package userswp
3609 *
3610 * @since 1.0.0
3611 */
3612 public function form_input_password( $html, $field, $value, $form_type ) {
3613
3614
3615 // Check if there is a custom field specific filter.
3616 if ( has_filter( "uwp_form_input_password_{$field->htmlvar_name}" ) ) {
3617 $html = apply_filters( "uwp_form_input_password_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3618 }
3619
3620 // If no html then we run the standard output.
3621 if ( empty( $html ) ) {
3622
3623 $design_style = uwp_get_option( "design_style", "bootstrap" );
3624 $bs_form_group = $design_style ? "form-group" : "";
3625 $bs_sr_only = $design_style ? "sr-only" : "";
3626 $bs_form_control = $design_style ? "form-control" : "";
3627
3628 ob_start(); // Start buffering;
3629 $site_title = uwp_get_form_label( $field );
3630
3631 if ( $design_style ) {
3632 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3633 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
3634 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
3635
3636 echo aui()->input( array(
3637 'type' => 'password',
3638 'id' => $field->htmlvar_name,
3639 'name' => $field->htmlvar_name,
3640 'placeholder' => uwp_get_field_placeholder( $field ),
3641 'title' => $site_title,
3642 'value' => $value,
3643 'required' => $field->is_required,
3644 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
3645 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
3646 'help_text' => uwp_get_field_description( $field ),
3647 'label' => is_admin() && !wp_doing_ajax() ? '' : $site_title . $required,
3648 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
3649 ) );
3650 } else {
3651 ?>
3652 <div id="<?php echo $field->htmlvar_name; ?>_row" class="<?php if ( $field->is_required ) {
3653 echo 'required_field';
3654 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3655 <?php
3656 if ( ! is_admin() ) { ?>
3657 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3658 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
3659 <?php if ( $field->is_required ) {
3660 echo '<span>*</span>';
3661 } ?>
3662 </label>
3663 <?php } ?>
3664
3665 <input name="<?php echo $field->htmlvar_name; ?>"
3666 class="<?php echo $field->css_class; ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
3667 id="<?php echo $field->htmlvar_name; ?>"
3668 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
3669 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
3670 title="<?php echo $site_title; ?>"
3671 <?php if ( $field->is_required == 1 ) {
3672 echo 'required="required"';
3673 } ?>
3674 type="password"
3675 />
3676 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
3677 <?php if ( $field->is_required ) { ?>
3678 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
3679 <?php } ?>
3680 </div>
3681
3682
3683 <?php
3684 }
3685
3686 $html = ob_get_clean();
3687 }
3688
3689 if ( has_filter( "uwp_form_input_password_{$field->htmlvar_name}_after" ) ) {
3690 $html = apply_filters( "uwp_form_input_password_{$field->htmlvar_name}_after", $html, $field, $value, $form_type );
3691 }
3692
3693 return $html;
3694 }
3695
3696 /**
3697 * Form field template for Phone field.
3698 *
3699 * @param string $html Form field html
3700 * @param object $field Field info.
3701 * @param string $value Form field default value.
3702 * @param string $form_type Form type
3703 *
3704 * @return string $html Modified form field html.
3705 * @since 1.0.0
3706 *
3707 */
3708 public function form_input_phone( $html, $field, $value, $form_type ) {
3709 if ( empty( $html ) ) {
3710 $design_style = uwp_get_option( "design_style", "bootstrap" );
3711 $bs_form_group = $design_style ? "form-group" : "";
3712 $bs_sr_only = $design_style ? "sr-only" : "";
3713 $bs_form_control = $design_style ? "form-control" : "";
3714 ob_start(); // Start buffering;
3715 $site_title = uwp_get_form_label( $field );
3716 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
3717 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
3718
3719 if ( $design_style ) {
3720 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3721
3722 echo aui()->input( array(
3723 'type' => 'tel',
3724 'id' => $field->htmlvar_name,
3725 'name' => $field->htmlvar_name,
3726 'placeholder' => uwp_get_field_placeholder( $field ),
3727 'title' => $site_title,
3728 'value' => $value,
3729 'required' => $field->is_required,
3730 'help_text' => uwp_get_field_description( $field ),
3731 'label' => is_admin() && !wp_doing_ajax() ? '' : $site_title . $required,
3732 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
3733 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
3734 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
3735 ) );
3736 } else {
3737 ?>
3738 <div id="<?php echo $field->htmlvar_name; ?>_row"
3739 class="<?php if ( $field->is_required ) {
3740 echo 'required_field';
3741 } ?> clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3742 <?php
3743 if ( ! is_admin() ) { ?>
3744 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3745 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
3746 <?php if ( $field->is_required ) {
3747 echo '<span>*</span>';
3748 } ?>
3749 </label>
3750 <?php } ?>
3751 <input name="<?php echo $field->htmlvar_name; ?>"
3752 class="<?php echo $field->css_class; ?> <?php echo esc_attr( $bs_form_control ); ?>"
3753 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
3754 title="<?php echo $site_title; ?>"
3755 <?php if ( $field->for_admin_use == 1 ) {
3756 echo 'readonly="readonly"';
3757 } ?>
3758 <?php if ( $field->is_required == 1 ) {
3759 echo 'required="required"';
3760 } ?>
3761 type="tel"
3762 value="<?php echo esc_html( $value ); ?>">
3763 </div>
3764 <?php
3765 }
3766 $html = ob_get_clean();
3767 }
3768
3769 return $html;
3770 }
3771
3772 public function form_input_register_gdpr( $html, $field, $value, $form_type ) {
3773
3774 $form_id = isset($field->form_id) ? (int) $field->form_id : 1;
3775 $reg_gdpr = uwp_get_register_form_by($form_id, 'gdpr_page');
3776 if(empty($reg_gdpr)){
3777 $reg_gdpr = uwp_get_option( 'register_gdpr_page', false );
3778 }
3779
3780 if ( ! empty( $reg_gdpr ) ) {
3781
3782 $design_style = uwp_get_option( "design_style", "bootstrap" );
3783 $bs_form_group = $design_style ? "form-group form-check" : "";
3784 $bs_form_control = $design_style ? "form-check-input" : "";
3785 $site_title = uwp_get_form_label( $field );
3786 $field->htmlvar_name = 'register_gdpr';
3787 $id = wp_doing_ajax() ? $field->htmlvar_name . "_ajax" : $field->htmlvar_name;
3788
3789 $gdpr_page = get_permalink( $reg_gdpr );
3790 $link_start = '<a href="' . $gdpr_page . '" target="_blank">';
3791 $link_end = '</a>';
3792 $field_desc = uwp_get_field_description( $field, '' );
3793 $field_desc = str_replace( '%%link_start%%', $link_start, $field_desc );
3794 $field_desc = str_replace( '%%link_end%%', $link_end, $field_desc );
3795 $content = $field_desc ? $field_desc : sprintf( __( 'By using this form I agree to the storage and handling of my data by this website. View our %s %s %s.', 'userswp' ), '<a href="' . $gdpr_page . '" target="_blank">', $site_title, '</a>' );
3796 $checked = $value == '1' ? true : false;
3797
3798 ob_start(); // Start buffering;
3799
3800 // bootstrap
3801 if ( $design_style ) {
3802 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3803 echo '<input type="hidden" name="' . $field->htmlvar_name . '" id="checkbox_' . $id . '" value="0"/>';
3804
3805 echo aui()->input(
3806 array(
3807 'id' => $id,
3808 'name' => $field->htmlvar_name,
3809 'type' => "checkbox",
3810 'value' => '1',
3811 'title' => $site_title,
3812 'label' => $content . $required,
3813 'label_show' => true,
3814 'required' => ! empty( $field->is_required ) ? true : false,
3815 'checked' => $checked,
3816 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
3817 'validation_text' => ! empty( $field->is_required ) ? __( $field->required_msg, 'userswp' ) : '',
3818 )
3819 );
3820
3821 } else {
3822 ?>
3823 <div id="<?php echo $field->htmlvar_name; ?>_row"
3824 class="<?php if ( $field->is_required ) {
3825 echo 'required_field';
3826 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3827 <input type="hidden" name="<?php echo $field->htmlvar_name; ?>" value="0"/>
3828 <input name="<?php echo $field->htmlvar_name; ?>"
3829 class="<?php echo $field->css_class; ?> <?php echo esc_attr( $bs_form_control ); ?>"
3830 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
3831 title="<?php echo $site_title; ?>"
3832 <?php if ( $value == '1' ) {
3833 echo 'checked="checked"';
3834 } ?>
3835 type="<?php echo $field->field_type; ?>"
3836 value="1">
3837 <?php
3838 echo ( trim( $content ) ) ? $content : '&nbsp;';
3839 ?>
3840 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
3841 <?php if ( $field->is_required ) { ?>
3842 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
3843 <?php } ?>
3844 </div>
3845
3846 <?php
3847 }
3848
3849 $html = ob_get_clean();
3850
3851 } else {
3852 $html = '<input type="hidden" name="register_gdpr" value="-1"/>';
3853 }
3854
3855 return $html;
3856 }
3857
3858 public function form_input_register_tos( $html, $field, $value, $form_type ) {
3859
3860 $form_id = isset($field->form_id) ? (int) $field->form_id : 1;
3861 $reg_tos = uwp_get_register_form_by($form_id, 'tos_page');
3862 if(empty($reg_tos)){
3863 $reg_tos = uwp_get_option( 'register_terms_page', false );
3864 }
3865
3866 if ( ! empty( $reg_tos ) ) {
3867
3868 $design_style = uwp_get_option( "design_style", "bootstrap" );
3869 $bs_form_group = $design_style ? "form-group form-check" : "";
3870 $bs_form_control = $design_style ? "form-check-input" : "";
3871
3872 $site_title = uwp_get_form_label( $field );
3873 $terms_page = get_permalink( $reg_tos );
3874 $link_start = '<a href="' . $terms_page . '" target="_blank">';
3875 $link_end = '</a>';
3876 $field_desc = uwp_get_field_description( $field, '' );
3877 $field_desc = str_replace( '%%link_start%%', $link_start, $field_desc );
3878 $field_desc = str_replace( '%%link_end%%', $link_end, $field_desc );
3879 $field->htmlvar_name = 'register_tos';
3880 $id = wp_doing_ajax() ? $field->htmlvar_name . "_ajax" : $field->htmlvar_name;
3881
3882 $content = $field_desc ? $field_desc : sprintf( __( 'I accept the %s %s %s.', 'userswp' ), '<a href="' . $terms_page . '" target="_blank">', $site_title, '</a>' );
3883 $checked = $value == '1' ? true : false;
3884
3885 ob_start();
3886
3887 if ( $design_style ) {
3888 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3889 echo '<input type="hidden" name="' . $field->htmlvar_name . '" id="checkbox_' . $id . '" value="0"/>';
3890
3891 echo aui()->input(
3892 array(
3893 'id' => $id,
3894 'name' => $field->htmlvar_name,
3895 'type' => "checkbox",
3896 'value' => '1',
3897 'title' => $site_title,
3898 'label' => $content . $required,
3899 'label_show' => true,
3900 'required' => ! empty( $field->is_required ) ? true : false,
3901 'checked' => $checked,
3902 'wrap_class' => isset( $field->css_class ) ? $field->css_class : '',
3903 'validation_text' => ! empty( $field->is_required ) ? __( $field->required_msg, 'userswp' ) : '',
3904 )
3905 );
3906
3907 } else {
3908 ?>
3909 <div id="<?php echo $field->htmlvar_name; ?>_row"
3910 class="<?php if ( $field->is_required ) {
3911 echo 'required_field';
3912 } ?> uwp_form_<?php echo $field->field_type; ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3913 <input type="hidden" name="<?php echo $field->htmlvar_name; ?>" value="0"/>
3914 <input name="<?php echo $field->htmlvar_name; ?>"
3915 class="<?php echo $field->css_class; ?> <?php echo esc_attr( $bs_form_control ); ?>"
3916 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
3917 title="<?php echo $site_title; ?>"
3918 <?php if ( $value == '1' ) {
3919 echo 'checked="checked"';
3920 } ?>
3921 type="<?php echo $field->field_type; ?>"
3922 value="1">
3923 <?php
3924 echo ( trim( $content ) ) ? $content : '&nbsp;';
3925 ?>
3926 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
3927 <?php if ( $field->is_required ) { ?>
3928 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
3929 <?php } ?>
3930 </div>
3931
3932 <?php
3933
3934 }
3935
3936 $html = ob_get_clean();
3937
3938 } else {
3939 $html = '<input type="hidden" name="register_tos" value="-1"/>';
3940 }
3941
3942 return $html;
3943 }
3944
3945 /**
3946 * Adds enctype tag in form for file fields.
3947 *
3948 * @return void
3949 * @package userswp
3950 *
3951 * @since 1.0.0
3952 */
3953 function add_multipart_to_admin_edit_form() {
3954 global $wpdb;
3955 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
3956 $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" );
3957 if ( $fields ) {
3958 echo 'enctype="multipart/form-data"';
3959 }
3960 }
3961
3962 /**
3963 * Handles UsersWP custom field requests from admin.
3964 *
3965 * @param int $user_id User ID.
3966 *
3967 * @return void
3968 * @since 1.0.0
3969 * @package userswp
3970 *
3971 */
3972 public function update_profile_extra_admin_edit( $user_id ) {
3973 global $wpdb;
3974 $file_obj = new UsersWP_Files();
3975 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
3976 //Normal fields
3977 $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" );
3978 if ( $fields ) {
3979 $result = uwp_validate_fields( $_POST, 'account', $fields );
3980 if ( is_wp_error( $result ) ) {
3981 die( $result->get_error_message() );
3982 }
3983 if ( isset( $result['display_name'] ) && ! empty( $result['display_name'] ) ) {
3984 $display_name = $result['display_name'];
3985 } else {
3986 if ( ! empty( $first_name ) || ! empty( $last_name ) ) {
3987 $display_name = $result['first_name'] . ' ' . $result['last_name'];
3988 } else {
3989 $user_info = get_userdata( $user_id );
3990 $display_name = $user_info->user_login;
3991 }
3992 }
3993 $result['display_name'] = $display_name;
3994 if ( ! is_wp_error( $result ) ) {
3995 foreach ( $fields as $field ) {
3996 $value = isset( $result[ $field->htmlvar_name ] ) ? $result[ $field->htmlvar_name ] : '';
3997 if ( $value == '0' || ! empty( $value ) ) {
3998 uwp_update_usermeta( $user_id, $field->htmlvar_name, $value );
3999 }
4000 }
4001 }
4002 }
4003
4004 //File fields
4005 $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" );
4006 if ( $fields ) {
4007 $result = $file_obj->validate_uploads( $_FILES, 'account', true, $fields );
4008 if ( ! is_wp_error( $result ) ) {
4009 foreach ( $fields as $field ) {
4010 $value = $result[ $field->htmlvar_name ];
4011 if ( $value == '0' || ! empty( $value ) ) {
4012 uwp_update_usermeta( $user_id, $field->htmlvar_name, $value );
4013 }
4014 }
4015 }
4016 }
4017 }
4018
4019 /**
4020 * Form field template for country field.
4021 *
4022 * @param string $html Form field html
4023 * @param object $field Field info.
4024 * @param string $value Form field default value.
4025 * @param string $form_type Form type
4026 *
4027 * @return string Modified form field html.
4028 * @package userswp
4029 *
4030 * @since 1.0.0
4031 */
4032 public function form_input_select_country( $html, $field, $value, $form_type ) {
4033
4034 // If no html then we run the standard output.
4035 if ( empty( $html ) ) {
4036
4037 $design_style = uwp_get_option( "design_style", "bootstrap" );
4038 $bs_form_group = $design_style ? "form-group m-0" : ""; // country wrapper div added by JS adds marginso we remove ours
4039 $bs_sr_only = $design_style ? "sr-only" : "";
4040 $bs_form_control = $design_style ? "form-control" : "";
4041
4042 ob_start(); // Start buffering;
4043
4044 ?>
4045 <div id="<?php echo $field->htmlvar_name; ?>_row"
4046 class="<?php if ( $field->is_required ) {
4047 echo 'required_field';
4048 } ?> uwp_clear <?php echo esc_attr( $bs_form_group. ' '.$field->css_class ); ?>">
4049
4050 <?php
4051 $site_title = uwp_get_form_label( $field );
4052 if ( ! is_admin() && !wp_doing_ajax() ) { ?>
4053 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
4054 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
4055 <?php if ( $field->is_required ) {
4056 echo '<span class="text-danger">*</span>';
4057 } ?>
4058 </label>
4059 <?php } ?>
4060
4061 <?php
4062 // if value empty set the default
4063 if ( $value == '' && isset( $field->default_value ) && $field->default_value ) {
4064 $value = $field->default_value;
4065 }
4066 $select_country_options = apply_filters( 'uwp_form_input_select_country', "{defaultCountry: '$value'}", $field, $value, $form_type );
4067 ?>
4068
4069 <input type="text" class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
4070 title="<?php echo $site_title; ?>" id="<?php echo $field->htmlvar_name;
4071 if ( wp_doing_ajax() ) {
4072 echo "_ajax";
4073 } ?>"/>
4074 <input type="hidden" id="<?php echo $field->htmlvar_name;
4075 if ( wp_doing_ajax() ) {
4076 echo "_ajax";
4077 } ?>_code" name="<?php echo $field->htmlvar_name; ?>"/>
4078
4079 <script>
4080 jQuery(function () {
4081 jQuery("#<?php echo $field->htmlvar_name; if ( wp_doing_ajax() ) {
4082 echo "_ajax";
4083 }?>").countrySelect(<?php echo $select_country_options;?>);
4084 });
4085 </script>
4086
4087
4088 <span class="uwp_message_note"><?php echo uwp_get_field_description( $field ); ?></span>
4089 <?php if ( $field->is_required ) { ?>
4090 <span class="uwp_message_error invalid-feedback"><?php _e( $field->required_msg, 'userswp' ); ?></span>
4091 <?php } ?>
4092 </div>
4093
4094 <?php
4095 $html = ob_get_clean();
4096 }
4097
4098 return $html;
4099 }
4100
4101 /**
4102 * Adds confirm password field in forms.
4103 *
4104 * @param string $html Form field html
4105 * @param object $field Field info.
4106 * @param string $value Form field default value.
4107 * @param string $form_type Form type
4108 *
4109 * @return string Modified form field html.
4110 * @package userswp
4111 *
4112 * @since 1.0.0
4113 */
4114 public function register_confirm_password_field( $html, $field, $value, $form_type ) {
4115 if ( $form_type == 'register' ) {
4116 //confirm password field
4117 $extra = array();
4118 if ( isset( $field->extra_fields ) && $field->extra_fields != '' ) {
4119 $extra = unserialize( $field->extra_fields );
4120 }
4121
4122 $enable_confirm_password_field = isset( $extra['confirm_password'] ) ? $extra['confirm_password'] : '0';
4123 if ( $enable_confirm_password_field == '1' ) {
4124
4125 $design_style = uwp_get_option( "design_style", "bootstrap" );
4126 $bs_form_group = $design_style ? "form-group" : "";
4127 $bs_sr_only = $design_style ? "sr-only" : "";
4128 $bs_form_control = $design_style ? "form-control" : "";
4129 $site_title = $placeholder = __( "Confirm Password", 'userswp' );
4130 $required = '';
4131 if ( isset( $field->is_required ) && ! empty( $field->is_required ) ) {
4132 $placeholder .= ' *';
4133 $required = ' <span class="text-danger">*</span>';
4134 }
4135 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
4136 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
4137
4138 ob_start(); // Start buffering;
4139
4140 if ( $design_style ) {
4141
4142 echo aui()->input( array(
4143 'type' => 'password',
4144 'id' => 'confirm_password',
4145 'name' => 'confirm_password',
4146 'placeholder' => $placeholder,
4147 'title' => $site_title,
4148 'value' => $value,
4149 'required' => $field->is_required,
4150 'help_text' => uwp_get_field_description( $field ),
4151 'label' => is_admin() && !wp_doing_ajax() ? '' : $site_title . $required,
4152 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
4153 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
4154 ) );
4155 } else {
4156 ?>
4157 <div id="uwp_account_confirm_password_row"
4158 class="<?php echo 'required_field'; ?> uwp_form_password_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
4159
4160 <?php
4161
4162 if ( ! is_admin() ) { ?>
4163 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
4164 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
4165 <?php if ( $field->is_required ) {
4166 echo '<span>*</span>';
4167 } ?>
4168 </label>
4169 <?php } ?>
4170
4171 <input name="confirm_password"
4172 class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
4173 id="uwp_account_confirm_password"
4174 placeholder="<?php echo $placeholder; ?>"
4175 value=""
4176 title="<?php echo $site_title; ?>"
4177 <?php echo 'required="required"'; ?>
4178 type="password"
4179 />
4180 </div>
4181
4182 <?php
4183 }
4184 $confirm_html = ob_get_clean();
4185 $html = $html . $confirm_html;
4186 }
4187 }
4188
4189 return $html;
4190 }
4191
4192 /**
4193 * Adds confirm email field in forms.
4194 *
4195 * @param string $html Form field html
4196 * @param object $field Field info.
4197 * @param string $value Form field default value.
4198 * @param string $form_type Form type
4199 *
4200 * @return string Modified form field html.
4201 * @package userswp
4202 *
4203 * @since 1.0.0
4204 */
4205 public function register_confirm_email_field( $html, $field, $value, $form_type ) {
4206 if ( $form_type == 'register' ) {
4207 //confirm email field
4208 $extra = array();
4209 if ( isset( $field->extra_fields ) && $field->extra_fields != '' ) {
4210 $extra = unserialize( $field->extra_fields );
4211 }
4212 $enable_confirm_email_field = isset( $extra['confirm_email'] ) ? $extra['confirm_email'] : '0';
4213 if ( $enable_confirm_email_field == '1' ) {
4214
4215 $design_style = uwp_get_option( "design_style", "bootstrap" );
4216 $bs_form_group = $design_style ? "form-group" : "";
4217 $bs_sr_only = $design_style ? "sr-only" : "";
4218 $bs_form_control = $design_style ? "form-control" : "";
4219 $site_title = __( "Confirm Email", 'userswp' );
4220 $required_msg = (!empty( $field->is_required ) && $field->required_msg != '') ? __( $field->required_msg, 'userswp' ) : '';
4221 $validation_text = !empty($field->validation_msg) ? __($field->validation_msg, 'userswp') : '';
4222
4223 ob_start();
4224
4225 if ( $design_style ) {
4226 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
4227
4228 echo aui()->input( array(
4229 'type' => 'email',
4230 'id' => $field->htmlvar_name,
4231 'name' => 'confirm_email',
4232 'placeholder' => $site_title,
4233 'title' => $site_title,
4234 'value' => $value,
4235 'required' => $field->is_required,
4236 'help_text' => uwp_get_field_description( $field ),
4237 'label' => is_admin() && !wp_doing_ajax() ? '' : $site_title . $required,
4238 'validation_text' => $validation_text != '' ? $validation_text : $required_msg,
4239 'validation_pattern' => ! empty( $field->validation_pattern ) ? wp_unslash($field->validation_pattern) : '',
4240 ) );
4241 } else {
4242 ?>
4243 <div id="uwp_account_confirm_email_row"
4244 class="<?php echo 'required_field'; ?> uwp_form_email_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
4245
4246 <?php
4247
4248 if ( ! is_admin() ) { ?>
4249 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
4250 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
4251 <?php if ( $field->is_required ) {
4252 echo '<span>*</span>';
4253 } ?>
4254 </label>
4255 <?php } ?>
4256
4257 <input name="confirm_email"
4258 class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
4259 id="uwp_account_confirm_email"
4260 placeholder="<?php echo $site_title; ?>"
4261 value=""
4262 title="<?php echo $site_title; ?>"
4263 <?php echo 'required="required"'; ?>
4264 type="email"
4265 />
4266 </div>
4267 <?php
4268 }
4269 $confirm_html = ob_get_clean();
4270 $html = $html . $confirm_html;
4271 }
4272 }
4273
4274 return $html;
4275 }
4276
4277 /**
4278 * Handles the privacy form submission.
4279 *
4280 * @return void
4281 * @package userswp
4282 *
4283 * @since 1.0.0
4284 */
4285 public function privacy_submit_handler() {
4286 if ( isset( $_POST['uwp_privacy_submit'] ) ) {
4287 if ( ! isset( $_POST['uwp_privacy_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_privacy_nonce'], 'uwp-privacy-nonce' ) ) {
4288 return;
4289 }
4290
4291 global $wpdb, $uwp_notices;
4292
4293 // Save fields privacy settings
4294 $extra_where = "AND is_public='2'";
4295 $fields = get_account_form_fields( $extra_where );
4296 $fields = apply_filters( 'uwp_account_privacy_fields', $fields );
4297 $user_id = get_current_user_id();
4298 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
4299
4300 $user_meta_info = $wpdb->get_row( $wpdb->prepare( "SELECT user_privacy, tabs_privacy FROM $meta_table WHERE user_id = %d", $user_id ) );
4301 if ( ! empty( $user_meta_info->user_privacy ) ) {
4302 $public_fields = explode( ',', $user_meta_info->user_privacy );
4303 } else {
4304 $public_fields = array();
4305 }
4306
4307 if ( $fields ) {
4308
4309 foreach ( $fields as $field ) {
4310 $field_name = $field->htmlvar_name . '_privacy';
4311 $field_value = strip_tags( esc_sql( $_POST[ $field_name ] ) );
4312
4313 if ( $field_value == 'no' ) {
4314 if ( ! in_array( $field_name, $public_fields ) ) {
4315 $public_fields[] = $field_name;
4316 }
4317 } else {
4318 if ( ( $field_name = array_search( $field_name, $public_fields ) ) !== false ) {
4319 unset( $public_fields[ $field_name ] );
4320 }
4321 }
4322 }
4323
4324 $value = implode( ',', $public_fields );
4325 uwp_update_usermeta( $user_id, 'user_privacy', $value );
4326 }
4327
4328 // Save tabs privacy settings
4329 $tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs';
4330 $tabs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $tabs_table_name . " WHERE form_type=%s AND user_decided = 1 ORDER BY sort_order ASC", 'profile-tabs' ) );
4331
4332 if ( $tabs ) {
4333 $public_fields = maybe_unserialize( $user_meta_info->tabs_privacy );
4334 $do_tabs_update = false;
4335 foreach ( $tabs as $tab ) {
4336 $field_name = $tab->tab_key . '_tab_privacy';
4337
4338 if ( isset( $_POST[ $field_name ] ) ) {
4339 $do_tabs_update = true;
4340 $field_value = $_POST[ $field_name ] == '' ? '' : absint( $_POST[ $field_name ] );
4341
4342 if ( $field_value === '' && isset( $public_fields[ $field_name ] ) ) {
4343 unset( $public_fields[ $field_name ] );
4344 } else {
4345 $public_fields[ $field_name ] = $field_value;
4346 }
4347 }
4348
4349 }
4350
4351 if ( $do_tabs_update ) {
4352 uwp_update_usermeta( $user_id, 'tabs_privacy', maybe_serialize( $public_fields ) );
4353 }
4354 }
4355
4356 if ( isset( $_POST['uwp_hide_from_listing'] ) && 1 == $_POST['uwp_hide_from_listing'] ) {
4357 update_user_meta( $user_id, 'uwp_hide_from_listing', 1 );
4358 } else {
4359 update_user_meta( $user_id, 'uwp_hide_from_listing', 0 );
4360 }
4361
4362 $make_profile_private = uwp_can_make_profile_private();
4363 if ( $make_profile_private ) {
4364 $field_name = 'uwp_make_profile_private';
4365 if ( isset( $_POST[ $field_name ] ) ) {
4366 $value = strip_tags( esc_sql( $_POST[ $field_name ] ) );
4367 $user_id = get_current_user_id();
4368 update_user_meta( $user_id, $field_name, $value );
4369 }
4370 }
4371
4372 $message = apply_filters( 'uwp_privacy_update_success_message', __( 'Privacy settings updated successfully.', 'userswp' ) );
4373 $message = aui()->alert( array(
4374 'type' => 'success',
4375 'content' => $message
4376 )
4377 );
4378 $uwp_notices[] = array( 'account' => $message );
4379
4380 }
4381 }
4382
4383 /**
4384 * Get the ajax login form.
4385 *
4386 * @since 1.2.0
4387 */
4388 public function ajax_login_form() {
4389
4390 // add the modal error container
4391 add_action( 'uwp_template_display_notices', array( $this, 'modal_error_container' ) );
4392
4393 $args = array(
4394 'form_title' => __('Login','userswp'),
4395 );
4396
4397 // get the form
4398 ob_start();
4399 uwp_get_template( "bootstrap/login.php", $args );
4400 $form = ob_get_clean();
4401
4402 // send ajax response
4403 wp_send_json_success( $form );
4404 }
4405
4406 /**
4407 * Get the ajax register form.
4408 *
4409 * @since 1.2.0
4410 */
4411 public function ajax_register_form() {
4412
4413 // add the modal error container
4414 add_action( 'uwp_template_display_notices', array( $this, 'modal_error_container' ) );
4415
4416 global $wp_scripts;
4417 if ( empty( $wp_scripts ) ) {
4418 $wp_scripts = wp_scripts();
4419 }
4420
4421 // do we need country code script in ajax?
4422 $country_field = false;
4423
4424 if(isset($_POST['form_id']) && !empty($_POST['form_id'])){
4425 $form_id = (int)$_POST['form_id'];
4426 } else {
4427 $form_id = 1;
4428 }
4429
4430 $fields = get_register_form_fields($form_id);
4431 if ( ! empty( $fields ) ) {
4432 foreach ( $fields as $field ) {
4433 if ( $field->field_type_key == 'country' || $field->field_type_key == 'uwp_country' ) {
4434 $country_field = true;
4435 }
4436 }
4437 }
4438
4439 ob_start();
4440
4441 // maybe add country code JS
4442 if ( $country_field ) {
4443 $country_data = uwp_get_country_data();
4444 echo "<script>var uwp_country_data = " . json_encode( $country_data ) . "</script>";
4445 echo "<script type='text/javascript' src='" . USERSWP_PLUGIN_URL . 'assets/js/countrySelect.min.js' . "' ></script>";
4446 }
4447
4448 $args = array();
4449 if($form_id > 0){
4450 $args['id'] = $form_id;
4451 }
4452
4453 $args['limit'] = uwp_get_option('register_modal_form', 1);
4454
4455 // get template
4456 uwp_get_template( "bootstrap/register.php", $args );
4457
4458
4459 // only show the JS if NOT doing a block render
4460 if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] != 'super_duper_output_shortcode' ) {
4461 // load scripts
4462 $wp_scripts->do_item( 'zxcvbn-async' );
4463 $wp_scripts->do_item( 'wp-hooks' );
4464 $wp_scripts->do_item( 'wp-i18n' );
4465 $wp_scripts->do_item( 'password-strength-meter' );
4466 ?>
4467 <script>
4468 // Password strength indicator script
4469 jQuery(function ($) {
4470
4471 // Load the settings like WP does.
4472 var first, s;
4473 s = document.createElement('script');
4474 s.src = _zxcvbnSettings.src;
4475 s.type = 'text/javascript';
4476 s.async = true;
4477 first = document.getElementsByTagName('script')[0];
4478 first.parentNode.insertBefore(s, first);
4479
4480 // Enable any pass inputs.
4481 $('body').on('keyup', 'input[name=password], input[name=confirm_password]',
4482 function (event) {
4483 var $form = $(this).closest('form');
4484 uwp_checkPasswordStrength(
4485 $('input[name=password]', $form), // First password field
4486 $('input[name=confirm_password]', $form), // Second password field
4487 $('#uwp-password-strength', $form), // Strength meter
4488 $('input[type=submit]', $form), // Submit button
4489 ['black', 'listed', 'word'] // Blacklisted words
4490 );
4491 }
4492 );
4493 });
4494 </script>
4495 <?php
4496 }
4497 $form = ob_get_clean();
4498
4499 // send ajax response
4500 wp_send_json_success( $form );
4501 }
4502
4503 /**
4504 * Get the ajax forgot password form.
4505 *
4506 * @since 1.2.0
4507 */
4508 public function ajax_forgot_password_form() {
4509
4510 // add the modal error container
4511 add_action( 'uwp_template_display_notices', array( $this, 'modal_error_container' ) );
4512
4513 // get the form
4514 ob_start();
4515 uwp_get_template( "bootstrap/forgot.php" );
4516 $form = ob_get_clean();
4517
4518 // send ajax response
4519 wp_send_json_success( $form );
4520 }
4521
4522 /**
4523 * Output the modal error container.
4524 *
4525 * @param string $type
4526 *
4527 * @since 1.2.0
4528 */
4529 public function modal_error_container( $type = '' ) {
4530 echo '<div class="form-group"><div class="modal-error"></div></div>';
4531 }
4532
4533 public function form_custom_html( $html, $field, $value, $form_type ) {
4534
4535 $html = ! empty( $field->default_value ) ? $field->default_value : ' ';
4536
4537 return $html;
4538 }
4539 }