PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.3.4
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.3.4
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / includes / class-forms.php

class-forms.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.3.4, at includes/class-forms.php

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