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

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