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

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