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

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