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

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

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