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

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

5,139 lines 177.7 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 global $wpdb;
2132 $file_field_names = $wpdb->get_col(
2133 $wpdb->prepare(
2134 "SELECT htmlvar_name FROM " . uwp_get_table_prefix() . "uwp_form_fields WHERE form_type = %s AND field_type IN ('file','image')",
2135 'account'
2136 )
2137 );
2138 foreach ( $file_field_names as $file_field_name ) {
2139 if ( isset( $result[ $file_field_name ] ) && ! isset( $uploads_result[ $file_field_name ] ) ) {
2140 unset( $result[ $file_field_name ] );
2141 }
2142 }
2143
2144 $result = array_merge( $result, $uploads_result );
2145
2146 $args = array(
2147 'ID' => get_current_user_id(),
2148 );
2149
2150 if ( isset( $result['first_name'] ) && isset( $result['last_name'] ) ) {
2151 $args['display_name'] = $result['first_name'] . ' ' . $result['last_name'];
2152 }
2153
2154 if ( isset( $result['first_name'] ) ) {
2155 $args['first_name'] = $result['first_name'];
2156 }
2157
2158 if ( isset( $result['last_name'] ) ) {
2159 $args['last_name'] = $result['last_name'];
2160 }
2161
2162 if ( isset( $result['user_url'] ) ) {
2163 $args['user_url'] = $result['user_url'];
2164 }
2165
2166 if ( isset( $result['display_name'] ) && ! empty( $result['display_name'] ) ) {
2167 $args['display_name'] = $result['display_name'];
2168 }
2169
2170 if ( isset( $result['password'] ) ) {
2171 $args['user_pass'] = $result['password'];
2172 }
2173
2174 $user_id = wp_update_user( $args );
2175
2176 if ( is_wp_error( $user_id ) ) {
2177 $message = aui()->alert(
2178 array(
2179 'type' => 'error',
2180 'content' => sprintf( __( '%s', 'userswp' ), $user_id->get_error_message() ),
2181 )
2182 );
2183 $uwp_notices[] = array( 'account' => $message );
2184
2185 return;
2186 }
2187
2188 $res = $this->save_user_extra_fields( $user_id, $result, 'account' );
2189
2190 if ( ! $res ) {
2191 $message = aui()->alert(
2192 array(
2193 'type' => 'error',
2194 'content' => __( 'Something went wrong. Please contact site admin.', 'userswp' ),
2195 )
2196 );
2197 $uwp_notices[] = array( 'account' => $message );
2198
2199 return;
2200 }
2201
2202 //updating bio field after saving extra fields to reflect the points in mycred add on.
2203 if ( isset( $result['bio'] ) && ! empty( $result['bio'] ) ) {
2204 $args = array(
2205 'ID' => $user_id,
2206 'description' => $result['bio'],
2207 );
2208 wp_update_user( $args );
2209 }
2210
2211 $user_data = get_userdata( $user_id );
2212
2213 $form_fields = apply_filters( 'uwp_send_mail_form_fields', '', 'account', $user_id );
2214
2215 if ( isset( $result['email'] ) && $user_data->user_email !== trim( $result['email'] ) ) {
2216
2217 if ( email_exists( trim( $result['email'] ) ) ) {
2218 $message = aui()->alert(
2219 array(
2220 'type' => 'error',
2221 'content' => __( 'This email is already registered, please choose another one.', 'userswp' ),
2222 )
2223 );
2224
2225 $uwp_notices[] = array( 'account' => $message );
2226 return;
2227
2228 }
2229
2230 $hash = md5( $result['email'] . time() . wp_rand() );
2231 $new_admin_email = array(
2232 'hash' => $hash,
2233 'newemail' => $result['email'],
2234 );
2235
2236 update_user_meta( get_current_user_id(), 'uwp_update_email_hash', $new_admin_email );
2237
2238 $new_email_link = add_query_arg(
2239 array(
2240 'uwp_new_email' => 'yes',
2241 'key' => $hash,
2242 'login' => $user_data->user_login,
2243 ),
2244 uwp_get_account_page_url()
2245 );
2246
2247 $email_vars = array(
2248 'user_id' => $user_id,
2249 'new_email' => $result['email'],
2250 'new_email_link' => esc_url( $new_email_link ),
2251 );
2252
2253 UsersWP_Mails::send( $result['email'], 'account_new_email_activation', $email_vars );
2254
2255 $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 );
2256 $message = aui()->alert(
2257 array(
2258 'type' => 'success',
2259 'content' => $message,
2260 )
2261 );
2262
2263 $uwp_notices[] = array( 'account' => $message );
2264
2265 } else {
2266 $email_vars = array(
2267 'user_id' => $user_id,
2268 'form_fields' => $form_fields,
2269 );
2270
2271 UsersWP_Mails::send( $user_data->user_email, 'account_update', $email_vars );
2272
2273 $message = apply_filters( 'uwp_account_update_success_message', __( 'Account updated successfully.', 'userswp' ), $data );
2274 $message = aui()->alert(
2275 array(
2276 'type' => 'success',
2277 'content' => $message,
2278 )
2279 );
2280
2281 $uwp_notices[] = array( 'account' => $message );
2282 }
2283
2284 do_action( 'uwp_after_process_account', $data, $user_id );
2285 }
2286
2287 /**
2288 * Modifies the forms field in email based on the form type.
2289 *
2290 * @param string $form_fields Form fields.
2291 * @param string $type Form type.
2292 * @param int $user_id User ID.
2293 *
2294 * @return string Modified mail field.
2295 * @package userswp
2296 * @subpackage userswp/includes
2297 *
2298 */
2299 public function init_mail_form_fields( $form_fields, $type, $user_id ) {
2300 switch ( $type ) {
2301 case 'register':
2302 $form_id = get_user_meta( $user_id, '_uwp_register_form_id', true );
2303 $fields = get_register_form_fields( $form_id );
2304 $user_data = get_userdata( $user_id );
2305 if ( ! empty( $fields ) && is_array( $fields ) ) {
2306 $form_fields = '<p><b>' . __( 'User Information:', 'userswp' ) . '</b></p>';
2307 $excluded = uwp_get_excluded_fields();
2308 foreach ( $fields as $key => $field ) {
2309 if ( $field->is_active != '1' || in_array( $field->htmlvar_name, $excluded ) ) {
2310 continue;
2311 }
2312 if ( $field->htmlvar_name == 'email' && isset( $user_data->user_email ) ) {
2313 $field_value = $user_data->user_email;
2314 } elseif ( $field->htmlvar_name == 'display_name' && isset( $user_data->user_login ) ) {
2315 $field_value = $user_data->user_login;
2316 } elseif ( $field->htmlvar_name == 'bio' ) {
2317 $field_value = get_user_meta( $user_id, 'description', true );
2318 } else {
2319 $field_value = uwp_get_usermeta( $user_id, $field->htmlvar_name );
2320 }
2321
2322 if ( is_array( $field_value ) && count( $field_value ) > 0 ) {
2323 $field_value = uwp_maybe_serialize( $field->htmlvar_name, $field_value );
2324 }
2325
2326 if ( isset( $field->site_title ) && ! empty( $field_value ) ) {
2327 $form_fields .= '<p><b>' . __( wp_unslash( $field->site_title ), 'userswp' ) . '</b>:&nbsp;' . $field_value . '</p>';
2328 }
2329 }
2330 }
2331 break;
2332 case 'account':
2333 $fields = get_account_form_fields();
2334 $user_data = get_userdata( $user_id );
2335 if ( ! empty( $fields ) && is_array( $fields ) ) {
2336 $form_fields = '<p><b>' . __( 'User Information:', 'userswp' ) . '</b></p>';
2337 foreach ( $fields as $key => $field ) {
2338 if ( $field->is_active != '1' ) {
2339 continue;
2340 }
2341 if ( $field->htmlvar_name == 'email' && isset( $user_data->user_email ) ) {
2342 $field_value = $user_data->user_email;
2343 } elseif ( $field->htmlvar_name == 'display_name' && isset( $user_data->user_login ) ) {
2344 $field_value = $user_data->user_login;
2345 } elseif ( $field->htmlvar_name == 'bio' ) {
2346 $field_value = get_user_meta( $user_id, 'description', true );
2347 } else {
2348 $field_value = uwp_get_usermeta( $user_id, $field->htmlvar_name );
2349 }
2350
2351 if ( is_array( $field_value ) && count( $field_value ) > 0 ) {
2352 $field_value = uwp_maybe_serialize( $field->htmlvar_name, $field_value );
2353 }
2354
2355 if ( isset( $field->site_title ) && ! empty( $field_value ) ) {
2356 $form_fields .= '<p><b>' . __( wp_unslash( $field->site_title ), 'userswp' ) . '</b>:&nbsp;' . $field_value . '</p>';
2357 }
2358 }
2359 }
2360 break;
2361 }
2362
2363 return apply_filters( 'uwp_mail_form_fields', $form_fields, $type, $user_id );
2364 }
2365
2366 /**
2367 *
2368 *
2369 * @return void
2370 * @since 1.0.12 Unlink file.
2371 * @package userswp
2372 * @since 1.0.0
2373 */
2374 public function upload_file_remove() {
2375 global $wpdb;
2376
2377 check_ajax_referer( 'uwp_basic_nonce', 'security' );
2378
2379 // Check user logged in.
2380 if ( ! is_user_logged_in() ) {
2381 $message = aui()->alert( array( 'type' => 'error', 'content' => __( 'Access denied!', 'userswp' ) ) );
2382 wp_send_json_error( array( 'message' => $message ) );
2383 }
2384
2385 $user_id = ! empty( $_POST['uid'] ) ? absint( $_POST['uid'] ) : 0;
2386 $htmlvar = ! empty( $_POST['htmlvar'] ) ? sanitize_key( $_POST['htmlvar'] ) : '';
2387
2388 if ( empty( $user_id ) || empty( $htmlvar ) ) {
2389 $message = aui()->alert( array( 'type' => 'error', 'content' => __( 'Invalid data!', 'userswp' ) ) );
2390 wp_send_json_error( array( 'message' => $message ) );
2391 }
2392
2393 // Validate the user / admin.
2394 if ( ! ( $user_id == (int) get_current_user_id() || current_user_can( 'manage_options' ) ) ) {
2395 $message = aui()->alert( array( 'type' => 'error', 'content' => __( 'Invalid access!', 'userswp' ) ) );
2396 wp_send_json_error( array( 'message' => $message ) );
2397 }
2398
2399 if ( $htmlvar == 'banner_thumb' ) {
2400 $field_key = 'banner';
2401 $type = 'banner';
2402 } else if ( $htmlvar == 'avatar_thumb' ) {
2403 $field_key = 'avatar';
2404 $type = 'avatar';
2405 } else {
2406 $field_key = $htmlvar;
2407 $type = '';
2408 }
2409
2410 $field = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . uwp_get_table_prefix() . "uwp_form_fields WHERE htmlvar_name = %s LIMIT 1", $field_key ) );
2411
2412 // Check field exists.
2413 if ( empty( $field ) ) {
2414 $message = aui()->alert( array( 'type' => 'error', 'content' => __( 'Invalid field!', 'userswp' ) ) );
2415 wp_send_json_error( array( 'message' => $message ) );
2416 }
2417
2418 // Validate field access.
2419 if ( ! empty( $field->for_admin_use ) && ! current_user_can( 'manage_options' ) ) {
2420 $message = aui()->alert( array( 'type' => 'error', 'content' => __( 'You are not allowed to perform this action!', 'userswp' ) ) );
2421 wp_send_json_error( array( 'message' => $message ) );
2422 }
2423
2424 if ( ! in_array( $field->field_type, array( 'file', 'image' ) ) ) {
2425 $message = aui()->alert( array( 'type' => 'error', 'content' => __( 'Invalid field type!', 'userswp' ) ) );
2426 wp_send_json_error( array( 'message' => $message ) );
2427 }
2428
2429 $value = uwp_get_usermeta( $user_id, $htmlvar );
2430
2431 uwp_update_usermeta( $user_id, $htmlvar, '' );
2432
2433 if ( $value && validate_file( $value ) === 0 ) {
2434 $uploads = wp_upload_dir();
2435 $upload_path = $uploads['basedir'];
2436
2437 if ( strpos( $value, 'http://' ) === 0 || strpos( $value, 'https://' ) === 0 ) {
2438 // Get the relative url.
2439 $value = uwp_get_file_relative_url( $value );
2440 }
2441
2442 $unlink_file = untrailingslashit( $upload_path ) . '/' . trim( $value, '/\\' );
2443
2444 // Canonicalize and enforce containment inside the uploads directory before deleting.
2445 $real_upload_path = realpath( $upload_path );
2446 $real_unlink_file = realpath( $unlink_file );
2447
2448 if ( $real_upload_path && $real_unlink_file && is_file( $real_unlink_file )
2449 && strpos( $real_unlink_file, $real_upload_path . DIRECTORY_SEPARATOR ) === 0 ) {
2450 wp_delete_file( $real_unlink_file );
2451
2452 // For avatar/banner, also remove the original (non-thumb) file.
2453 if ( $type ) {
2454 $unlink_ori_file = str_replace( '_uwp_' . $type . '_thumb' . '.', '.', $real_unlink_file );
2455 $real_unlink_ori_file = realpath( $unlink_ori_file );
2456
2457 if ( $real_unlink_ori_file && is_file( $real_unlink_ori_file )
2458 && strpos( $real_unlink_ori_file, $real_upload_path . DIRECTORY_SEPARATOR ) === 0 ) {
2459 wp_delete_file( $real_unlink_ori_file );
2460 }
2461 }
2462 }
2463 }
2464
2465 wp_send_json_success();
2466
2467 wp_die();
2468 }
2469
2470 /**
2471 * Form field template for datepicker field type.
2472 *
2473 * @param string $html Form field html
2474 * @param object $field Field info.
2475 * @param string $value Form field default value.
2476 * @param string $form_type Form type
2477 *
2478 * @return string Modified form field html.
2479 * @package userswp
2480 *
2481 * @since 1.0.0
2482 */
2483 public function form_input_datepicker( $html, $field, $value, $form_type ) {
2484
2485 // Check if there is a field specific filter.
2486 if ( has_filter( "uwp_form_input_html_datepicker_{$field->htmlvar_name}" ) ) {
2487 $html = apply_filters( "uwp_form_input_html_datepicker_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2488 }
2489
2490 // If no html then we run the standard output.
2491 if ( empty( $html ) ) {
2492
2493 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
2494 $bs_form_group = $design_style ? 'form-group mb-3' : '';
2495 $bs_sr_only = $design_style ? 'sr-only' : '';
2496 $bs_form_control = $design_style ? 'form-control' : '';
2497 $extra_attributes = array();
2498 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
2499 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
2500
2501 ob_start(); // Start buffering;
2502
2503 $extra_fields = unserialize( $field->extra_fields );
2504
2505 if ( $extra_fields['date_format'] == '' ) {
2506 $extra_fields['date_format'] = 'yy-mm-dd';
2507 }
2508
2509 $date_format = $extra_fields['date_format'];
2510 $jquery_date_format = $date_format;
2511
2512 // check if we need to change the format or not
2513 $date_format_len = strlen( str_replace( ' ', '', $date_format ) );
2514 if ( $date_format_len > 5 ) {// if greater then 5 then it's the old style format.
2515
2516 $search = array( 'dd', 'd', 'DD', 'mm', 'm', 'MM', 'yy' ); //jQuery UI datepicker format
2517 $replace = array( 'd', 'j', 'l', 'm', 'n', 'F', 'Y' );//PHP date format
2518
2519 $date_format = str_replace( $search, $replace, $date_format );
2520 } else {
2521 $jquery_date_format = uwp_date_format_php_to_jqueryui( $jquery_date_format );
2522 }
2523
2524 if ( ! empty( $value ) && ! is_string( $value ) ) {
2525 $value = date( 'Y-m-d', $value );
2526 }
2527
2528 if ( $value == '0000-00-00' ) {
2529 $value = '';
2530 }//if date not set, then mark it empty
2531 $value = uwp_date( $value, 'Y-m-d', $date_format );
2532 $site_title = uwp_get_form_label( $field );
2533
2534 // bootstrap
2535 if ( $design_style ) {
2536 // flatpickr attributes
2537 $extra_attributes['data-alt-input'] = 'true';
2538 $extra_attributes['data-alt-format'] = $date_format;
2539 $extra_attributes['data-date-format'] = 'Y-m-d';
2540
2541 if ( 'dob' == $field->htmlvar_name ) {
2542 $extra_attributes['data-max-date'] = 'today';
2543 }
2544
2545 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
2546
2547 echo aui()->input( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2548 array(
2549 'id' => esc_attr( $field->htmlvar_name ),
2550 'name' => esc_attr( $field->htmlvar_name ),
2551 'required' => ! empty( $field->is_required ) ? true : false,
2552 'label' => wp_kses_post( $site_title . $required ),
2553 'label_show' => true,
2554 'label_type' => 'hidden',
2555 'type' => 'datepicker',
2556 'title' => esc_html( $site_title ),
2557 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ),
2558 'class' => '',
2559 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
2560 'value' => esc_attr( $value ),
2561 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
2562 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
2563 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
2564 'extra_attributes' => $extra_attributes, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2565 )
2566 );
2567 } else {
2568 ?>
2569 <script type="text/javascript">
2570
2571 jQuery(function () {
2572 jQuery("#<?php echo esc_attr( $field->htmlvar_name ); ?>").datepicker({
2573 changeMonth: true, changeYear: true
2574 <?php
2575 if ( $field->htmlvar_name == 'dob' ) {
2576 echo ", yearRange: '1900:+0'";
2577 } else {
2578 echo ", yearRange: '1900:2050'";
2579 }
2580 ?>
2581 <?php echo apply_filters( "uwp_datepicker_extra_{$field->htmlvar_name}", '' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>});
2582
2583 jQuery("#<?php echo esc_attr( $field->htmlvar_name ); ?>").datepicker("option", "dateFormat", '<?php echo esc_attr( $jquery_date_format ); ?>');
2584
2585 <?php if ( ! empty( $value ) ) { ?>
2586 var parsedDate = jQuery.datepicker.parseDate('yy-mm-dd', '<?php echo esc_attr( $value ); ?>');
2587 jQuery("#<?php echo esc_attr( $field->htmlvar_name ); ?>").datepicker("setDate", parsedDate);
2588 <?php } ?>
2589
2590 });
2591
2592 </script>
2593 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
2594 class="
2595 <?php
2596 if ( $field->is_required ) {
2597 echo 'required_field';
2598 }
2599 ?>
2600 clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2601
2602 <?php
2603
2604 if ( ! is_admin() ) {
2605 ?>
2606 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2607 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
2608 <?php
2609 if ( $field->is_required ) {
2610 echo '<span>*</span>';
2611 }
2612 ?>
2613 </label>
2614 <?php } ?>
2615
2616 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
2617 id="<?php echo esc_attr( $field->htmlvar_name ); ?>"
2618 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
2619 title="<?php echo esc_attr( $site_title ); ?>"
2620 type="text"
2621 <?php
2622 if ( $field->is_required == 1 ) {
2623 echo 'required="required"';
2624 }
2625 ?>
2626 value="<?php echo esc_attr( $value ); ?>"
2627 class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"/>
2628
2629 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
2630 <?php if ( $field->is_required ) { ?>
2631 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
2632 <?php } ?>
2633 </div>
2634
2635 <?php
2636 }
2637
2638 $html = ob_get_clean();
2639 }
2640
2641 return $html;
2642 }
2643
2644 /**
2645 * Form field template for time field type.
2646 *
2647 * @param string $html Form field html
2648 * @param object $field Field info.
2649 * @param string $value Form field default value.
2650 * @param string $form_type Form type
2651 *
2652 * @return string Modified form field html.
2653 * @package userswp
2654 *
2655 * @since 1.0.0
2656 */
2657 public function form_input_time( $html, $field, $value, $form_type ) {
2658
2659 if ( has_filter( "uwp_form_input_html_time_{$field->htmlvar_name}" ) ) {
2660
2661 $html = apply_filters( "uwp_form_input_html_time_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2662 }
2663
2664 // If no html then we run the standard output.
2665 if ( empty( $html ) ) {
2666
2667 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
2668 $bs_form_group = $design_style ? 'form-group mb-3' : '';
2669 $bs_sr_only = $design_style ? 'sr-only' : '';
2670 $bs_form_control = $design_style ? 'form-control bg-white' : '';
2671 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
2672 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
2673
2674 ob_start(); // Start buffering;
2675
2676 if ( $value != '' ) {
2677 $value = date( 'H:i', strtotime( $value ) );
2678 }
2679
2680 // flatpickr attributes
2681 $extra_attributes['data-enable-time'] = 'true';
2682 $extra_attributes['data-no-calendar'] = 'true';
2683 $extra_attributes['data-date-format'] = 'H:i';
2684 $site_title = uwp_get_form_label( $field );
2685 $label_type = is_admin() ? '' : 'top';
2686
2687 if ( $design_style ) {
2688 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
2689
2690 echo aui()->input( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2691 array(
2692 'id' => esc_attr( $field->htmlvar_name ),
2693 'name' => esc_attr( $field->htmlvar_name ),
2694 'required' => ! empty( $field->is_required ) ? true : false,
2695 'label' => wp_kses_post( $site_title . $required ),
2696 'label_show' => true,
2697 'label_type' => esc_attr( $label_type ),
2698 'type' => 'timepicker',
2699 'title' => esc_html( $site_title ),
2700 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ),
2701 'class' => '',
2702 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
2703 'value' => esc_attr( $value ),
2704 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
2705 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
2706 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
2707 'extra_attributes' => $extra_attributes, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2708 '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>',
2709 )
2710 );
2711 } else {
2712 ?>
2713 <script type="text/javascript">
2714 jQuery(document).ready(function () {
2715 jQuery('#<?php echo esc_attr( $field->htmlvar_name ); ?>').timepicker({
2716 showPeriod: true,
2717 showLeadingZero: true
2718 });
2719 });
2720 </script>
2721 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
2722 class="
2723 <?php
2724 if ( $field->is_required ) {
2725 echo 'required_field';
2726 }
2727 ?>
2728 clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2729
2730 <?php
2731 $site_title = uwp_get_form_label( $field );
2732 if ( ! is_admin() ) {
2733 ?>
2734 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2735 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
2736 <?php
2737 if ( $field->is_required ) {
2738 echo '<span>*</span>';
2739 }
2740 ?>
2741 </label>
2742 <?php } ?>
2743
2744 <input readonly="readonly" name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
2745 id="<?php echo esc_attr( $field->htmlvar_name ); ?>"
2746 value="<?php echo esc_attr( $value ); ?>"
2747 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
2748 type="text"
2749 class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"/>
2750
2751 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
2752 <?php if ( $field->is_required ) { ?>
2753 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
2754 <?php } ?>
2755 </div>
2756 <?php
2757 }
2758 $html = ob_get_clean();
2759 }
2760
2761 return $html;
2762 }
2763
2764 /**
2765 * Form field template for select field type.
2766 *
2767 * @param string $html Form field html
2768 * @param object $field Field info.
2769 * @param string $value Form field default value.
2770 * @param string $form_type Form type
2771 *
2772 * @return string Modified form field html.
2773 * @package userswp
2774 *
2775 * @since 1.0.0
2776 */
2777 public function form_input_select( $html, $field, $value, $form_type ) {
2778
2779 // Check if there is a field specific filter.
2780 if ( has_filter( "uwp_form_input_html_select_{$field->htmlvar_name}" ) ) {
2781 $html = apply_filters( "uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2782 }
2783
2784 // Check if there is a field type specific filter.
2785 if ( has_filter( "uwp_form_input_html_select_{$field->field_type_key}" ) ) {
2786 $html = apply_filters( "uwp_form_input_html_select_{$field->field_type_key}", $html, $field, $value, $form_type );
2787 }
2788
2789 // If no html then we run the standard output.
2790 if ( empty( $html ) ) {
2791
2792 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
2793 $bs_form_group = $design_style ? 'form-group mb-3' : '';
2794 $bs_sr_only = $design_style ? 'sr-only' : '';
2795 $bs_form_control = $design_style ? 'form-control' : '';
2796 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
2797 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
2798
2799 ob_start(); // Start buffering;
2800 $option_values_arr = uwp_string_values_to_options( $field->option_values, true );
2801 $site_title = uwp_get_form_label( $field );
2802
2803 // bootstrap
2804 if ( $design_style ) {
2805
2806 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
2807
2808 echo aui()->select(
2809 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2810 'id' => esc_attr( $field->htmlvar_name ),
2811 'name' => esc_attr( $field->htmlvar_name ),
2812 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ),
2813 'title' => esc_html( $site_title ),
2814 'value' => esc_attr( $value ),
2815 'required' => (bool) $field->is_required,
2816 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
2817 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
2818 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
2819 'label' => wp_kses_post( $site_title . $required ),
2820 'options' => $option_values_arr, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2821 'select2' => true,
2822 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
2823 )
2824 );
2825 } else {
2826 ?>
2827 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
2828 class="
2829 <?php
2830 if ( $field->is_required ) {
2831 echo 'required_field';
2832 }
2833 ?>
2834 uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2835
2836 <?php
2837 if ( ! is_admin() ) {
2838 ?>
2839 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2840 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
2841 <?php
2842 if ( $field->is_required ) {
2843 echo '<span>*</span>';
2844 }
2845 ?>
2846 </label>
2847 <?php } ?>
2848
2849 <?php
2850
2851 $select_options = '';
2852 if ( ! empty( $option_values_arr ) ) {
2853 foreach ( $option_values_arr as $option_row ) {
2854 if ( isset( $option_row['optgroup'] ) && ( $option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end' ) ) {
2855 $option_label = isset( $option_row['label'] ) ? $option_row['label'] : '';
2856
2857 $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
2858 } else {
2859 $option_label = isset( $option_row['label'] ) ? $option_row['label'] : '';
2860 $option_value = isset( $option_row['value'] ) ? $option_row['value'] : '';
2861 $selected = $option_value == $value ? 'selected="selected"' : '';
2862
2863 $select_options .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . '>' . $option_label . '</option>';
2864 }
2865 }
2866 }
2867 ?>
2868 <select name="<?php echo esc_attr( $field->htmlvar_name ); ?>" id="<?php echo esc_attr( $field->htmlvar_name ); ?>"
2869 class="uwp_textfield aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
2870 title="<?php echo esc_attr( $site_title ); ?>"
2871 data-placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
2872 ><?php echo $select_options; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
2873 </select>
2874 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
2875 <?php if ( $field->is_required ) { ?>
2876 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
2877 <?php } ?>
2878 </div>
2879
2880 <?php
2881 }
2882 $html = ob_get_clean();
2883 }
2884
2885 return $html;
2886 }
2887
2888 /**
2889 * Form field template for multiselect field type.
2890 *
2891 * @param string $html Form field html
2892 * @param object $field Field info.
2893 * @param string $value Form field default value.
2894 * @param string $form_type Form type
2895 *
2896 * @return string Modified form field html.
2897 * @package userswp
2898 *
2899 * @since 1.0.0
2900 */
2901 public function form_input_multiselect( $html, $field, $value, $form_type ) {
2902
2903 // Check if there is a field specific filter.
2904 if ( has_filter( "uwp_form_input_html_multiselect_{$field->htmlvar_name}" ) ) {
2905 $html = apply_filters( "uwp_form_input_html_multiselect_{$field->htmlvar_name}", $html, $field, $value, $form_type );
2906 }
2907
2908 if ( empty( $html ) ) {
2909
2910 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
2911 $bs_form_group = $design_style ? 'form-group mb-3' : '';
2912 $bs_sr_only = $design_style ? 'sr-only' : '';
2913 $bs_form_control = $design_style ? 'form-control' : '';
2914 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
2915 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
2916
2917 ob_start(); // Start buffering;
2918
2919 $multi_display = 'select';
2920 if ( ! empty( $field->extra_fields ) ) {
2921 $multi_display = unserialize( $field->extra_fields );
2922 }
2923
2924 $option_values_arr = uwp_string_values_to_options( $field->option_values, true );
2925 $site_title = uwp_get_form_label( $field );
2926 $value = is_array( $value ) ? $value : esc_attr( $value );
2927
2928 // bootstrap
2929 if ( $design_style ) {
2930
2931 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
2932
2933 echo aui()->select(
2934 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2935 'id' => esc_attr( $field->htmlvar_name ),
2936 'name' => esc_attr( $field->htmlvar_name ),
2937 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ),
2938 'title' => esc_html( $site_title ),
2939 'value' => $value,
2940 'required' => (bool) $field->is_required,
2941 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
2942 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
2943 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
2944 'label' => wp_kses_post( $site_title . $required ),
2945 'options' => $option_values_arr, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2946 'select2' => true,
2947 'multiple' => true,
2948 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
2949 )
2950 );
2951 } else {
2952 ?>
2953 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
2954 class="
2955 <?php
2956 if ( $field->is_required ) {
2957 echo 'required_field';
2958 }
2959 ?>
2960 uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
2961
2962 <?php
2963 if ( ! is_admin() ) {
2964 ?>
2965 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
2966 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
2967 <?php
2968 if ( $field->is_required ) {
2969 echo '<span>*</span>';
2970 }
2971 ?>
2972 </label>
2973 <?php } ?>
2974
2975 <input type="hidden" name="<?php echo esc_attr( $field->htmlvar_name ); ?>" value=""/>
2976 <?php if ( $multi_display == 'select' ) { ?>
2977 <div class="uwp_multiselect_list">
2978 <select name="<?php echo esc_attr( $field->htmlvar_name ); ?>[]"
2979 id="<?php echo esc_attr( $field->htmlvar_name ); ?>"
2980 title="<?php echo esc_attr( $site_title ); ?>"
2981 data-placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
2982 class="aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
2983 >
2984 <?php
2985 } else {
2986 ?>
2987 <ul class="uwp_multi_choice">
2988 <?php
2989 }
2990
2991 $option_values_arr = uwp_string_values_to_options( $field->option_values, true );
2992 $select_options = '';
2993 if ( ! empty( $option_values_arr ) ) {
2994 foreach ( $option_values_arr as $option_row ) {
2995 if ( isset( $option_row['optgroup'] ) && ( $option_row['optgroup'] == 'start' || $option_row['optgroup'] == 'end' ) ) {
2996 $option_label = isset( $option_row['label'] ) ? $option_row['label'] : '';
2997
2998 if ( $multi_display == 'select' ) {
2999 $select_options .= $option_row['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
3000 } else {
3001 $select_options .= $option_row['optgroup'] == 'start' ? '<li>' . $option_label . '</li>' : '';
3002 }
3003 } else {
3004 $option_label = isset( $option_row['label'] ) ? $option_row['label'] : '';
3005 $option_value = isset( $option_row['value'] ) ? $option_row['value'] : '';
3006 $selected = $option_value == $value ? 'selected="selected"' : '';
3007 $checked = '';
3008
3009 if ( ( ! is_array( $value ) && trim( $value ) != '' ) || ( is_array( $value ) && ! empty( $value ) ) ) {
3010 if ( ! is_array( $value ) ) {
3011 $value_array = explode( ',', $value );
3012 } else {
3013 $value_array = $value;
3014 }
3015
3016 if ( is_array( $value_array ) ) {
3017 if ( in_array( $option_value, $value_array ) ) {
3018 $selected = 'selected="selected"';
3019 $checked = 'checked="checked"';
3020 }
3021 }
3022 }
3023
3024 if ( $multi_display == 'select' ) {
3025 $select_options .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . '>' . $option_label . '</option>';
3026 } else {
3027 $select_options .= '<li><input name="' . $field->name . '[]" ' . $checked . ' value="' . esc_attr( $option_value ) . '" class="uwp-' . $multi_display . '" type="' . $multi_display . '" />&nbsp;' . $option_label . ' </li>';
3028 }
3029 }
3030 }
3031 }
3032 echo $select_options; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3033
3034 if ( $multi_display == 'select' ) {
3035
3036 ?>
3037 </select></div>
3038 <?php } else { ?>
3039 </ul>
3040 <?php } ?>
3041 <?php if ( $field->is_required ) { ?>
3042 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
3043 <?php } ?>
3044 </div>
3045 <?php
3046 }
3047 $html = ob_get_clean();
3048 }
3049
3050 return $html;
3051 }
3052
3053 /**
3054 * Form field template for file field type.
3055 *
3056 * @param string $html Form field html
3057 * @param object $field Field info.
3058 * @param string $value Form field default value.
3059 * @param string $form_type Form type
3060 *
3061 * @return string Modified form field html.
3062 * @package userswp
3063 *
3064 * @since 1.0.0
3065 */
3066 public function form_input_file( $html, $field, $value, $form_type ) {
3067
3068 $file_obj = new UsersWP_Files();
3069
3070 // Check if there is a field specific filter.
3071 if ( has_filter( "uwp_form_input_html_file_{$field->htmlvar_name}" ) ) {
3072 $html = apply_filters( "uwp_form_input_html_file_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3073 }
3074
3075 // If no html then we run the standard output.
3076 if ( empty( $html ) ) {
3077
3078 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
3079 $wrap_class = isset( $field->css_class ) ? $field->css_class : '';
3080 $bs_form_group = $design_style ? 'form-group mb-3' : '';
3081 $bs_sr_only = $design_style ? 'sr-only' : '';
3082 $bs_form_control = $design_style ? 'form-control' : '';
3083
3084 ob_start(); // Start buffering;
3085
3086 ?>
3087 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
3088 class="
3089 <?php
3090 if ( $field->is_required ) {
3091 echo 'required_field';
3092 }
3093 ?>
3094 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group . $wrap_class ); ?>">
3095
3096 <?php
3097 $site_title = uwp_get_form_label( $field );
3098 if ( ! is_admin() && ! wp_doing_ajax() ) {
3099 ?>
3100 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3101 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
3102 <?php
3103 if ( $field->is_required ) {
3104 echo ' <span class="text-danger">*</span>';
3105 }
3106 ?>
3107 </label>
3108 <?php } ?>
3109
3110 <?php echo $file_obj->file_upload_preview( $field, $value ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
3111 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3112 class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>"
3113 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
3114 title="<?php echo esc_attr( $site_title ); ?>"
3115 <?php
3116 if ( $field->is_required == 1 ) {
3117 echo 'data-is-required="1"';
3118 }
3119 if ( $field->is_required == 1 && ! $value ) {
3120 echo 'required="required"';
3121 }
3122 ?>
3123 type="<?php echo esc_attr( $field->field_type ); ?>">
3124 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
3125 <?php if ( $field->is_required ) { ?>
3126 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
3127 <?php } ?>
3128 </div>
3129
3130 <?php
3131 $html = ob_get_clean();
3132 }
3133
3134 return $html;
3135 }
3136
3137 /**
3138 * Form field template for checkbox field type.
3139 *
3140 * @param string $html Form field html
3141 * @param object $field Field info.
3142 * @param string $value Form field default value.
3143 * @param string $form_type Form type
3144 *
3145 * @return string Modified form field html.
3146 * @package userswp
3147 *
3148 * @since 1.0.0
3149 */
3150 public function form_input_checkbox( $html, $field, $value, $form_type ) {
3151
3152 // Check if there is a field specific filter.
3153 if ( has_filter( "uwp_form_input_html_checkbox_{$field->htmlvar_name}" ) ) {
3154 $html = apply_filters( "uwp_form_input_html_checkbox_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3155 }
3156
3157 // If no html then we run the standard output.
3158 if ( empty( $html ) ) {
3159
3160 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
3161 $bs_form_group = $design_style ? 'form-group mb-3 form-check' : '';
3162 $bs_sr_only = $design_style ? 'form-check-label' : '';
3163 $bs_form_control = $design_style ? 'form-check-input' : '';
3164
3165 ob_start(); // Start buffering;
3166 $site_title = uwp_get_form_label( $field );
3167
3168 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
3169 $id = wp_doing_ajax() ? $field->htmlvar_name . '_ajax' : $field->htmlvar_name;
3170
3171 $checked = $value == '1' ? true : false;
3172
3173 // bootstrap
3174 if ( $design_style ) {
3175 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3176
3177 echo '<input type="hidden" name="' . esc_attr( $field->htmlvar_name ) . '" id="checkbox_' . esc_attr( $id ) . '" value="0"/>';
3178
3179 echo aui()->input( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3180 array(
3181 'id' => esc_attr( $id ),
3182 'name' => esc_attr( $field->htmlvar_name ),
3183 'type' => 'checkbox',
3184 'value' => '1',
3185 'title' => esc_html( $site_title ),
3186 'label' => wp_kses_post( $site_title . $required ),
3187 'label_show' => true,
3188 'required' => ! empty( $field->is_required ) ? true : false,
3189 'checked' => (bool) $checked,
3190 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
3191 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
3192 'validation_text' => ! empty( $field->is_required ) ? esc_attr__( stripslashes( $field->required_msg ), 'userswp' ) : '',
3193 )
3194 );
3195
3196 } else {
3197 ?>
3198 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
3199 class="
3200 <?php
3201 if ( $field->is_required ) {
3202 echo 'required_field';
3203 }
3204 ?>
3205 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3206 <?php if ( ! empty( $design_style ) ) { ?>
3207 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3208 <?php } ?>
3209 <input type="hidden" name="<?php echo esc_attr( $field->htmlvar_name ); ?>" value="0"/>
3210 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3211 class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>"
3212 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
3213 title="<?php echo esc_attr( $site_title ); ?>"
3214 <?php
3215 if ( $field->is_required == 1 ) {
3216 echo 'required="required"';
3217 }
3218 ?>
3219 <?php
3220 if ( $value == '1' ) {
3221 echo 'checked="checked"';
3222 }
3223 ?>
3224 type="<?php echo esc_attr( $field->field_type ); ?>"
3225 value="1">
3226 <?php
3227 echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;';
3228 ?>
3229 <?php if ( ! empty( $design_style ) ) { ?>
3230 </label>
3231 <?php } ?>
3232 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
3233 <?php if ( $field->is_required ) { ?>
3234 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
3235 <?php } ?>
3236 </div>
3237
3238 <?php
3239
3240 }
3241
3242 $html = ob_get_clean();
3243
3244 }
3245
3246 return $html;
3247 }
3248
3249 /**
3250 * Form field template for radio field type.
3251 *
3252 * @param string $html Form field html
3253 * @param object $field Field info.
3254 * @param string $value Form field default value.
3255 * @param string $form_type Form type
3256 *
3257 * @return string Modified form field html.
3258 * @package userswp
3259 *
3260 * @since 1.0.0
3261 */
3262 public function form_input_radio( $html, $field, $value, $form_type ) {
3263
3264 // Check if there is a field specific filter.
3265 if ( has_filter( "uwp_form_input_html_radio_{$field->htmlvar_name}" ) ) {
3266 $html = apply_filters( "uwp_form_input_html_radio_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3267 }
3268
3269 // If no html then we run the standard output.
3270 if ( empty( $html ) ) {
3271
3272 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
3273 $bs_form_group = $design_style ? 'form-group mb-3 form-check-inline' : '';
3274 $bs_sr_only = $design_style ? 'sr-only' : '';
3275 $bs_label_class = $design_style ? 'form-check-label' : '';
3276 $bs_form_control = $design_style ? 'form-check-input' : '';
3277
3278 ob_start(); // Start buffering;
3279
3280 if ( $design_style ) {
3281
3282 $option_values_deep = uwp_string_values_to_options( $field->option_values, true );
3283 $option_values = array();
3284 if ( ! empty( $option_values_deep ) ) {
3285 foreach ( $option_values_deep as $option ) {
3286 $option_values[ $option['value'] ] = $option['label'];
3287 }
3288 }
3289
3290 $site_title = uwp_get_form_label( $field );
3291
3292 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3293
3294 echo aui()->radio( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3295 array(
3296 'id' => esc_attr( $field->htmlvar_name ),
3297 'name' => esc_attr( $field->htmlvar_name ),
3298 'type' => 'radio',
3299 'title' => esc_html( $site_title ),
3300 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ),
3301 'label_type' => 'top',
3302 'class' => '',
3303 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
3304 'value' => esc_attr( $value ),
3305 'options' => $option_values, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3306 )
3307 );
3308
3309 } else {
3310
3311 ?>
3312 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
3313 class="
3314 <?php
3315 if ( $field->is_required ) {
3316 echo 'required_field';
3317 }
3318 ?>
3319 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3320
3321 <?php
3322 $site_title = uwp_get_form_label( $field );
3323 if ( ! is_admin() ) {
3324 ?>
3325 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3326 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
3327 <?php
3328 if ( $field->is_required ) {
3329 echo '<span>*</span>';
3330 }
3331 ?>
3332 </label>
3333 <?php } ?>
3334
3335 <?php
3336 if ( $field->option_values ) {
3337 $option_values = uwp_string_values_to_options( $field->option_values, true );
3338
3339 if ( ! empty( $option_values ) ) {
3340 $count = 0;
3341 foreach ( $option_values as $option_value ) {
3342 if ( empty( $option_value['optgroup'] ) ) {
3343 ++$count;
3344 if ( $count == 1 ) {
3345 $class = 'uwp-radio-first';
3346 } else {
3347 $class = '';
3348 }
3349 ?>
3350 <?php if ( ! empty( $design_style ) ) { ?>
3351 <label class="<?php echo esc_attr( $bs_label_class ); ?>">
3352 <?php } else { ?>
3353 <span class="uwp-radios <?php echo esc_attr( $class ); ?>">
3354 <?php } ?>
3355 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3356 id="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3357 title="<?php echo esc_attr( $option_value['label'] ); ?>"
3358 <?php checked( $value, $option_value['value'] ); ?>
3359 <?php
3360 if ( $field->is_required == 1 ) {
3361 echo 'required="required"';
3362 }
3363 ?>
3364 value="<?php echo esc_attr( $option_value['value'] ); ?>"
3365 class="uwp-radio <?php echo esc_attr( $bs_form_control ); ?>" type="radio"/>
3366 <?php echo esc_html( $option_value['label'] ); ?>
3367 <?php if ( ! empty( $design_style ) ) { ?>
3368 </label>
3369 <?php } else { ?>
3370 </span>
3371 <?php
3372 }
3373 }
3374 }
3375 }
3376 }
3377 ?>
3378 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
3379 <?php if ( $field->is_required ) { ?>
3380 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
3381 <?php } ?>
3382 </div>
3383 <?php
3384 }
3385
3386 $html = ob_get_clean();
3387 }
3388
3389 return $html;
3390 }
3391
3392 /**
3393 * Form field template for text field type.
3394 *
3395 * @param string $html Form field html
3396 * @param object $field Field info.
3397 * @param string $value Form field default value.
3398 * @param string $form_type Form type
3399 *
3400 * @return string Modified form field html.
3401 * @package userswp
3402 *
3403 * @since 1.0.0
3404 */
3405 public function form_input_text( $html, $field, $value, $form_type ) {
3406
3407 // Check if there is a custom field specific filter.
3408 if ( has_filter( "uwp_form_input_text_{$field->htmlvar_name}" ) ) {
3409 $html = apply_filters( "uwp_form_input_text_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3410 }
3411
3412 // If no html then we run the standard output.
3413 if ( empty( $html ) ) {
3414
3415 ob_start(); // Start buffering;
3416
3417 $type = 'text';
3418 $step = false;
3419 //number and float validation $validation_pattern
3420 if ( isset( $field->data_type ) && $field->data_type == 'INT' ) {
3421 $type = 'number';
3422 } elseif ( isset( $field->data_type ) && $field->data_type == 'FLOAT' ) {
3423 $dp = $field->decimal_point;
3424 switch ( $dp ) {
3425 case '1':
3426 $step = '0.1';
3427 break;
3428 case '2':
3429 $step = '0.01';
3430 break;
3431 case '3':
3432 $step = '0.001';
3433 break;
3434 case '4':
3435 $step = '0.0001';
3436 break;
3437 case '5':
3438 $step = '0.00001';
3439 break;
3440 case '6':
3441 $step = '0.000001';
3442 break;
3443 case '7':
3444 $step = '0.0000001';
3445 break;
3446 case '8':
3447 $step = '0.00000001';
3448 break;
3449 case '9':
3450 $step = '0.000000001';
3451 break;
3452 case '10':
3453 $step = '0.0000000001';
3454 break;
3455 default:
3456 $step = '0.01';
3457 break;
3458 }
3459 $type = 'number';
3460 }
3461
3462 $site_title = uwp_get_form_label( $field );
3463 $placeholder = uwp_get_field_placeholder( $field );
3464 $manual_label = apply_filters( 'uwp_login_username_label_manual', true );
3465 if ( $manual_label
3466 && isset( $field->form_type )
3467 && $field->form_type == 'login'
3468 && $field->htmlvar_name == 'username' ) {
3469 $site_title = __( 'Username or Email', 'userswp' );
3470 $required = ! empty( $field->is_required ) ? ' *' : '';
3471 $placeholder = $site_title . $required;
3472 $placeholder = apply_filters( 'uwp_get_field_placeholder', stripslashes( $placeholder ), $field );
3473 }
3474
3475 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
3476 $bs_form_group = $design_style ? 'form-group mb-3' : '';
3477 $bs_sr_only = $design_style ? 'sr-only' : '';
3478 $bs_form_control = $design_style ? 'form-control' : '';
3479
3480 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
3481 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
3482
3483 // bootstrap
3484 if ( $design_style ) {
3485 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3486
3487 echo aui()->input(
3488 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3489 'type' => esc_attr( $type ),
3490 'id' => esc_attr( $field->htmlvar_name ),
3491 'name' => esc_attr( $field->htmlvar_name ),
3492 'placeholder' => esc_attr( $placeholder ),
3493 'title' => esc_html( $site_title ),
3494 'value' => esc_attr( wp_unslash( $value ) ),
3495 'required' => (bool) $field->is_required,
3496 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
3497 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
3498 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
3499 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ),
3500 'step' => esc_attr( $step ),
3501 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
3502 )
3503 );
3504 } else {
3505 ?>
3506 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" class="
3507 <?php
3508 if ( $field->is_required ) {
3509 echo 'required_field';
3510 }
3511 ?>
3512 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3513 <?php
3514
3515 if ( ! is_admin() ) {
3516 ?>
3517 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3518 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
3519 <?php
3520 if ( $field->is_required ) {
3521 echo '<span>*</span>';
3522 }
3523 ?>
3524 </label>
3525 <?php
3526 }
3527 ?>
3528
3529 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3530 class="<?php echo esc_attr( $field->css_class ); ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
3531 id="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3532 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
3533 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
3534 title="<?php echo esc_attr( $site_title ); ?>"
3535 oninvalid="this.setCustomValidity('<?php esc_attr_e( stripslashes( $field->required_msg ), 'userswp' ); ?>')"
3536 oninput="setCustomValidity('')"
3537 <?php
3538 if ( $field->is_required == 1 ) {
3539 echo 'required="required"';
3540 }
3541 ?>
3542 <?php
3543 if ( $field->for_admin_use == 1 ) {
3544 echo 'readonly="readonly"';
3545 }
3546 ?>
3547 type="<?php echo esc_attr( $type ); ?>"
3548 <?php
3549 if ( $step ) {
3550 echo 'step="' . esc_attr( $step ) . '"';
3551 }
3552 ?>
3553 />
3554 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
3555 <?php if ( $field->is_required ) { ?>
3556 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
3557 <?php } ?>
3558 </div>
3559
3560
3561 <?php
3562 }
3563 $html = ob_get_clean();
3564 }
3565
3566 return $html;
3567 }
3568
3569 /**
3570 * Form field template for textarea field type.
3571 *
3572 * @param string $html Form field html
3573 * @param object $field Field info.
3574 * @param string $value Form field default value.
3575 * @param string $form_type Form type
3576 *
3577 * @return string Modified form field html.
3578 * @package userswp
3579 *
3580 * @since 1.0.0
3581 */
3582 public function form_input_textarea( $html, $field, $value, $form_type ) {
3583
3584 // Check if there is a field specific filter.
3585 if ( has_filter( "uwp_form_input_textarea_{$field->htmlvar_name}" ) ) {
3586 $html = apply_filters( "uwp_form_input_textarea_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3587 }
3588
3589 // If no html then we run the standard output.
3590 if ( empty( $html ) ) {
3591
3592 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
3593 $bs_form_group = $design_style ? 'form-group mb-3' : '';
3594 $bs_sr_only = $design_style ? 'sr-only' : '';
3595 $bs_form_control = $design_style ? 'form-control' : '';
3596 $site_title = uwp_get_form_label( $field );
3597
3598 ob_start(); // Start buffering;
3599
3600 // bootstrap
3601 if ( $design_style ) {
3602 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3603
3604 echo aui()->textarea(
3605 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3606 'id' => esc_attr( $field->htmlvar_name ),
3607 'name' => esc_attr( $field->htmlvar_name ),
3608 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ),
3609 'title' => esc_html( $site_title ),
3610 'value' => wp_kses_post( stripslashes( $value ) ),
3611 'required' => (bool) $field->is_required,
3612 'validation_text' => ! empty( $field->is_required ) ? esc_attr__( stripslashes( $field->required_msg ), 'userswp' ) : '',
3613 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
3614 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ),
3615 'rows' => '4',
3616 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
3617 )
3618 );
3619 } else {
3620 ?>
3621
3622 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
3623 class="
3624 <?php
3625 if ( $field->is_required ) {
3626 echo 'required_field';
3627 }
3628 ?>
3629 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3630
3631 <?php
3632
3633 if ( ! is_admin() ) {
3634 ?>
3635 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3636 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
3637 <?php
3638 if ( $field->is_required ) {
3639 echo '<span>*</span>';
3640 }
3641 ?>
3642 </label>
3643 <?php } ?>
3644
3645 <textarea name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3646 class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>"
3647 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
3648 title="<?php echo esc_attr( $site_title ); ?>"
3649 oninvalid="this.setCustomValidity('<?php esc_attr_e( stripslashes( $field->required_msg ), 'userswp' ); ?>')"
3650 oninput="setCustomValidity('')"
3651 <?php
3652 if ( $field->is_required == 1 ) {
3653 echo 'required="required"';
3654 }
3655 ?>
3656 type="<?php echo esc_attr( $field->field_type ); ?>"
3657 rows="4"><?php echo wp_kses_post( stripslashes( $value ) ); ?></textarea>
3658 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
3659 <?php if ( $field->is_required ) { ?>
3660 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
3661 <?php } ?>
3662 </div>
3663
3664 <?php
3665 }
3666 $html = ob_get_clean();
3667 }
3668
3669 return $html;
3670 }
3671
3672 public function form_input_editor( $html, $field, $value, $form_type ) {
3673
3674 // Check if there is a field specific filter.
3675 if ( has_filter( "uwp_form_input_editor_{$field->htmlvar_name}" ) ) {
3676 $html = apply_filters( "uwp_form_input_editor_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3677 }
3678
3679 if ( empty( $html ) ) {
3680
3681 ob_start();
3682
3683 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
3684 $bs_form_group = $design_style ? 'form-group mb-3' : '';
3685 $bs_sr_only = $design_style ? 'sr-only' : '';
3686 $site_title = uwp_get_form_label( $field );
3687
3688 $content = stripslashes( $value );
3689 $editor_id = $field->htmlvar_name;
3690 $args = array(
3691 'textarea_rows' => 5,
3692 'media_buttons' => false,
3693 'quicktags' => false,
3694 );
3695
3696 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
3697 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
3698
3699 // bootstrap
3700 if ( $design_style ) {
3701 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3702
3703 echo aui()->textarea(
3704 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3705 'id' => esc_attr( $field->htmlvar_name ),
3706 'name' => esc_attr( $field->htmlvar_name ),
3707 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ),
3708 'title' => esc_html( $site_title ),
3709 'value' => wp_kses_post( stripslashes( $value ) ),
3710 'required' => (bool) $field->is_required,
3711 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
3712 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
3713 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
3714 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ),
3715 'rows' => 5,
3716 'wysiwyg' => true,
3717 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
3718 )
3719 );
3720 } else {
3721 ?>
3722 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
3723 class="
3724 <?php
3725 if ( $field->is_required ) {
3726 echo 'required_field';
3727 }
3728 ?>
3729 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3730
3731 <?php
3732
3733 if ( ! is_admin() ) {
3734 ?>
3735 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3736 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
3737 <?php
3738 if ( $field->is_required ) {
3739 echo '<span>*</span>';
3740 }
3741 ?>
3742 </label>
3743 <?php } ?>
3744
3745 <?php wp_editor( $content, $editor_id, $args ); ?>
3746
3747 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
3748 <?php if ( $field->is_required ) { ?>
3749 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
3750 <?php } ?>
3751 </div>
3752 <?php
3753 }
3754 $html = ob_get_clean();
3755 }
3756
3757 return $html;
3758 }
3759
3760 /**
3761 * Form field template for fieldset field type.
3762 *
3763 * @param string $html Form field html
3764 * @param object $field Field info.
3765 * @param string $value Form field default value.
3766 * @param string $form_type Form type
3767 *
3768 * @return string Modified form field html.
3769 * @package userswp
3770 *
3771 * @since 1.0.0
3772 */
3773 public function form_input_fieldset( $html, $field, $value, $form_type ) {
3774 // Check if there is a custom field specific filter.
3775 if ( has_filter( "uwp_form_input_fieldset_{$field->htmlvar_name}" ) ) {
3776 $html = apply_filters( "uwp_form_input_fieldset_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3777 }
3778
3779 // If no html then we run the standard output.
3780 if ( empty( $html ) ) {
3781
3782 ob_start(); // Start buffering;
3783 $site_title = uwp_get_form_label( $field );
3784 ?>
3785 <h3 class="uwp_input_fieldset <?php echo esc_attr( $field->css_class ); ?>">
3786 <?php echo esc_html( $site_title ); ?>
3787 <?php
3788 if ( $field->help_text != '' ) {
3789 echo '<small>( ' . wp_kses_post( $field->help_text ) . ' )</small>';
3790 }
3791 ?>
3792 </h3>
3793 <?php
3794 $html = ob_get_clean();
3795 }
3796
3797 return $html;
3798 }
3799
3800 /**
3801 * Form field template for url field type.
3802 *
3803 * @param string $html Form field html
3804 * @param object $field Field info.
3805 * @param string $value Form field default value.
3806 * @param string $form_type Form type
3807 *
3808 * @return string Modified form field html.
3809 * @package userswp
3810 *
3811 * @since 1.0.0
3812 */
3813 public function form_input_url( $html, $field, $value, $form_type ) {
3814
3815 // Check if there is a custom field specific filter.
3816 if ( has_filter( "uwp_form_input_url_{$field->htmlvar_name}" ) ) {
3817 $html = apply_filters( "uwp_form_input_url_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3818 }
3819
3820 // If no html then we run the standard output.
3821 if ( empty( $html ) ) {
3822
3823 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
3824 $bs_form_group = $design_style ? 'form-group mb-3' : '';
3825 $bs_sr_only = $design_style ? 'sr-only' : '';
3826 $bs_form_control = $design_style ? 'form-control' : '';
3827
3828 ob_start(); // Start buffering;
3829 $site_title = uwp_get_form_label( $field );
3830 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : __( 'Please enter a valid URL including https://', 'userswp' );
3831 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
3832
3833 // bootstrap
3834 if ( $design_style ) {
3835 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3836
3837 echo aui()->input(
3838 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3839 'type' => 'url',
3840 'id' => esc_attr( $field->htmlvar_name ),
3841 'name' => esc_attr( $field->htmlvar_name ),
3842 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ),
3843 'title' => esc_html( $site_title ),
3844 'value' => esc_attr( $value ),
3845 'required' => (bool) $field->is_required,
3846 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
3847 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
3848 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
3849 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ),
3850 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
3851 )
3852 );
3853 } else {
3854 ?>
3855 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
3856 class="
3857 <?php
3858 if ( $field->is_required ) {
3859 echo 'required_field';
3860 }
3861 ?>
3862 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3863
3864 <?php
3865 if ( ! is_admin() ) {
3866 ?>
3867 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3868 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
3869 <?php
3870 if ( $field->is_required ) {
3871 echo '<span>*</span>';
3872 }
3873 ?>
3874 </label>
3875 <?php } ?>
3876
3877 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3878 class="
3879 <?php
3880 //echo $field->css_class;
3881 ?>
3882 uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
3883 id="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3884 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
3885 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
3886 title="<?php echo esc_attr( $site_title ); ?>"
3887 <?php
3888 if ( $field->is_required == 1 ) {
3889 echo 'required="required"';
3890 }
3891 ?>
3892 type="url"
3893 oninvalid="setCustomValidity('<?php esc_attr_e( 'Please enter a valid URL including http://', 'userswp' ); ?>')"
3894 onchange="try{setCustomValidity('')}catch(e){}"
3895 />
3896 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
3897 <?php if ( $field->is_required ) { ?>
3898 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
3899 <?php } ?>
3900 </div>
3901
3902 <?php
3903 }
3904
3905 $html = ob_get_clean();
3906 }
3907
3908 return $html;
3909 }
3910
3911 /**
3912 * Form field template for email field type.
3913 *
3914 * @param string $html Form field html
3915 * @param object $field Field info.
3916 * @param string $value Form field default value.
3917 * @param string $form_type Form type
3918 *
3919 * @return string Modified form field html.
3920 * @package userswp
3921 *
3922 * @since 1.0.0
3923 */
3924 public function form_input_email( $html, $field, $value, $form_type ) {
3925
3926 // Check if there is a custom field specific filter.
3927 if ( has_filter( "uwp_form_input_email_{$field->htmlvar_name}" ) ) {
3928 $html = apply_filters( "uwp_form_input_email_{$field->htmlvar_name}", $html, $field, $value, $form_type );
3929 }
3930
3931 // If no html then we run the standard output.
3932 if ( empty( $html ) ) {
3933
3934 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
3935 $bs_form_group = $design_style ? 'form-group mb-3' : '';
3936 $bs_sr_only = $design_style ? 'sr-only' : '';
3937 $bs_form_control = $design_style ? 'form-control' : '';
3938
3939 ob_start(); // Start buffering;
3940 $site_title = uwp_get_form_label( $field );
3941 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
3942 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
3943
3944 $is_forgot_email = ( $form_type === 'forgot' && $field->htmlvar_name === 'email' );
3945 $input_type = $is_forgot_email ? 'text' : 'email';
3946 if ( $is_forgot_email ) {
3947 $site_title = __( 'Username or Email', 'userswp' );
3948 $placeholder = $site_title . ( ! empty( $field->is_required ) ? ' *' : '' );
3949 } else {
3950 $placeholder = uwp_get_field_placeholder( $field );
3951 }
3952
3953 if ( $design_style ) {
3954 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
3955
3956 echo aui()->input(
3957 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3958 'type' => $input_type,
3959 'id' => esc_attr( $field->htmlvar_name ),
3960 'name' => esc_attr( $field->htmlvar_name ),
3961 'placeholder' => esc_attr( $placeholder ),
3962 'title' => esc_html( $site_title ),
3963 'value' => esc_attr( wp_unslash( $value ) ),
3964 'required' => (bool) $field->is_required,
3965 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
3966 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
3967 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
3968 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ),
3969 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
3970 )
3971 );
3972 } else {
3973 ?>
3974 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
3975 class="
3976 <?php
3977 if ( $field->is_required ) {
3978 echo 'required_field';
3979 }
3980 ?>
3981 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
3982
3983 <?php
3984 if ( ! is_admin() ) {
3985 ?>
3986 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
3987 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
3988 <?php
3989 if ( $field->is_required ) {
3990 echo '<span>*</span>';
3991 }
3992 ?>
3993 </label>
3994 <?php } ?>
3995
3996 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3997 class="<?php echo esc_attr( $field->css_class ); ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
3998 id="<?php echo esc_attr( $field->htmlvar_name ); ?>"
3999 placeholder="<?php echo esc_attr( $placeholder ); ?>"
4000 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
4001 title="<?php echo esc_attr( $site_title ); ?>"
4002 <?php
4003 if ( $field->is_required == 1 ) {
4004 echo 'required="required"';
4005 }
4006 ?>
4007 type="<?php echo esc_attr( $input_type ); ?>"
4008 />
4009 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
4010 <?php if ( $field->is_required ) { ?>
4011 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
4012 <?php } ?>
4013 </div>
4014
4015
4016 <?php
4017 }
4018 $html = ob_get_clean();
4019
4020 }
4021
4022 if ( has_filter( "uwp_form_input_email_{$field->htmlvar_name}_after" ) ) {
4023 $html = apply_filters( "uwp_form_input_email_{$field->htmlvar_name}_after", $html, $field, $value, $form_type );
4024 }
4025
4026 return $html;
4027 }
4028
4029 /**
4030 * Form field template for password field type.
4031 *
4032 * @param string $html Form field html
4033 * @param object $field Field info.
4034 * @param string $value Form field default value.
4035 * @param string $form_type Form type
4036 *
4037 * @return string Modified form field html.
4038 * @package userswp
4039 *
4040 * @since 1.0.0
4041 */
4042 public function form_input_password( $html, $field, $value, $form_type ) {
4043
4044 // Check if there is a custom field specific filter.
4045 if ( has_filter( "uwp_form_input_password_{$field->htmlvar_name}" ) ) {
4046 $html = apply_filters( "uwp_form_input_password_{$field->htmlvar_name}", $html, $field, $value, $form_type );
4047 }
4048
4049 // If no html then we run the standard output.
4050 if ( empty( $html ) ) {
4051
4052 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
4053 $bs_form_group = $design_style ? 'form-group mb-3' : '';
4054 $bs_sr_only = $design_style ? 'sr-only' : '';
4055 $bs_form_control = $design_style ? 'form-control' : '';
4056
4057 ob_start(); // Start buffering;
4058 $site_title = uwp_get_form_label( $field );
4059
4060 if ( $design_style ) {
4061 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
4062 $required_msg = ( ! empty( $field->required_msg ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
4063 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
4064 $wrap_class = isset( $field->css_class ) ? $field->css_class . ' uwp-password-wrap' : 'uwp-password-wrap';
4065
4066 echo aui()->input(
4067 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
4068 'type' => 'password',
4069 'id' => esc_attr( $field->htmlvar_name ),
4070 'name' => esc_attr( $field->htmlvar_name ),
4071 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ),
4072 'title' => esc_html( $site_title ),
4073 'value' => esc_attr( $value ),
4074 'required' => (bool) $field->is_required,
4075 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
4076 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
4077 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
4078 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ),
4079 'wrap_class' => esc_attr( $wrap_class ),
4080 )
4081 );
4082 } else {
4083 ?>
4084 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" class="
4085 <?php
4086 if ( $field->is_required ) {
4087 echo 'required_field';
4088 }
4089 ?>
4090 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
4091 <?php
4092 if ( ! is_admin() ) {
4093 ?>
4094 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
4095 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
4096 <?php
4097 if ( $field->is_required ) {
4098 echo '<span>*</span>';
4099 }
4100 ?>
4101 </label>
4102 <?php } ?>
4103
4104 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
4105 class="<?php echo esc_attr( $field->css_class ); ?> uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
4106 id="<?php echo esc_attr( $field->htmlvar_name ); ?>"
4107 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
4108 value="<?php echo esc_attr( stripslashes( $value ) ); ?>"
4109 title="<?php echo esc_attr( $site_title ); ?>"
4110 <?php
4111 if ( $field->is_required == 1 ) {
4112 echo 'required="required"';
4113 }
4114 ?>
4115 type="password"
4116 />
4117 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
4118 <?php if ( $field->is_required ) { ?>
4119 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
4120 <?php } ?>
4121 </div>
4122
4123
4124 <?php
4125 }
4126
4127 $html = ob_get_clean();
4128 }
4129
4130 if ( has_filter( "uwp_form_input_password_{$field->htmlvar_name}_after" ) ) {
4131 $html = apply_filters( "uwp_form_input_password_{$field->htmlvar_name}_after", $html, $field, $value, $form_type );
4132 }
4133
4134 return $html;
4135 }
4136
4137 /**
4138 * Form field template for Phone field.
4139 *
4140 * @param string $html Form field html
4141 * @param object $field Field info.
4142 * @param string $value Form field default value.
4143 * @param string $form_type Form type
4144 *
4145 * @return string $html Modified form field html.
4146 * @since 1.0.0
4147 *
4148 */
4149 public function form_input_phone( $html, $field, $value, $form_type ) {
4150 if ( empty( $html ) ) {
4151 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
4152 $bs_form_group = $design_style ? 'form-group mb-3' : '';
4153 $bs_sr_only = $design_style ? 'sr-only' : '';
4154 $bs_form_control = $design_style ? 'form-control' : '';
4155 ob_start(); // Start buffering;
4156 $site_title = uwp_get_form_label( $field );
4157 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
4158 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
4159
4160 if ( $design_style ) {
4161 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
4162
4163 echo aui()->input(
4164 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
4165 'type' => 'tel',
4166 'id' => esc_attr( $field->htmlvar_name ),
4167 'name' => esc_attr( $field->htmlvar_name ),
4168 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ),
4169 'title' => esc_html( $site_title ),
4170 'value' => esc_attr( $value ),
4171 'required' => (bool) $field->is_required,
4172 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
4173 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ),
4174 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
4175 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
4176 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
4177 )
4178 );
4179 } else {
4180 ?>
4181 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
4182 class="
4183 <?php
4184 if ( $field->is_required ) {
4185 echo 'required_field';
4186 }
4187 ?>
4188 clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
4189 <?php
4190 if ( ! is_admin() ) {
4191 ?>
4192 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
4193 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
4194 <?php
4195 if ( $field->is_required ) {
4196 echo '<span>*</span>';
4197 }
4198 ?>
4199 </label>
4200 <?php } ?>
4201 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
4202 class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>"
4203 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
4204 title="<?php echo esc_attr( $site_title ); ?>"
4205 <?php
4206 if ( $field->for_admin_use == 1 ) {
4207 echo 'readonly="readonly"';
4208 }
4209 ?>
4210 <?php
4211 if ( $field->is_required == 1 ) {
4212 echo 'required="required"';
4213 }
4214 ?>
4215 type="tel"
4216 value="<?php echo esc_html( $value ); ?>">
4217 </div>
4218 <?php
4219 }
4220 $html = ob_get_clean();
4221 }
4222
4223 return $html;
4224 }
4225
4226 public function form_input_register_gdpr( $html, $field, $value, $form_type ) {
4227
4228 $form_id = isset( $field->form_id ) ? (int) $field->form_id : 1;
4229 $reg_gdpr = uwp_get_register_form_by( $form_id, 'gdpr_page' );
4230 if ( empty( $reg_gdpr ) ) {
4231 $reg_gdpr = uwp_get_option( 'register_gdpr_page', false );
4232 }
4233
4234 if ( ! empty( $reg_gdpr ) ) {
4235
4236 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
4237 $bs_form_group = $design_style ? 'form-group mb-3 form-check' : '';
4238 $bs_form_control = $design_style ? 'form-check-input' : '';
4239 $site_title = uwp_get_form_label( $field );
4240 $field->htmlvar_name = 'register_gdpr';
4241 $id = wp_doing_ajax() ? $field->htmlvar_name . '_ajax' : $field->htmlvar_name;
4242
4243 $gdpr_page = get_permalink( $reg_gdpr );
4244 $link_start = '<a href="' . esc_url( $gdpr_page ) . '" target="_blank">';
4245 $link_end = '</a>';
4246 $field_desc = uwp_get_field_description( $field, '' );
4247 $field_desc = str_replace( '%%link_start%%', $link_start, $field_desc );
4248 $field_desc = str_replace( '%%link_end%%', $link_end, $field_desc );
4249 $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>' );
4250 $checked = $value == '1' ? true : false;
4251
4252 ob_start(); // Start buffering;
4253
4254 // bootstrap
4255 if ( $design_style ) {
4256 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
4257 echo '<input type="hidden" name="' . esc_attr( $field->htmlvar_name ) . '" id="checkbox_' . esc_attr( $id ) . '" value="0"/>';
4258
4259 echo aui()->input( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
4260 array(
4261 'id' => esc_attr( $id ),
4262 'name' => esc_attr( $field->htmlvar_name ),
4263 'type' => 'checkbox',
4264 'value' => '1',
4265 'title' => esc_html( $site_title ),
4266 'label' => wp_kses_post( $content . $required ),
4267 'label_show' => true,
4268 'required' => ! empty( $field->is_required ) ? true : false,
4269 'checked' => (bool) $checked,
4270 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
4271 'validation_text' => ! empty( $field->is_required ) ? esc_attr__( stripslashes( $field->required_msg ), 'userswp' ) : '',
4272 )
4273 );
4274
4275 } else {
4276 ?>
4277 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
4278 class="
4279 <?php
4280 if ( $field->is_required ) {
4281 echo 'required_field';
4282 }
4283 ?>
4284 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
4285 <input type="hidden" name="<?php echo esc_attr( $field->htmlvar_name ); ?>" value="0"/>
4286 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
4287 class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>"
4288 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
4289 title="<?php echo esc_attr( $site_title ); ?>"
4290 <?php
4291 if ( $value == '1' ) {
4292 echo 'checked="checked"';
4293 }
4294 ?>
4295 type="<?php echo esc_attr( $field->field_type ); ?>"
4296 value="1">
4297 <?php
4298 echo ( trim( $content ) ) ? wp_kses_post( $content ) : '&nbsp;';
4299 ?>
4300 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
4301 <?php if ( $field->is_required ) { ?>
4302 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
4303 <?php } ?>
4304 </div>
4305
4306 <?php
4307 }
4308
4309 $html = ob_get_clean();
4310
4311 } else {
4312 $html = '<input type="hidden" name="register_gdpr" value="-1"/>';
4313 }
4314
4315 return $html;
4316 }
4317
4318 public function form_input_register_tos( $html, $field, $value, $form_type ) {
4319
4320 $form_id = isset( $field->form_id ) ? (int) $field->form_id : 1;
4321 $reg_tos = uwp_get_register_form_by( $form_id, 'tos_page' );
4322 if ( empty( $reg_tos ) ) {
4323 $reg_tos = uwp_get_option( 'register_terms_page', false );
4324 }
4325
4326 if ( ! empty( $reg_tos ) ) {
4327
4328 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
4329 $bs_form_group = $design_style ? 'form-group mb-3 form-check' : '';
4330 $bs_form_control = $design_style ? 'form-check-input' : '';
4331
4332 $site_title = uwp_get_form_label( $field );
4333 $terms_page = get_permalink( $reg_tos );
4334 $link_start = '<a href="' . esc_url( $terms_page ) . '" target="_blank">';
4335 $link_end = '</a>';
4336 $field_desc = uwp_get_field_description( $field, '' );
4337 $field_desc = str_replace( '%%link_start%%', $link_start, $field_desc );
4338 $field_desc = str_replace( '%%link_end%%', $link_end, $field_desc );
4339 $field->htmlvar_name = 'register_tos';
4340 $id = wp_doing_ajax() ? $field->htmlvar_name . '_ajax' : $field->htmlvar_name;
4341
4342 $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>' );
4343 $checked = $value == '1' ? true : false;
4344
4345 ob_start();
4346
4347 if ( $design_style ) {
4348 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
4349 echo '<input type="hidden" name="' . esc_attr( $field->htmlvar_name ) . '" id="checkbox_' . esc_attr( $id ) . '" value="0"/>';
4350
4351 echo aui()->input( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
4352 array(
4353 'id' => esc_attr( $id ),
4354 'name' => esc_attr( $field->htmlvar_name ),
4355 'type' => 'checkbox',
4356 'value' => '1',
4357 'title' => esc_html( $site_title ),
4358 'label' => wp_kses_post( $content . $required ),
4359 'label_show' => true,
4360 'required' => ! empty( $field->is_required ) ? true : false,
4361 'checked' => (bool) $checked,
4362 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
4363 'validation_text' => ! empty( $field->is_required ) ? esc_attr__( stripslashes( $field->required_msg ), 'userswp' ) : '',
4364 )
4365 );
4366
4367 } else {
4368 ?>
4369 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
4370 class="
4371 <?php
4372 if ( $field->is_required ) {
4373 echo 'required_field';
4374 }
4375 ?>
4376 uwp_form_<?php echo esc_attr( $field->field_type ); ?>_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
4377 <input type="hidden" name="<?php echo esc_attr( $field->htmlvar_name ); ?>" value="0"/>
4378 <input name="<?php echo esc_attr( $field->htmlvar_name ); ?>"
4379 class="<?php echo esc_attr( $field->css_class ); ?> <?php echo esc_attr( $bs_form_control ); ?>"
4380 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
4381 title="<?php echo esc_attr( $site_title ); ?>"
4382 <?php
4383 if ( $value == '1' ) {
4384 echo 'checked="checked"';
4385 }
4386 ?>
4387 type="<?php echo esc_attr( $field->field_type ); ?>"
4388 value="1">
4389 <?php
4390 echo ( trim( $content ) ) ? wp_kses_post( $content ) : '&nbsp;';
4391 ?>
4392 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
4393 <?php if ( $field->is_required ) { ?>
4394 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
4395 <?php } ?>
4396 </div>
4397
4398 <?php
4399
4400 }
4401
4402 $html = ob_get_clean();
4403
4404 } else {
4405 $html = '<input type="hidden" name="register_tos" value="-1"/>';
4406 }
4407
4408 return $html;
4409 }
4410
4411 /**
4412 * Adds enctype tag in form for file fields.
4413 *
4414 * @return void
4415 * @package userswp
4416 *
4417 * @since 1.0.0
4418 */
4419 function add_multipart_to_admin_edit_form() {
4420 global $wpdb;
4421 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
4422 $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
4423 if ( $fields ) {
4424 echo 'enctype="multipart/form-data"';
4425 }
4426 }
4427
4428 /**
4429 * Handles UsersWP custom field requests from admin.
4430 *
4431 * @param int $user_id User ID.
4432 *
4433 * @return void
4434 * @since 1.0.0
4435 * @package userswp
4436 *
4437 */
4438 public function update_profile_extra_admin_edit( $user_id ) {
4439 global $wpdb;
4440 $file_obj = new UsersWP_Files();
4441 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
4442 //Normal fields
4443 $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
4444 if ( $fields ) {
4445 if ( isset( $_POST['locale'] ) ) {
4446 $_POST['uwp_language'] = sanitize_text_field( $_POST['locale'] );
4447 }
4448 $result = uwp_validate_fields( $_POST, 'account', $fields );
4449 if ( is_wp_error( $result ) ) {
4450 die( wp_kses_post( $result->get_error_message() ) );
4451 }
4452 if ( isset( $result['display_name'] ) && ! empty( $result['display_name'] ) ) {
4453 $display_name = $result['display_name'];
4454 } elseif ( ! empty( $first_name ) || ! empty( $last_name ) ) {
4455 $display_name = $result['first_name'] . ' ' . $result['last_name'];
4456 } else {
4457 $user_info = get_userdata( $user_id );
4458 $display_name = $user_info->user_login;
4459 }
4460 $result['display_name'] = $display_name;
4461 if ( ! is_wp_error( $result ) ) {
4462 foreach ( $fields as $field ) {
4463 $value = isset( $result[ $field->htmlvar_name ] ) ? $result[ $field->htmlvar_name ] : '';
4464 if ( $value == '0' || ! empty( $value ) ) {
4465 uwp_update_usermeta( $user_id, $field->htmlvar_name, $value );
4466 }
4467 }
4468 }
4469 }
4470
4471 //File fields
4472 $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
4473 if ( $fields ) {
4474 $result = $file_obj->validate_uploads( $_FILES, 'account', true, $fields );
4475 if ( ! is_wp_error( $result ) ) {
4476 foreach ( $fields as $field ) {
4477 $value = isset( $result[ $field->htmlvar_name ] ) ? $result[ $field->htmlvar_name ] : '';
4478 if ( $value == '0' || ! empty( $value ) ) {
4479 uwp_update_usermeta( $user_id, $field->htmlvar_name, $value );
4480 }
4481 }
4482 }
4483 }
4484 }
4485
4486 /**
4487 * Form field template for country field.
4488 *
4489 * @param string $html Form field html
4490 * @param object $field Field info.
4491 * @param string $value Form field default value.
4492 * @param string $form_type Form type
4493 *
4494 * @return string Modified form field html.
4495 * @package userswp
4496 *
4497 * @since 1.0.0
4498 */
4499 public function form_input_select_country( $html, $field, $value, $form_type ) {
4500
4501 // If no html then we run the standard output.
4502 if ( empty( $html ) ) {
4503
4504 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
4505 $bs_form_group = $design_style ? 'form-group m-0' : ''; // country wrapper div added by JS adds margin so we remove ours
4506 $bs_sr_only = $design_style ? 'sr-only' : '';
4507 $bs_form_control = $design_style ? 'form-control' : '';
4508
4509 ob_start(); // Start buffering;
4510 ?>
4511 <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 ); ?>">
4512
4513 <?php
4514 $site_title = uwp_get_form_label( $field );
4515
4516 if ( ! is_admin() && ! wp_doing_ajax() ) {
4517 ?>
4518 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
4519 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
4520 <?php
4521 if ( $field->is_required ) {
4522 echo '<span class="text-danger">*</span>';
4523 }
4524 ?>
4525 </label>
4526 <?php
4527 }
4528 // if value empty set the default
4529 if ( $value == '' && isset( $field->default_value ) && $field->default_value ) {
4530 $value = $field->default_value;
4531 }
4532 if ( $value === false ) {
4533 $value = '';
4534 }
4535 $select_country_options = wp_json_encode( array( 'defaultCountry' => wp_unslash( $value ) ) );
4536 $select_country_options = apply_filters( 'uwp_form_input_select_country', $select_country_options, $field, $value, $form_type );
4537
4538 $htmlvar_name = $field->htmlvar_name;
4539 if ( wp_doing_ajax() ) {
4540 $htmlvar_name .= '_ajax';
4541 }
4542 ?>
4543 <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 ); ?>"/>
4544 <input type="hidden" id="<?php echo esc_attr( $htmlvar_name ); ?>_code" name="<?php echo esc_attr( $field->htmlvar_name ); ?>"/>
4545 <script>jQuery(function(){jQuery("#<?php echo esc_js( $htmlvar_name ); ?>").countrySelect(<?php echo wp_json_encode( json_decode( $select_country_options ) ); ?>);});</script>
4546 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
4547 <?php if ( $field->is_required ) { ?>
4548 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
4549 <?php } ?>
4550 </div>
4551 <?php
4552 $html = ob_get_clean();
4553 }
4554
4555 return $html;
4556 }
4557
4558 /**
4559 * Form field template for language field.
4560 *
4561 * @param string $html Form field html
4562 * @param object $field Field info.
4563 * @param string $value Form field default value.
4564 * @param string $form_type Form type
4565 *
4566 * @return string Modified form field html.
4567 * @package userswp
4568 *
4569 * @since 1.0.0
4570 */
4571 public function form_input_uwp_language( $html, $field, $value, $form_type ) {
4572
4573 // If no html then we run the standard output.
4574 if ( empty( $html ) ) {
4575
4576 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
4577 $bs_form_group = $design_style ? 'form-group m-0' : '';
4578 $bs_sr_only = $design_style ? 'sr-only' : '';
4579 $bs_form_control = $design_style ? 'form-control' : '';
4580 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
4581 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
4582
4583 ob_start(); // Start buffering;
4584
4585 ?>
4586 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
4587 class="
4588 <?php
4589 if ( $field->is_required ) {
4590 echo 'required_field';
4591 }
4592 ?>
4593 uwp_clear <?php echo esc_attr( $bs_form_group . ' ' . $field->css_class ); ?>">
4594
4595 <?php
4596 $site_title = uwp_get_form_label( $field );
4597 if ( ! is_admin() && ! wp_doing_ajax() ) {
4598 ?>
4599 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
4600 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
4601 <?php
4602 if ( $field->is_required ) {
4603 echo '<span class="text-danger">*</span>';
4604 }
4605 ?>
4606 </label>
4607 <?php } ?>
4608
4609 <?php
4610 if ( empty( $field->default_value ) ) {
4611 $field->default_value = 'site-default';
4612 }
4613
4614 // if value empty set the default
4615 if ( $value == '' && isset( $field->default_value ) && $field->default_value ) {
4616 $value = $field->default_value;
4617 }
4618
4619 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
4620 $translations = wp_get_available_translations();
4621 $available_languages = get_available_languages();
4622 $languages = array( 'site-default' => __( 'Site Default', 'userswp' ) );
4623
4624 foreach ( $available_languages as $locale ) {
4625 if ( isset( $translations[ $locale ] ) ) {
4626 $translation = $translations[ $locale ];
4627 $languages[ $translation['language'] ] = $translation['native_name'];
4628
4629 // Remove installed language from available translations.
4630 unset( $translations[ $locale ] );
4631 } else {
4632 $languages[ $locale ] = $translation[ $locale ];
4633 }
4634 }
4635
4636 if ( $design_style ) {
4637
4638 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
4639
4640 echo aui()->select(
4641 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
4642 'id' => esc_attr( $field->htmlvar_name ),
4643 'name' => esc_attr( $field->htmlvar_name ),
4644 'placeholder' => esc_attr( uwp_get_field_placeholder( $field ) ),
4645 'title' => esc_attr( $site_title ),
4646 'value' => esc_attr( $value ),
4647 'required' => (bool) $field->is_required,
4648 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
4649 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
4650 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
4651 'label' => wp_kses_post( $site_title . $required ),
4652 'options' => $languages, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
4653 'select2' => true,
4654 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '',
4655 )
4656 );
4657 } else {
4658 ?>
4659 <select name="<?php echo esc_attr( $field->htmlvar_name ); ?>" id="<?php echo esc_attr( $field->htmlvar_name ); ?>"
4660 class="uwp_textfield aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
4661 title="<?php echo esc_attr( $site_title ); ?>"
4662 data-placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
4663 ><?php echo $select_options; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
4664 </select>
4665 <span class="uwp_message_note"><?php echo wp_kses_post( uwp_get_field_description( $field ) ); ?></span>
4666 <?php if ( $field->is_required ) { ?>
4667 <span class="uwp_message_error invalid-feedback"><?php echo esc_html__( stripslashes( $field->required_msg ), 'userswp' ); ?></span>
4668 <?php
4669 }
4670 }
4671
4672 $html = ob_get_clean();
4673 }
4674
4675 return $html;
4676 }
4677
4678 /**
4679 * Adds confirm password field in forms.
4680 *
4681 * @param string $html Form field html
4682 * @param object $field Field info.
4683 * @param string $value Form field default value.
4684 * @param string $form_type Form type
4685 *
4686 * @return string Modified form field html.
4687 * @package userswp
4688 *
4689 * @since 1.0.0
4690 */
4691 public function register_confirm_password_field( $html, $field, $value, $form_type ) {
4692 if ( $form_type == 'register' ) {
4693 //confirm password field
4694 $extra = array();
4695 if ( isset( $field->extra_fields ) && $field->extra_fields != '' ) {
4696 $extra = unserialize( $field->extra_fields );
4697 }
4698
4699 $enable_confirm_password_field = isset( $extra['confirm_password'] ) ? $extra['confirm_password'] : '0';
4700 if ( $enable_confirm_password_field == '1' ) {
4701
4702 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
4703 $bs_form_group = $design_style ? 'form-group mb-3' : '';
4704 $bs_sr_only = $design_style ? 'sr-only' : '';
4705 $bs_form_control = $design_style ? 'form-control' : '';
4706 $site_title = $placeholder = __( 'Confirm Password', 'userswp' );
4707 $required = '';
4708 if ( isset( $field->is_required ) && ! empty( $field->is_required ) ) {
4709 $placeholder .= ' *';
4710 $required = ' <span class="text-danger">*</span>';
4711 }
4712 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
4713 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
4714 $wrap_class = isset( $field->css_class ) ? $field->css_class . ' uwp-password-wrap' : 'uwp-password-wrap';
4715
4716 ob_start(); // Start buffering;
4717
4718 if ( $design_style ) {
4719
4720 echo aui()->input(
4721 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
4722 'type' => 'password',
4723 'id' => 'confirm_password',
4724 'name' => 'confirm_password',
4725 'placeholder' => esc_attr( $placeholder ),
4726 'title' => esc_attr( $site_title ),
4727 'value' => esc_attr( $value ),
4728 'required' => (bool) $field->is_required,
4729 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
4730 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ),
4731 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
4732 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
4733 'wrap_class' => esc_attr( $wrap_class ),
4734 )
4735 );
4736 } else {
4737 ?>
4738 <div id="uwp_account_confirm_password_row"
4739 class="<?php echo 'required_field'; ?> uwp_form_password_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
4740
4741 <?php
4742
4743 if ( ! is_admin() ) {
4744 ?>
4745 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
4746 <?php echo ( trim( $site_title ) ) ? esc_html( $site_title ) : '&nbsp;'; ?>
4747 <?php
4748 if ( $field->is_required ) {
4749 echo '<span>*</span>';
4750 }
4751 ?>
4752 </label>
4753 <?php } ?>
4754 <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"/>
4755 </div>
4756
4757 <?php
4758 }
4759 $confirm_html = ob_get_clean();
4760 $html = $html . $confirm_html;
4761 }
4762 }
4763
4764 return $html;
4765 }
4766
4767 /**
4768 * Adds confirm email field in forms.
4769 *
4770 * @param string $html Form field html
4771 * @param object $field Field info.
4772 * @param string $value Form field default value.
4773 * @param string $form_type Form type
4774 *
4775 * @return string Modified form field html.
4776 * @package userswp
4777 *
4778 * @since 1.0.0
4779 */
4780 public function register_confirm_email_field( $html, $field, $value, $form_type ) {
4781 if ( $form_type == 'register' ) {
4782 //confirm email field
4783 $extra = array();
4784 if ( isset( $field->extra_fields ) && $field->extra_fields != '' ) {
4785 $extra = unserialize( $field->extra_fields );
4786 }
4787 $enable_confirm_email_field = isset( $extra['confirm_email'] ) ? $extra['confirm_email'] : '0';
4788 if ( $enable_confirm_email_field == '1' ) {
4789
4790 $design_style = uwp_get_option( 'design_style', 'bootstrap' );
4791 $bs_form_group = $design_style ? 'form-group mb-3' : '';
4792 $bs_sr_only = $design_style ? 'sr-only' : '';
4793 $bs_form_control = $design_style ? 'form-control' : '';
4794 $site_title = __( 'Confirm Email', 'userswp' );
4795 $required_msg = ( ! empty( $field->is_required ) && $field->required_msg != '') ? __( stripslashes( $field->required_msg ), 'userswp' ) : '';
4796 $validation_text = ! empty( $field->validation_msg ) ? __( stripslashes( $field->validation_msg ), 'userswp' ) : '';
4797
4798 ob_start();
4799
4800 if ( $design_style ) {
4801 $required = ! empty( $field->is_required ) ? ' <span class="text-danger">*</span>' : '';
4802
4803 echo aui()->input(
4804 array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
4805 'type' => 'email',
4806 'id' => esc_attr( $field->htmlvar_name ),
4807 'name' => 'confirm_email',
4808 'placeholder' => esc_attr( $site_title ),
4809 'title' => esc_attr( $site_title ),
4810 'value' => esc_attr( $value ),
4811 'required' => (bool) $field->is_required,
4812 'help_text' => wp_kses_post( uwp_get_field_description( $field ) ),
4813 'label' => is_admin() && ! wp_doing_ajax() ? '' : wp_kses_post( $site_title . $required ),
4814 'validation_text' => $validation_text != '' ? esc_attr( $validation_text ) : esc_attr( $required_msg ),
4815 'validation_pattern' => ! empty( $field->validation_pattern ) ? esc_attr( wp_unslash( $field->validation_pattern ) ) : '',
4816 )
4817 );
4818 } else {
4819 ?>
4820 <div id="uwp_account_confirm_email_row"
4821 class="<?php echo 'required_field'; ?> uwp_form_email_row uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
4822
4823 <?php
4824
4825 if ( ! is_admin() ) {
4826 ?>
4827 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
4828 <?php echo ( trim( $site_title ) ) ? esc_attr( $site_title ) : '&nbsp;'; ?>
4829 <?php
4830 if ( $field->is_required ) {
4831 echo '<span>*</span>';
4832 }
4833 ?>
4834 </label>
4835 <?php } ?>
4836
4837 <input name="confirm_email"
4838 class="uwp_textfield <?php echo esc_attr( $bs_form_control ); ?>"
4839 id="uwp_account_confirm_email"
4840 placeholder="<?php echo esc_attr( $site_title ); ?>"
4841 value=""
4842 title="<?php echo esc_attr( $site_title ); ?>"
4843 <?php echo 'required="required"'; ?>
4844 type="email"
4845 />
4846 </div>
4847 <?php
4848 }
4849 $confirm_html = ob_get_clean();
4850 $html = $html . $confirm_html;
4851 }
4852 }
4853
4854 return $html;
4855 }
4856
4857 /**
4858 * Handles the privacy form submission.
4859 *
4860 * @return void
4861 * @package userswp
4862 *
4863 * @since 1.0.0
4864 */
4865 public function privacy_submit_handler() {
4866 if ( isset( $_POST['uwp_privacy_submit'] ) ) {
4867 if ( ! isset( $_POST['uwp_privacy_nonce'] ) || ! wp_verify_nonce( $_POST['uwp_privacy_nonce'], 'uwp-privacy-nonce' ) ) {
4868 return;
4869 }
4870
4871 global $wpdb, $uwp_notices;
4872
4873 // Save fields privacy settings
4874 $extra_where = "AND is_public='2'";
4875 $fields = get_account_form_fields( $extra_where );
4876 $fields = apply_filters( 'uwp_account_privacy_fields', $fields );
4877 $user_id = get_current_user_id();
4878 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
4879
4880 $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
4881 if ( ! empty( $user_meta_info->user_privacy ) ) {
4882 $public_fields = explode( ',', $user_meta_info->user_privacy );
4883 } else {
4884 $public_fields = array();
4885 }
4886
4887 if ( $fields ) {
4888
4889 foreach ( $fields as $field ) {
4890 $field_name = $field->htmlvar_name . '_privacy';
4891 $field_value = strip_tags( esc_sql( $_POST[ $field_name ] ) );
4892
4893 if ( $field_value == 'no' ) {
4894 if ( ! in_array( $field_name, $public_fields ) ) {
4895 $public_fields[] = $field_name;
4896 }
4897 } elseif ( ( $field_name = array_search( $field_name, $public_fields ) ) !== false ) {
4898 unset( $public_fields[ $field_name ] );
4899 }
4900 }
4901
4902 $value = implode( ',', $public_fields );
4903 uwp_update_usermeta( $user_id, 'user_privacy', $value );
4904 }
4905
4906 // Save tabs privacy settings
4907 $tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs';
4908 $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
4909
4910 if ( $tabs ) {
4911 $public_fields = maybe_unserialize( $user_meta_info->tabs_privacy );
4912 $do_tabs_update = false;
4913 foreach ( $tabs as $tab ) {
4914 $field_name = $tab->tab_key . '_tab_privacy';
4915
4916 if ( isset( $_POST[ $field_name ] ) ) {
4917 $do_tabs_update = true;
4918 $field_value = $_POST[ $field_name ] == '' ? '' : absint( $_POST[ $field_name ] );
4919
4920 if ( $field_value === '' && isset( $public_fields[ $field_name ] ) ) {
4921 unset( $public_fields[ $field_name ] );
4922 } else {
4923 $public_fields[ $field_name ] = $field_value;
4924 }
4925 }
4926 }
4927
4928 if ( $do_tabs_update ) {
4929 uwp_update_usermeta( $user_id, 'tabs_privacy', maybe_serialize( $public_fields ) );
4930 }
4931 }
4932
4933 if ( isset( $_POST['uwp_hide_from_listing'] ) && 1 == $_POST['uwp_hide_from_listing'] ) {
4934 update_user_meta( $user_id, 'uwp_hide_from_listing', 1 );
4935 } else {
4936 update_user_meta( $user_id, 'uwp_hide_from_listing', 0 );
4937 }
4938
4939 $make_profile_private = uwp_can_make_profile_private();
4940 if ( $make_profile_private ) {
4941 $field_name = 'uwp_make_profile_private';
4942 if ( isset( $_POST[ $field_name ] ) ) {
4943 $value = strip_tags( esc_sql( $_POST[ $field_name ] ) );
4944 $user_id = get_current_user_id();
4945 update_user_meta( $user_id, $field_name, $value );
4946 }
4947 }
4948
4949 $message = apply_filters( 'uwp_privacy_update_success_message', __( 'Privacy settings updated successfully.', 'userswp' ) );
4950 $message = aui()->alert(
4951 array(
4952 'type' => 'success',
4953 'content' => $message,
4954 )
4955 );
4956 $uwp_notices[] = array( 'account' => $message );
4957
4958 }
4959 }
4960
4961 /**
4962 * Get the ajax login form.
4963 *
4964 * @since 1.2.0
4965 */
4966 public function ajax_login_form() {
4967
4968 // add the modal error container
4969 add_action( 'uwp_template_display_notices', array( $this, 'modal_error_container' ) );
4970
4971 $args = array(
4972 'form_title' => __( 'Login', 'userswp' ),
4973 );
4974
4975 // get the form
4976 ob_start();
4977 uwp_get_template( 'bootstrap/login.php', $args );
4978 $form = ob_get_clean();
4979
4980 // bs5
4981 if ( function_exists( 'aui_bs_convert_sd_output' ) ) {
4982 $form = aui_bs_convert_sd_output( $form );
4983 }
4984 // send ajax response
4985 wp_send_json_success( $form );
4986 }
4987
4988 /**
4989 * Get the ajax register form.
4990 *
4991 * @since 1.2.0
4992 */
4993 public function ajax_register_form() {
4994
4995 // add the modal error container
4996 add_action( 'uwp_template_display_notices', array( $this, 'modal_error_container' ) );
4997
4998 global $wp_scripts;
4999 if ( empty( $wp_scripts ) ) {
5000 $wp_scripts = wp_scripts();
5001 }
5002
5003 // do we need country code script in ajax?
5004 $country_field = false;
5005 $lightbox_forms = uwp_get_option( 'register_modal_form', 1 );
5006
5007 if ( isset( $_POST['form_id'] ) && ! empty( $_POST['form_id'] ) ) {
5008 $form_id = (int)$_POST['form_id'];
5009 } elseif ( is_array( $lightbox_forms ) && count( $lightbox_forms ) > 0 ) {
5010 $form_id = reset( $lightbox_forms );
5011 } else {
5012 $form_id = 1;
5013 }
5014
5015 $fields = get_register_form_fields( $form_id );
5016 if ( ! empty( $fields ) ) {
5017 foreach ( $fields as $field ) {
5018 if ( $field->field_type_key == 'country' || $field->field_type_key == 'uwp_country' ) {
5019 $country_field = true;
5020 }
5021 }
5022 }
5023
5024 ob_start();
5025
5026 // maybe add country code JS
5027 if ( $country_field ) {
5028 $country_data = uwp_get_country_data();
5029 echo '<script>var uwp_country_data = ' . json_encode( $country_data ) . '</script>';
5030 echo "<script type='text/javascript' src='" . esc_url( USERSWP_PLUGIN_URL ) . 'assets/js/countrySelect.min.js' . "' ></script>";
5031 }
5032
5033 $args = array( 'form_title' => '' );
5034 if ( $form_id > 0 ) {
5035 $args['id'] = $form_id;
5036 }
5037
5038 $args['limit'] = $lightbox_forms;
5039
5040 // get template
5041 uwp_get_template( 'bootstrap/register.php', $args );
5042
5043 // only show the JS if NOT doing a block render
5044 if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] != 'super_duper_output_shortcode' ) {
5045 // load scripts
5046 $wp_scripts->do_item( 'zxcvbn-async' );
5047 $wp_scripts->do_item( 'wp-hooks' );
5048 $wp_scripts->do_item( 'wp-i18n' );
5049 $wp_scripts->do_item( 'password-strength-meter' );
5050 ?>
5051 <script>
5052 // Password strength indicator script
5053 jQuery(function ($) {
5054
5055 // Load the settings like WP does.
5056 var first, s;
5057 s = document.createElement('script');
5058 s.src = _zxcvbnSettings.src;
5059 s.type = 'text/javascript';
5060 s.async = true;
5061 first = document.getElementsByTagName('script')[0];
5062 first.parentNode.insertBefore(s, first);
5063
5064 // Enable any pass inputs.
5065 $('body').on('keyup', 'input[name=password], input[name=confirm_password]',
5066 function (event) {
5067 var $form = $(this).closest('form');
5068 if( ! $form.hasClass('uwp-login-form') ) {
5069 uwp_checkPasswordStrength(
5070 $form.find('input[name=password]'),
5071 $form.find('input[name=confirm_password]'),
5072 $form.find('#uwp-password-strength'),
5073 $form.find('button[type="submit"], input[type="submit"]'),
5074 ['black', 'listed', 'word']
5075 );
5076 }
5077 }
5078 );
5079 });
5080 </script>
5081 <?php
5082 }
5083 $form = ob_get_clean();
5084
5085 // bs5
5086 if ( function_exists( 'aui_bs_convert_sd_output' ) ) {
5087 $form = aui_bs_convert_sd_output( $form );
5088 }
5089
5090 // send ajax response
5091 wp_send_json_success( $form );
5092 }
5093
5094 /**
5095 * Get the ajax forgot password form.
5096 *
5097 * @since 1.2.0
5098 */
5099 public function ajax_forgot_password_form() {
5100
5101 // add the modal error container
5102 add_action( 'uwp_template_display_notices', array( $this, 'modal_error_container' ) );
5103 $args = array(
5104 'form_title' => '',
5105 'css_class' => ''
5106 );
5107 // get the form
5108 ob_start();
5109 uwp_get_template( 'bootstrap/forgot.php', $args );
5110 $form = ob_get_clean();
5111
5112 // bs5
5113 if ( function_exists( 'aui_bs_convert_sd_output' ) ) {
5114 $form = aui_bs_convert_sd_output( $form );
5115 }
5116
5117 // send ajax response
5118 wp_send_json_success( $form );
5119 }
5120
5121 /**
5122 * Output the modal error container.
5123 *
5124 * @param string $type
5125 *
5126 * @since 1.2.0
5127 */
5128 public function modal_error_container( $type = '' ) {
5129 echo '<div class="form-group mb-3"><div class="modal-error"></div></div>';
5130 }
5131
5132 public function form_custom_html( $html, $field, $value, $form_type ) {
5133
5134 $html = ! empty( $field->default_value ) ? $field->default_value : ' ';
5135
5136 return $html;
5137 }
5138 }
5139