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