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

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