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

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