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

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

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