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