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

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