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

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