PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
← All changes | front-end/class-formbuilder.php +76 -33 3.15.94.0.3 View file →
@@ -38,8 +38,16 @@
38 38 if( $this->args['form_name'] != 'unspecified' ){
39 39 $this->args['ID'] = Profile_Builder_Form_Creator::wppb_get_form_id_from_form_name( $this->args['form_name'], $this->args['form_type'] );
40 40 }
41 41
42 + /* Let add-ons finalise the form args once ID/form_name are resolved.
43 + The form-builder hooks this (wppb_fb_resolve_default_form_id) to point
44 + a shortcode with no form specified (empty ID) at the configured
45 + default form CPT, so [wppb-register] / [wppb-edit-profile] render the
46 + default form. Must run before the wppb_change_form_fields filter below
47 + (multiple-forms reads $this->args['ID'] to pick the per-form list). */
48 + $this->args = apply_filters( 'wppb_form_args_after_init', $this->args );
49 +
42 50 global $wppb_shortcode_on_front;
43 51 $wppb_shortcode_on_front = true;
44 52
45 53 global $wppb_register_edit_profile_shortcode_on_front;
@@ -58,9 +66,12 @@
58 66
59 67 if( defined( 'WPPB_PAID_PLUGIN_DIR' ) && isset( $this->args['ajax'] ) && $this->args['ajax'] === 'true' && file_exists( WPPB_PAID_PLUGIN_DIR . '/features/ajax/assets/forms-ajax-validation.js' ) ) {
60 68 wp_enqueue_script( 'wppb-forms-ajax-validation-script', WPPB_PAID_PLUGIN_URL . 'features/ajax/assets/forms-ajax-validation.js', array( 'jquery' ), PROFILE_BUILDER_VERSION, true );
61 69 wp_localize_script( 'wppb-forms-ajax-validation-script', 'submitButtonData', array( 'processingText' => __( 'Processing...', 'profile-builder' ) ) );
62 - wp_enqueue_editor();
70 +
71 + // AJAX validation re-renders the form and needs editor assets only when a WYSIWYG field must be reinitialized
72 + if( apply_filters( 'wppb_ajax_form_should_enqueue_editor', $this->wppb_form_has_wysiwyg_field( $this->args['form_fields'] ), $this->args, $this ) )
73 + wp_enqueue_editor();
63 74 }
64 75
65 76 // NOTE: for Multisite, the capability we check against is `remove_users` because `edit_users` is on the do not allow on multisite list for current_user_can()
66 77 // current_user_can( 'edit_users' ) will only return true on a Multisite for Super Administrator Users
@@ -156,14 +167,35 @@
156 167 $role_in_arg = get_role( $this->args['role'] );
157 168 if( !empty( $role_in_arg->capabilities['manage_options'] ) || !empty( $role_in_arg->capabilities['remove_users'] ) ){
158 169 if( !current_user_can( 'manage_options' ) || !current_user_can( 'remove_users' ) ){
159 170 $this->args['role'] = get_option('default_role');
160 - echo wp_kses_post( apply_filters( 'wppb_register_pre_form_user_role_message', '<p class="alert wppb-error" id="wppb_form_general_message">'.__( 'The role of the created user set to the default role. Only an administrator can register a user with the role assigned to this form.', 'profile-builder').'</p>' ) );
171 + echo wp_kses_post( apply_filters( 'wppb_register_pre_form_user_role_message', '<p class="alert wppb-error" id="wppb_form_general_message" role="alert">'.__( 'The role of the created user set to the default role. Only an administrator can register a user with the role assigned to this form.', 'profile-builder').'</p>' ) );
161 172 }
162 173 }
163 174 }
164 175 }
165 176
177 + /**
178 + * Check whether the current form field list contains a WYSIWYG field
179 + *
180 + * @param array $form_fields The form fields configured for the current form.
181 + * @return bool True when a WYSIWYG field is present, false otherwise.
182 + */
183 + function wppb_form_has_wysiwyg_field( $form_fields ){
184 + if( empty( $form_fields ) || !is_array( $form_fields ) )
185 + return false;
186 +
187 + foreach( $form_fields as $field ){
188 + if( empty( $field['field'] ) )
189 + continue;
190 +
191 + if( $field['field'] === 'WYSIWYG' )
192 + return true;
193 + }
194 +
195 + return false;
196 + }
197 +
166 198 function wppb_form_logic() {
167 199 if( isset( $this->args['form_type'] ) ) {
168 200 if( $this->args['form_type'] == 'register' ){
169 201 $registration = apply_filters ( 'wppb_register_setting_override', true );//used to be get_option( 'users_can_register' )
@@ -169,9 +201,9 @@
169 201 $registration = apply_filters ( 'wppb_register_setting_override', true );//used to be get_option( 'users_can_register' )
170 202
171 203 if ( !is_user_logged_in() ){
172 204 if ( !$registration )
173 - echo wp_kses_post( apply_filters( 'wppb_register_pre_form_message', '<p class="alert" id="wppb_register_pre_form_message">'.esc_html(__( 'Only an administrator can add new users.', 'profile-builder')).'</p>' ) );
205 + echo wp_kses_post( apply_filters( 'wppb_register_pre_form_message', '<p class="alert" id="wppb_register_pre_form_message" role="alert">'.esc_html(__( 'Only an administrator can add new users.', 'profile-builder')).'</p>' ) );
174 206
175 207 elseif ( $registration ){
176 208 $this->wppb_form_content( apply_filters( 'wppb_register_pre_form_message', '' ) );
177 209 }
@@ -179,12 +211,12 @@
179 211 }else{
180 212 $current_user_capability = apply_filters ( 'wppb_registration_user_capability', 'create_users' );
181 213
182 214 if ( current_user_can( $current_user_capability ) && $registration )
183 - $this->wppb_form_content( apply_filters( 'wppb_register_pre_form_message', '<p class="alert" id="wppb_register_pre_form_message">'.esc_html(__( 'Users can register themselves or you can manually create users here.', 'profile-builder')). '<img src="'.WPPB_PLUGIN_URL.'assets/images/pencil_delete.png" title="'.esc_attr(__( 'This message is only visible by administrators', 'profile-builder' )).'"/>' . '</p>' ) );
215 + $this->wppb_form_content( apply_filters( 'wppb_register_pre_form_message', '<p class="alert" id="wppb_register_pre_form_message" role="alert">'.esc_html(__( 'Users can register themselves or you can manually create users here.', 'profile-builder')). '<img src="'.WPPB_PLUGIN_URL.'assets/images/pencil_delete.png" title="'.esc_attr(__( 'This message is only visible by administrators', 'profile-builder' )).'"/>' . '</p>' ) );
184 216
185 217 elseif ( current_user_can( $current_user_capability ) && !$registration )
186 - $this->wppb_form_content( apply_filters( 'wppb_register_pre_form_message', '<p class="alert" id="wppb_register_pre_form_message">'.esc_html(__( 'Users cannot currently register themselves, but you can manually create users here.', 'profile-builder')). '<img src="'.WPPB_PLUGIN_URL.'assets/images/pencil_delete.png" title="'.esc_attr(__( 'This message is only visible by administrators', 'profile-builder' )).'"/>' . '</p>' ) );
218 + $this->wppb_form_content( apply_filters( 'wppb_register_pre_form_message', '<p class="alert" id="wppb_register_pre_form_message" role="alert">'.esc_html(__( 'Users cannot currently register themselves, but you can manually create users here.', 'profile-builder')). '<img src="'.WPPB_PLUGIN_URL.'assets/images/pencil_delete.png" title="'.esc_attr(__( 'This message is only visible by administrators', 'profile-builder' )).'"/>' . '</p>' ) );
187 219
188 220 elseif ( !current_user_can( $current_user_capability ) ){
189 221 global $user_ID;
190 222
@@ -202,15 +234,15 @@
202 234 // CHECK FOR REDIRECT
203 235 $this->args['logout_redirect_url'] = wppb_get_redirect_url( $this->args['redirect_priority'], 'after_logout', $this->args['logout_redirect_url'], $userdata );
204 236 $this->args['logout_redirect_url'] = apply_filters( 'wppb_after_logout_redirect_url', $this->args['logout_redirect_url'] );
205 237
206 - echo wp_kses_post( apply_filters( 'wppb_register_pre_form_message', '<p class="alert" id="wppb_register_pre_form_message">'.sprintf( __( "You are currently logged in as %1s. You don't need another account. %2s", 'profile-builder' ), '<a href="'.get_author_posts_url( $user_ID ).'" title="'.$display_name.'">'.$display_name.'</a>', '<a href="'.wp_logout_url( $this->args['logout_redirect_url'] ).'" title="'.__( 'Log out of this account.', 'profile-builder' ).'">'.__( 'Logout', 'profile-builder' ).' &raquo;</a>' ).'</p>', $user_ID ) );
238 + echo wp_kses_post( apply_filters( 'wppb_register_pre_form_message', '<p class="alert" id="wppb_register_pre_form_message" role="alert">'.sprintf( __( "You are currently logged in as %1s. You don't need another account. %2s", 'profile-builder' ), '<a href="'.get_author_posts_url( $user_ID ).'" title="'.$display_name.'">'.$display_name.'</a>', '<a href="'.wp_logout_url( $this->args['logout_redirect_url'] ).'" title="'.__( 'Log out of this account.', 'profile-builder' ).'">'.__( 'Logout', 'profile-builder' ).' &raquo;</a>' ).'</p>', $user_ID ) );
207 239 }
208 240 }
209 241
210 242 }elseif ( $this->args['form_type'] == 'edit_profile' ){
211 243 if ( !is_user_logged_in() )
212 - echo wp_kses_post( apply_filters( 'wppb_edit_profile_user_not_logged_in_message', '<p class="warning" id="wppb_edit_profile_user_not_logged_in_message">'.esc_html(__( 'You must be logged in to edit your profile.', 'profile-builder' )) .'</p>' ) );
244 + echo wp_kses_post( apply_filters( 'wppb_edit_profile_user_not_logged_in_message', '<p class="warning" id="wppb_edit_profile_user_not_logged_in_message" role="alert">'.esc_html(__( 'You must be logged in to edit your profile.', 'profile-builder' )) .'</p>' ) );
213 245
214 246 elseif ( is_user_logged_in() )
215 247 $this->wppb_form_content( apply_filters( 'wppb_edit_profile_logged_in_user_message', '' ) );
216 248
@@ -218,9 +250,9 @@
218 250 }
219 251 }
220 252
221 253 // Function used to automatically log in a user after register if that option is set on yes in register form settings
222 - function wppb_log_in_user( $redirect, $redirect_old ) {
254 + function wppb_log_in_user( $redirect, $redirect_old, $user_id ) {
223 255 if( is_user_logged_in() ) {
224 256 return;
225 257 }
226 258
@@ -234,19 +266,25 @@
234 266 if ( isset( $wppb_general_settings['emailConfirmation'] ) && ( $wppb_general_settings['emailConfirmation'] == 'yes' ) && !$should_bypass_ec ) {
235 267 return $redirect_old;
236 268 }
237 269
238 - /* get user id */
239 - if( empty( $_POST['email'] ) )
240 - return;
270 + // Reject failed registrations
271 + if ( is_wp_error( $user_id ) ) {
272 + return $redirect_old;
273 + }
241 274
242 - $user = get_user_by( 'email', trim( sanitize_email( $_POST['email'] ) ) );
275 + $user_id = absint( $user_id );
243 276
244 - if( !$user )
245 - return;
277 + if ( ! $user_id ) {
278 + return $redirect_old;
279 + }
246 280
247 - $nonce = wp_create_nonce( 'autologin-'. $user->ID .'-'. (int)( time() / 60 ) );
281 + $user = get_userdata( $user_id );
248 282
283 + if ( ! $user ) {
284 + return $redirect_old;
285 + }
286 +
249 287 if ( wppb_get_admin_approval_option_value() === 'yes' ) {
250 288 if( !empty( $wppb_general_settings['adminApprovalOnUserRole'] ) ) {
251 289 foreach ($user->roles as $role) {
252 290 if ( in_array( $role, $wppb_general_settings['adminApprovalOnUserRole'] ) ) {
@@ -261,9 +299,9 @@
261 299
262 300 /* define redirect location */
263 301 if( $this->args['redirect_activated'] == 'No' ) {
264 302 if( isset( $_POST['_wp_http_referer'] ) ) {
265 - $redirect = esc_url_raw($_POST['_wp_http_referer']);
303 + $redirect = wppb_sanitize_request_url( $_POST['_wp_http_referer'] );
266 304 } else {
267 305 $redirect = home_url();
268 306 }
269 307 }
@@ -272,9 +310,9 @@
272 310 $redirect = wppb_curpageurl();
273 311
274 312 $redirect = apply_filters( 'wppb_login_after_reg_redirect_url', $redirect, $this );
275 313
276 - $redirect = add_query_arg( array( 'autologin' => 'true', 'uid' => $user->ID, '_wpnonce' => $nonce ), $redirect );
314 + $redirect = add_query_arg( wppb_get_autologin_query_args( $user_id ), $redirect );
277 315
278 316 // CHECK FOR REDIRECT
279 317 if( $this->args['redirect_activated'] == 'No' || ( empty( $this->args['redirect_delay'] ) || $this->args['redirect_delay'] == '0' ) ) {
280 318 $redirect = wppb_build_redirect( $redirect, 0, 'register', $this->args );
@@ -345,11 +383,14 @@
345 383 $user_id = $this->wppb_save_form_values( $_REQUEST );
346 384
347 385 do_action( 'wppb_after_saving_form_values',$_REQUEST, $this->args );
348 386
349 - if( ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] ) && ( isset( $_POST['action'] ) && $_POST['action'] === $this->args['form_type'] ) ) {
387 + if( $this->args['form_type'] == 'register' && is_wp_error( $user_id ) ) {
388 + // Failed registration: show the error and re-render the form so the user can retry.
389 + echo $message . wp_kses_post( apply_filters( 'wppb_general_top_error_message', '<p id="wppb_form_general_message" class="wppb-error" role="alert">'. esc_html__( 'Something went wrong while creating the user account, please try again.', 'profile-builder' ) .'</p>' ) ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
390 + } elseif( ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] ) && ( isset( $_POST['action'] ) && $_POST['action'] === $this->args['form_type'] ) ) {
350 391
351 - $form_message_tpl_start = apply_filters( 'wppb_form_message_tpl_start', '<p class="alert wppb-success" id="wppb_form_general_message">' );
392 + $form_message_tpl_start = apply_filters( 'wppb_form_message_tpl_start', '<p class="alert wppb-success" id="wppb_form_general_message" role="alert">' );
352 393 $form_message_tpl_end = apply_filters( 'wppb_form_message_tpl_end', '</p>' );
353 394
354 395 if( ! current_user_can( 'manage_options' ) && $this->args['form_type'] != 'edit_profile' && isset( $_POST['custom_field_user_role'] ) ) {
355 396 $user_role = sanitize_text_field($_POST['custom_field_user_role']);
@@ -411,9 +452,9 @@
411 452 $redirect = $this->wppb_get_redirect( 'register', 'after_registration', $account_name, $user_role );
412 453
413 454 // using case-insensitive string comparison to allow for both 'Yes' and 'yes'
414 455 if( strcasecmp($this->args['login_after_register'], 'Yes') == 0 ) {
415 - $redirect = $this->wppb_log_in_user( $this->args['redirect_url'], $redirect );
456 + $redirect = $this->wppb_log_in_user( $this->args['redirect_url'], $redirect, $user_id );
416 457 }
417 458
418 459 echo $form_message_tpl_start . wp_kses_post( $wppb_register_success_message ) . $form_message_tpl_end . $redirect; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ /* properly escaped above */
419 460
@@ -439,9 +480,9 @@
439 480
440 481 }
441 482
442 483 }else
443 - echo $message. wp_kses_post( apply_filters( 'wppb_general_top_error_message', '<p id="wppb_form_general_message" class="wppb-error">'.esc_html(__( 'There was an error in the submitted form', 'profile-builder' )).'</p>' ) ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ /* properly escaped above */
484 + echo $message. wp_kses_post( apply_filters( 'wppb_general_top_error_message', '<p id="wppb_form_general_message" class="wppb-error" role="alert">'.esc_html(__( 'There was an error in the submitted form', 'profile-builder' )).'</p>' ) ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ /* properly escaped above */
444 485
445 486 }else
446 487 echo $message; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ /* properly escaped when created */
447 488
@@ -479,9 +520,9 @@
479 520 $wppb_form_class .= ' wppb-edit-user';
480 521 $wppb_form_class .= $wppb_user_role_class;
481 522
482 523 ?>
483 - <form enctype="multipart/form-data" method="post" id="<?php echo esc_attr( apply_filters( 'wppb_form_id', $wppb_form_id, $this ) ); ?>" class="<?php echo esc_attr( apply_filters( 'wppb_form_class', $wppb_form_class, $this ) ) . ( $this->args['ajax'] == 'true' ? ' wppb-ajax-form' : ''); ?>" action="<?php echo esc_url( apply_filters( 'wppb_form_action', wppb_curpageurl(), $this->args ) ); ?>">
524 + <form enctype="multipart/form-data" method="post" novalidate id="<?php echo esc_attr( apply_filters( 'wppb_form_id', $wppb_form_id, $this ) ); ?>" class="<?php echo esc_attr( apply_filters( 'wppb_form_class', $wppb_form_class, $this ) ) . ( $this->args['ajax'] == 'true' ? ' wppb-ajax-form' : ''); ?>" action="<?php echo esc_url( apply_filters( 'wppb_form_action', wppb_curpageurl(), $this->args ) ); ?>">
484 525 <?php
485 526 do_action( 'wppb_form_args_before_output', $this->args );
486 527 $this->args = apply_filters( 'wppb_filter_form_args_before_output', $this->args );
487 528
@@ -516,11 +557,11 @@
516 557 $wppb_module_settings = get_option( 'wppb_module_settings' );
517 558
518 559 if( isset( $wppb_module_settings['wppb_customRedirect'] ) && $wppb_module_settings['wppb_customRedirect'] == 'show' ) {
519 560 if( isset( $_POST['wppb_referer_url'] ) )
520 - $referer = esc_url_raw( $_POST['wppb_referer_url'] );
561 + $referer = wppb_sanitize_request_url( $_POST['wppb_referer_url'] );
521 562 elseif( isset( $_SERVER['HTTP_REFERER'] ) )
522 - $referer = esc_url_raw( $_SERVER['HTTP_REFERER'] );
563 + $referer = wppb_sanitize_request_url( $_SERVER['HTTP_REFERER'] );
523 564 else
524 565 $referer = '';
525 566
526 567 echo '<input type="hidden" name="wppb_referer_url" value="'. esc_attr( $referer ).'"/>';
@@ -642,9 +683,9 @@
642 683 if( $user_data ) {
643 684 $user_data->remove_all_caps();
644 685
645 686 foreach ($userdata['role'] as $role) {
646 - if ($role !== 'administrator' || $role !== 'super-admin')//make sure this doesn't happen for any reason
687 + if ($role !== 'administrator' && $role !== 'super-admin')//make sure this doesn't happen for any reason
647 688 $user_data->add_role($role);
648 689 }
649 690 }
650 691
@@ -737,9 +778,9 @@
737 778 if( !empty( $field['meta-name'] ) && ( ! isset( $field['field'] ) || 'Default - Biographical Info' !== $field['field'] ) ){
738 779 if ( ! array_key_exists( $field['meta-name'], $global_request ) ) {
739 780 $posted_value = '';
740 781 } elseif( in_array( $field['field'], array( 'URL' ), true ) ) {
741 - $posted_value = esc_url_raw( $global_request[ $field['meta-name'] ] );
782 + $posted_value = wppb_sanitize_request_url( $global_request[ $field['meta-name'] ] );
742 783 } elseif( in_array( $field['field'], array( 'Textarea' ), true ) ){
743 784 $meta_value = sanitize_textarea_field( wp_unslash( $global_request[ $field['meta-name'] ] ) );
744 785
745 786 if( apply_filters( 'wppb_form_field_textarea_escape_on_save', false ) )
@@ -918,20 +959,22 @@
918 959
919 960 /* set action for automatic login after registration */
920 961 add_action( 'init', 'wppb_autologin_after_registration' );
921 962 function wppb_autologin_after_registration(){
922 - if( isset( $_GET['autologin'] ) && isset( $_GET['uid'] ) && isset( $_REQUEST['_wpnonce'] ) ){
923 - $uid = absint( $_GET['uid'] );
963 + if( isset( $_GET['autologin'] ) && isset( $_REQUEST['_wpnonce'] ) ){
964 + $nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) );
965 + $uid = wppb_get_autologin_user_id( $nonce, false );
924 966
925 967 $arr_params = array( 'autologin', 'uid', '_wpnonce' );
926 968 $current_page_url = remove_query_arg( $arr_params, wppb_curpageurl() );
927 969
928 - if ( ! ( wp_verify_nonce( sanitize_text_field( $_REQUEST['_wpnonce'] ) , 'autologin-'.$uid.'-'.(int)( time() / 60 ) ) || wp_verify_nonce( sanitize_text_field( $_REQUEST['_wpnonce'] ) , 'autologin-'.$uid.'-'.(int)( time() / 60 - 1 ) ) ) ){
970 + if ( ! $uid || ! get_userdata( $uid ) || ! wppb_verify_autologin_nonce( $nonce, $uid ) ) {
929 971 wp_redirect( $current_page_url );
930 972 exit;
931 - } else {
932 - wp_set_auth_cookie( $uid );
933 - wp_redirect( $current_page_url );
934 - exit;
935 973 }
974 +
975 + wppb_get_autologin_user_id( $nonce, true );
976 + wp_set_auth_cookie( $uid );
977 + wp_redirect( $current_page_url );
978 + exit;
936 979 }
937 980 }