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

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