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