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 +217 -64 3.9.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;
@@ -55,13 +63,29 @@
55 63 require_once( WPPB_PAID_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' );
56 64
57 65 $this->wppb_retrieve_custom_settings();
58 66
59 - if( ( !is_multisite() && current_user_can( 'edit_users' ) ) || ( is_multisite() && current_user_can( 'manage_network' ) ) )
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' ) ) {
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 );
69 + wp_localize_script( 'wppb-forms-ajax-validation-script', 'submitButtonData', array( 'processingText' => __( 'Processing...', 'profile-builder' ) ) );
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();
74 + }
75 +
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()
77 + // current_user_can( 'edit_users' ) will only return true on a Multisite for Super Administrator Users
78 + if( ( !is_multisite() && current_user_can( 'edit_users' ) ) || ( is_multisite() && ( current_user_can( 'remove_users' ) || current_user_can( 'manage_options' ) ) ) )
60 79 add_action( 'wppb_before_edit_profile_fields', array( 'Profile_Builder_Form_Creator', 'wppb_edit_profile_select_user_to_edit' ), 10, 4 );
61 80
62 81 //enqueue frontend scripts for forms
63 82 add_action( 'wp_footer', array( $this, 'wppb_frontend_scripts' ), 9999 );
83 +
84 + //admin_edit_roles parameter
85 + if( !empty( $this->args['admin_edit_roles'] ) ){
86 + add_filter( 'wppb_edit_other_users_dropdown_query_args', array( $this, 'wppb_admin_edit_roles' ), 10, 2 );
87 + }
64 88 }
65 89
66 90 /**
67 91 * @param $form_name The "slug" generated from the current Form Title
@@ -70,8 +94,11 @@
70 94 */
71 95 static function wppb_get_form_id_from_form_name( $form_name, $form_type ){
72 96 global $wpdb;
73 97
98 + if( empty( $form_name ) || empty( $form_type ) )
99 + return null;
100 +
74 101 if( $form_type == 'edit_profile' ){
75 102 $post_type = 'wppb-epf-cpt';
76 103 }elseif( $form_type == 'register' ){
77 104 $post_type = 'wppb-rf-cpt';
@@ -101,12 +128,12 @@
101 128 }
102 129
103 130 function wppb_retrieve_custom_settings(){
104 131 $this->args['login_after_register'] = apply_filters( 'wppb_automatically_login_after_register', 'No' );
105 - $this->args['redirect_activated'] = apply_filters( 'wppb_redirect_default_setting', '-' );
106 - $this->args['redirect_url'] = apply_filters( 'wppb_redirect_default_location', ( $this->args['redirect_url'] != '' ) ? $this->args['redirect_url'] : '' );
107 - $this->args['logout_redirect_url'] = apply_filters( 'wppb_logout_redirect_default_location', ( $this->args['logout_redirect_url'] != '' ) ? $this->args['logout_redirect_url'] : '' );
108 - $this->args['redirect_delay'] = apply_filters( 'wppb_redirect_default_duration', 3 );
132 + $this->args['redirect_activated'] = apply_filters( 'wppb_redirect_default_setting', '-' );
133 + $this->args['redirect_url'] = apply_filters( 'wppb_redirect_default_location', ( $this->args['redirect_url'] != '' ) ? $this->args['redirect_url'] : '' );
134 + $this->args['logout_redirect_url'] = apply_filters( 'wppb_logout_redirect_default_location', ( $this->args['logout_redirect_url'] != '' ) ? $this->args['logout_redirect_url'] : '' );
135 + $this->args['redirect_delay'] = apply_filters( 'wppb_redirect_default_duration', 3 );
109 136
110 137 $wppb_general_settings = get_option( 'wppb_general_settings' );
111 138 $this->args['login_after_register'] = ( isset( $wppb_general_settings['automaticallyLogIn'] ) ? $wppb_general_settings['automaticallyLogIn'] : $this->args['login_after_register'] );
112 139
@@ -122,13 +149,16 @@
122 149 else
123 150 $selected_role = $page_settings[0]['set-role'];
124 151 }
125 152
126 - $this->args['role'] = ( isset( $selected_role ) ? $selected_role : $this->args['role'] );
153 + $this->args['role'] = ( isset( $selected_role ) ? $selected_role : $this->args['role'] );
127 154 $this->args['login_after_register'] = ( isset( $page_settings[0]['automatically-log-in'] ) ? $page_settings[0]['automatically-log-in'] : $this->args['login_after_register'] );
128 - $this->args['redirect_activated'] = ( isset( $page_settings[0]['redirect'] ) ? $page_settings[0]['redirect'] : $this->args['redirect_activated'] );
129 - $this->args['redirect_url'] = ( ! empty( $page_settings[0]['url'] ) && $this->args['redirect_activated'] == 'Yes' && $this->args['redirect_priority'] != 'top' ? $page_settings[0]['url'] : $this->args['redirect_url'] );
130 - $this->args['redirect_delay'] = ( isset( $page_settings[0]['display-messages'] ) && $this->args['redirect_activated'] == 'Yes' ? $page_settings[0]['display-messages'] : $this->args['redirect_delay'] );
155 + $this->args['redirect_activated'] = ( isset( $page_settings[0]['redirect'] ) ? $page_settings[0]['redirect'] : $this->args['redirect_activated'] );
156 + $this->args['redirect_url'] = ( ! empty( $page_settings[0]['url'] ) && $this->args['redirect_activated'] == 'Yes' && $this->args['redirect_priority'] != 'top' ? $page_settings[0]['url'] : $this->args['redirect_url'] );
157 + $this->args['redirect_delay'] = ( isset( $page_settings[0]['display-messages'] ) && $this->args['redirect_activated'] == 'Yes' ? $page_settings[0]['display-messages'] : $this->args['redirect_delay'] );
158 +
159 + if( isset( $page_settings[0]['ajax'] ) && !empty( $page_settings[0]['ajax'] ) )
160 + $this->args['ajax'] = $page_settings[0]['ajax'];
131 161 }
132 162
133 163 // the 'automatic_login' shortcode parameter overwrites all other settings
134 164 $this->args['login_after_register'] = ( $this->args['automatic_login'] != '' ) ? $this->args['automatic_login'] : $this->args['login_after_register'];
@@ -137,14 +167,35 @@
137 167 $role_in_arg = get_role( $this->args['role'] );
138 168 if( !empty( $role_in_arg->capabilities['manage_options'] ) || !empty( $role_in_arg->capabilities['remove_users'] ) ){
139 169 if( !current_user_can( 'manage_options' ) || !current_user_can( 'remove_users' ) ){
140 170 $this->args['role'] = get_option('default_role');
141 - 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>' ) );
142 172 }
143 173 }
144 174 }
145 175 }
146 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 +
147 198 function wppb_form_logic() {
148 199 if( isset( $this->args['form_type'] ) ) {
149 200 if( $this->args['form_type'] == 'register' ){
150 201 $registration = apply_filters ( 'wppb_register_setting_override', true );//used to be get_option( 'users_can_register' )
@@ -150,9 +201,9 @@
150 201 $registration = apply_filters ( 'wppb_register_setting_override', true );//used to be get_option( 'users_can_register' )
151 202
152 203 if ( !is_user_logged_in() ){
153 204 if ( !$registration )
154 - 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>' ) );
155 206
156 207 elseif ( $registration ){
157 208 $this->wppb_form_content( apply_filters( 'wppb_register_pre_form_message', '' ) );
158 209 }
@@ -160,12 +211,12 @@
160 211 }else{
161 212 $current_user_capability = apply_filters ( 'wppb_registration_user_capability', 'create_users' );
162 213
163 214 if ( current_user_can( $current_user_capability ) && $registration )
164 - $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>' ) );
165 216
166 217 elseif ( current_user_can( $current_user_capability ) && !$registration )
167 - $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>' ) );
168 219
169 220 elseif ( !current_user_can( $current_user_capability ) ){
170 221 global $user_ID;
171 222
@@ -183,15 +234,15 @@
183 234 // CHECK FOR REDIRECT
184 235 $this->args['logout_redirect_url'] = wppb_get_redirect_url( $this->args['redirect_priority'], 'after_logout', $this->args['logout_redirect_url'], $userdata );
185 236 $this->args['logout_redirect_url'] = apply_filters( 'wppb_after_logout_redirect_url', $this->args['logout_redirect_url'] );
186 237
187 - 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 ) );
188 239 }
189 240 }
190 241
191 242 }elseif ( $this->args['form_type'] == 'edit_profile' ){
192 243 if ( !is_user_logged_in() )
193 - 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>' ) );
194 245
195 246 elseif ( is_user_logged_in() )
196 247 $this->wppb_form_content( apply_filters( 'wppb_edit_profile_logged_in_user_message', '' ) );
197 248
@@ -199,30 +250,41 @@
199 250 }
200 251 }
201 252
202 253 // Function used to automatically log in a user after register if that option is set on yes in register form settings
203 - function wppb_log_in_user( $redirect, $redirect_old ) {
254 + function wppb_log_in_user( $redirect, $redirect_old, $user_id ) {
204 255 if( is_user_logged_in() ) {
205 256 return;
206 257 }
207 258
208 259 $wppb_general_settings = get_option( 'wppb_general_settings' );
260 + $ec_bypass_forms = wppb_toolbox_get_settings( 'forms', 'ec-bypass' );
209 261
210 - if ( isset( $wppb_general_settings['emailConfirmation'] ) && ( $wppb_general_settings['emailConfirmation'] == 'yes' ) ) {
262 + if ( is_array( $ec_bypass_forms ) && !empty( $_POST['form_name'] ) && in_array( sanitize_text_field( $_POST['form_name'] ), $ec_bypass_forms ) )
263 + $should_bypass_ec = true;
264 + else $should_bypass_ec = false;
265 +
266 + if ( isset( $wppb_general_settings['emailConfirmation'] ) && ( $wppb_general_settings['emailConfirmation'] == 'yes' ) && !$should_bypass_ec ) {
211 267 return $redirect_old;
212 268 }
213 269
214 - /* get user id */
215 - if( empty( $_POST['email'] ) )
216 - return;
270 + // Reject failed registrations
271 + if ( is_wp_error( $user_id ) ) {
272 + return $redirect_old;
273 + }
217 274
218 - $user = get_user_by( 'email', trim( sanitize_email( $_POST['email'] ) ) );
275 + $user_id = absint( $user_id );
219 276
220 - if( !$user )
221 - return;
277 + if ( ! $user_id ) {
278 + return $redirect_old;
279 + }
222 280
223 - $nonce = wp_create_nonce( 'autologin-'. $user->ID .'-'. (int)( time() / 60 ) );
281 + $user = get_userdata( $user_id );
224 282
283 + if ( ! $user ) {
284 + return $redirect_old;
285 + }
286 +
225 287 if ( wppb_get_admin_approval_option_value() === 'yes' ) {
226 288 if( !empty( $wppb_general_settings['adminApprovalOnUserRole'] ) ) {
227 289 foreach ($user->roles as $role) {
228 290 if ( in_array( $role, $wppb_general_settings['adminApprovalOnUserRole'] ) ) {
@@ -237,9 +299,9 @@
237 299
238 300 /* define redirect location */
239 301 if( $this->args['redirect_activated'] == 'No' ) {
240 302 if( isset( $_POST['_wp_http_referer'] ) ) {
241 - $redirect = esc_url_raw($_POST['_wp_http_referer']);
303 + $redirect = wppb_sanitize_request_url( $_POST['_wp_http_referer'] );
242 304 } else {
243 305 $redirect = home_url();
244 306 }
245 307 }
@@ -248,9 +310,9 @@
248 310 $redirect = wppb_curpageurl();
249 311
250 312 $redirect = apply_filters( 'wppb_login_after_reg_redirect_url', $redirect, $this );
251 313
252 - $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 );
253 315
254 316 // CHECK FOR REDIRECT
255 317 if( $this->args['redirect_activated'] == 'No' || ( empty( $this->args['redirect_delay'] ) || $this->args['redirect_delay'] == '0' ) ) {
256 318 $redirect = wppb_build_redirect( $redirect, 0, 'register', $this->args );
@@ -290,17 +352,24 @@
290 352 ob_start();
291 353
292 354 // check if the form is being displayed in the Elementor editor
293 355 // if true remove any messages
294 - $is_elementor_edit_mode = false;
356 + $is_elementor_edit_mode_or_divi_ajax = false;
295 357 if( class_exists ( '\Elementor\Plugin' ) ){
296 - $is_elementor_edit_mode = \Elementor\Plugin::$instance->editor->is_edit_mode();
358 + $is_elementor_edit_mode_or_divi_ajax = \Elementor\Plugin::$instance->editor->is_edit_mode();
297 359 $message= "";
298 360 }
299 361
300 - if( !$is_elementor_edit_mode && isset( $_REQUEST['action'], $_REQUEST['form_name'], $this->args['form_name'] ) && $_REQUEST['form_name'] === $this->args['form_name'] ) {
362 + if ( is_array( $_POST ) && array_key_exists( 'action', $_POST ) && $_POST['action'] === 'wppb_divi_extension_ajax' ) {
363 + $is_elementor_edit_mode_or_divi_ajax = true;
364 + }
365 +
366 + if( !$is_elementor_edit_mode_or_divi_ajax && isset( $_REQUEST['action'], $_REQUEST['form_name'], $this->args['form_name'] ) && $_REQUEST['form_name'] === $this->args['form_name'] ) {
301 367 if( ! isset( $_POST[$this->args['form_type'].'_'. $this->args['form_name'] .'_nonce_field'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST[$this->args['form_type'].'_'. $this->args['form_name'] .'_nonce_field'] ), 'wppb_verify_form_submission' ) ) {
302 368 echo '<span class="wppb-form-error wppb-error">'. esc_html(__( 'You are not allowed to do this.', 'profile-builder' )) . '</span>';
369 +
370 + ob_end_flush();
371 +
303 372 return;
304 373 }
305 374
306 375 $_REQUEST = apply_filters( 'wppb_filter_form_request_data', $_REQUEST, $this->args );
@@ -314,11 +383,14 @@
314 383 $user_id = $this->wppb_save_form_values( $_REQUEST );
315 384
316 385 do_action( 'wppb_after_saving_form_values',$_REQUEST, $this->args );
317 386
318 - 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'] ) ) {
319 391
320 - $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">' );
321 393 $form_message_tpl_end = apply_filters( 'wppb_form_message_tpl_end', '</p>' );
322 394
323 395 if( ! current_user_can( 'manage_options' ) && $this->args['form_type'] != 'edit_profile' && isset( $_POST['custom_field_user_role'] ) ) {
324 396 $user_role = sanitize_text_field($_POST['custom_field_user_role']);
@@ -358,9 +430,9 @@
358 430 }
359 431
360 432 switch( $account_management_settings ) {
361 433 case 'ec-no_aa-no':
362 - $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "The account %1s has been successfully created!", 'profile-builder' ), $account_name ), $account_name ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
434 + $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "The account %1\$s has been successfully created!", 'profile-builder' ), $account_name ), $account_name ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
363 435 break;
364 436 case 'ec-yes_aa-no':
365 437 $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "Before you can access your account %1s, you need to confirm your email address. Please check your inbox and click the activation link.", 'profile-builder' ), $account_name ), $account_name ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
366 438 break;
@@ -365,10 +437,10 @@
365 437 $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "Before you can access your account %1s, you need to confirm your email address. Please check your inbox and click the activation link.", 'profile-builder' ), $account_name ), $account_name ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
366 438 break;
367 439 case 'ec-no_aa-yes':
368 440 if( current_user_can( 'delete_users' ) ) {
369 - $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "The account %1s has been successfully created!", 'profile-builder' ), $account_name ), $account_name ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
370 - } else {
441 + $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "The account %1\$s has been successfully created!", 'profile-builder' ), $account_name ), $account_name ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
442 + } else {
371 443 $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "Before you can access your account %1s, an administrator has to approve it. You will be notified via email.", 'profile-builder' ), $account_name ), $account_name ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
372 444 }
373 445 break;
374 446 case 'ec-yes_aa-yes':
@@ -380,13 +452,16 @@
380 452 $redirect = $this->wppb_get_redirect( 'register', 'after_registration', $account_name, $user_role );
381 453
382 454 // using case-insensitive string comparison to allow for both 'Yes' and 'yes'
383 455 if( strcasecmp($this->args['login_after_register'], 'Yes') == 0 ) {
384 - $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 );
385 457 }
386 458
387 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 */
388 - //action hook after registration success
460 +
461 + ob_end_flush();
462 +
463 + //action hook after registration success
389 464 do_action( 'wppb_register_success', $_REQUEST, $this->args['form_name'], $user_id );
390 465 return;
391 466 } elseif( $this->args['form_type'] == 'edit_profile' ) {
392 467 // CHECK FOR REDIRECT
@@ -395,22 +470,25 @@
395 470 echo $form_message_tpl_start . apply_filters( 'wppb_edit_profile_success_message', esc_html(__( 'Your profile has been successfully updated!', 'profile-builder' )) ) . $form_message_tpl_end . $redirect; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ /* properly escaped above */
396 471
397 472 //action hook after edit profile success
398 473 do_action( 'wppb_edit_profile_success', $_REQUEST, $this->args['form_name'], $user_id );
399 - if( apply_filters( 'wppb_no_form_after_profile_update', false ) )
474 +
475 + if( apply_filters( 'wppb_no_form_after_profile_update', false ) ){
476 + ob_end_flush();
400 477 return;
478 + }
401 479 }
402 480
403 481 }
404 482
405 483 }else
406 - 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 */
407 485
408 486 }else
409 487 echo $message; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ /* properly escaped when created */
410 488
411 489 // use this action hook to add extra content before the register form
412 - do_action( 'wppb_before_'.$this->args['form_type'].'_fields', $this->args['form_name'], $this->args['ID'], $this->args['form_type'], $is_elementor_edit_mode );
490 + do_action( 'wppb_before_'.$this->args['form_type'].'_fields', $this->args['form_name'], $this->args['ID'], $this->args['form_type'], $is_elementor_edit_mode_or_divi_ajax );
413 491
414 492 $wppb_user_role_class = '';
415 493 if( is_user_logged_in() ) {
416 494 $wppb_user = wp_get_current_user();
@@ -442,9 +520,9 @@
442 520 $wppb_form_class .= ' wppb-edit-user';
443 521 $wppb_form_class .= $wppb_user_role_class;
444 522
445 523 ?>
446 - <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 ) ); ?>" 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 ) ); ?>">
447 525 <?php
448 526 do_action( 'wppb_form_args_before_output', $this->args );
449 527 $this->args = apply_filters( 'wppb_filter_form_args_before_output', $this->args );
450 528
@@ -455,8 +533,10 @@
455 533 echo apply_filters( 'wppb_before_send_credentials_checkbox', '<ul>', $this->args['form_type'], $this->args['ID'] ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
456 534 $this->wppb_add_send_credentials_checkbox( $_REQUEST, $this->args['form_type'] );
457 535 echo apply_filters( 'wppb_after_send_credentials_checkbox', '</ul>', $this->args['form_type'] ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
458 536
537 + echo apply_filters( 'wppb_form_bottom', '</ul>', $this->args['form_type'], $this->args['ID'], $_REQUEST ); /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */
538 +
459 539 $wppb_form_submit_extra_attr = apply_filters( 'wppb_form_submit_extra_attr', '', $this->args['form_type'], $this->args['ID'] );
460 540 ?>
461 541 <p class="form-submit" <?php echo $wppb_form_submit_extra_attr; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ /* properly escaped when created */ ?> >
462 542 <?php
@@ -477,11 +557,11 @@
477 557 $wppb_module_settings = get_option( 'wppb_module_settings' );
478 558
479 559 if( isset( $wppb_module_settings['wppb_customRedirect'] ) && $wppb_module_settings['wppb_customRedirect'] == 'show' ) {
480 560 if( isset( $_POST['wppb_referer_url'] ) )
481 - $referer = esc_url_raw( $_POST['wppb_referer_url'] );
561 + $referer = wppb_sanitize_request_url( $_POST['wppb_referer_url'] );
482 562 elseif( isset( $_SERVER['HTTP_REFERER'] ) )
483 - $referer = esc_url_raw( $_SERVER['HTTP_REFERER'] );
563 + $referer = wppb_sanitize_request_url( $_SERVER['HTTP_REFERER'] );
484 564 else
485 565 $referer = '';
486 566
487 567 echo '<input type="hidden" name="wppb_referer_url" value="'. esc_attr( $referer ).'"/>';
@@ -514,9 +594,9 @@
514 594 if( $display_field == false )
515 595 continue;
516 596
517 597 $css_class = apply_filters( 'wppb_field_css_class', 'wppb-form-field wppb-'. Wordpress_Creation_Kit_PB::wck_generate_slug( $field['field'] ) .$error_var, $field, $error_var );
518 - $output_fields .= apply_filters( 'wppb_output_before_form_field', '<li class="'. $css_class .'" id="wppb-form-element-'. $field['id'] .'">', $field, $error_var, $this->args['role'] );
598 + $output_fields .= apply_filters( 'wppb_output_before_form_field', '<li class="'. $css_class .'" id="wppb-form-element-'. $field['id'] .'">', $field, $error_var, $this->args['role'], $this->args['ID'], $this->args['form_type']);
519 599
520 600 $render_field = true;
521 601 if( wppb_conditional_fields_exists() && isset( $wppb_generalSettings['conditional_fields_ajax'] ) ){
522 602 if($wppb_generalSettings['conditional_fields_ajax'] === 'yes' && isset($field['conditional-logic-enabled']) && $field['conditional-logic-enabled'] === 'yes') {
@@ -603,9 +683,9 @@
603 683 if( $user_data ) {
604 684 $user_data->remove_all_caps();
605 685
606 686 foreach ($userdata['role'] as $role) {
607 - 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
608 688 $user_data->add_role($role);
609 689 }
610 690 }
611 691
@@ -623,12 +703,13 @@
623 703
624 704 if ( $this->args['form_type'] == 'register' ){
625 705 if ( !is_wp_error( $user_id ) ){
626 706 $wppb_general_settings = get_option( 'wppb_general_settings' );
627 - if( isset( $global_request['send_credentials_via_email'] ) && ( $global_request['send_credentials_via_email'] == 'sending' ) )
707 + if( ( isset( $global_request['send_credentials_via_email'] ) && ( $global_request['send_credentials_via_email'] == 'sending' ) ) || apply_filters( 'wppb_register_send_credentials_via_email', false, $user_id, $this->args ) )
628 708 $send_credentials_via_email = 'sending';
629 709 else
630 710 $send_credentials_via_email = '';
711 +
631 712 wppb_notify_user_registration_email( get_bloginfo( 'name' ), ( isset( $userdata['user_login'] ) ? trim( $userdata['user_login'] ) : trim( $userdata['user_email'] ) ), trim( $userdata['user_email'] ), $send_credentials_via_email, trim( $userdata['user_pass'] ), ( wppb_get_admin_approval_option_value() === 'yes' ? 'yes' : 'no' ) );
632 713 }
633 714 }
634 715 }
@@ -665,8 +746,10 @@
665 746 $userdata['registered_for_blog_id'] = get_current_blog_id();
666 747 $userdata = wp_unslash( $userdata );
667 748 }
668 749
750 + $userdata['form_name'] = $this->args['form_name'];
751 +
669 752 wppb_signup_user( $userdata['user_login'], $userdata['user_email'], $this->args['login_after_register'], $userdata );
670 753 }else{
671 754 if( ! isset( $userdata['role'] ) ) {
672 755 $userdata['role'] = $this->args['role'];
@@ -691,12 +774,37 @@
691 774 function wppb_add_custom_field_values( $global_request, $meta, $form_properties ){
692 775 $form_fields = apply_filters( 'wppb_form_fields', $this->args['form_fields'], array( 'meta' => $meta, 'global_request' => $global_request, 'context' => 'user_signup' ) );
693 776 if( !empty( $form_fields ) ){
694 777 foreach( $form_fields as $field ){
695 - if( !empty( $field['meta-name'] ) ){
696 - $posted_value = ( !empty( $global_request[$field['meta-name']] ) ? $global_request[$field['meta-name']] : '' );
778 + if( !empty( $field['meta-name'] ) && ( ! isset( $field['field'] ) || 'Default - Biographical Info' !== $field['field'] ) ){
779 + if ( ! array_key_exists( $field['meta-name'], $global_request ) ) {
780 + $posted_value = '';
781 + } elseif( in_array( $field['field'], array( 'URL' ), true ) ) {
782 + $posted_value = wppb_sanitize_request_url( $global_request[ $field['meta-name'] ] );
783 + } elseif( in_array( $field['field'], array( 'Textarea' ), true ) ){
784 + $meta_value = sanitize_textarea_field( wp_unslash( $global_request[ $field['meta-name'] ] ) );
785 +
786 + if( apply_filters( 'wppb_form_field_textarea_escape_on_save', false ) )
787 + $meta_value = esc_textarea( $meta_value );
788 +
789 + $posted_value = $meta_value;
790 + } elseif ( is_array( $global_request[ $field['meta-name'] ] ) ) {
791 + $posted_value = array_map( 'sanitize_text_field', $global_request[ $field['meta-name'] ] );
792 + } else {
793 + $posted_value = sanitize_text_field( $global_request[ $field['meta-name'] ] );
794 + }
795 +
697 796 $meta[$field['meta-name']] = apply_filters( 'wppb_add_to_user_signup_form_field_'.Wordpress_Creation_Kit_PB::wck_generate_slug( $field['field'] ), $posted_value, $field, $global_request );
797 +
698 798 }
799 +
800 + if ( isset( $field['field'] ) && 'Default - Biographical Info' === $field['field'] ) {
801 + $posted_value = '';
802 + if ( array_key_exists( 'description', $global_request ) ) {
803 + $posted_value = wppb_sanitize_default_biographical_info_from_request( $global_request );
804 + }
805 + $meta['description'] = apply_filters( 'wppb_add_to_user_signup_form_field_' . Wordpress_Creation_Kit_PB::wck_generate_slug( $field['field'] ), $posted_value, $field, $global_request );
806 + }
699 807 }
700 808 }
701 809
702 810 return apply_filters( 'wppb_add_to_user_signup_form_meta', $meta, $global_request, $this->args['role'] );
@@ -707,9 +815,9 @@
707 815 */
708 816 function wppb_get_desired_user_id(){
709 817 if( $this->args['form_type'] == 'edit_profile' ){
710 818 //only admins
711 - if( ( !is_multisite() && current_user_can( 'edit_users' ) ) || ( is_multisite() && current_user_can( 'manage_network' ) ) ) {
819 + if( ( !is_multisite() && current_user_can( 'edit_users' ) ) || ( is_multisite() && ( current_user_can( 'remove_users' ) || current_user_can( 'manage_options' ) ) ) ){
712 820 if( isset( $_GET['edit_user'] ) && ! empty( $_GET['edit_user'] ) ){
713 821 return absint( $_GET['edit_user'] );
714 822 }
715 823 }
@@ -717,12 +825,12 @@
717 825
718 826 return get_current_user_id();
719 827 }
720 828
721 - static function wppb_edit_profile_select_user_to_edit( $form_name, $id, $form_type, $is_elementor_edit_mode ){
829 + static function wppb_edit_profile_select_user_to_edit( $form_name, $id, $form_type, $is_elementor_edit_mode_or_divi_ajax ){
722 830
723 831 $display_edit_users_dropdown = apply_filters( 'wppb_display_edit_other_users_dropdown', true, $form_name );
724 - if( !$display_edit_users_dropdown || $is_elementor_edit_mode )
832 + if( !$display_edit_users_dropdown || $is_elementor_edit_mode_or_divi_ajax )
725 833 return;
726 834
727 835 /* add a hard cap: if we have more than 5000 users don't display the dropdown for performance considerations */
728 836 $user_count = count_users();
@@ -740,10 +848,19 @@
740 848 'role__not_in' => array( 'administrator' ),
741 849 'orderby' => array( 'display_name', 'user_login' ),
742 850 );
743 851
744 - $users = get_users( apply_filters( 'wppb_edit_other_users_dropdown_query_args', $query_args ) );
745 -
852 + $users = get_users( apply_filters( 'wppb_edit_other_users_dropdown_query_args', $query_args, $form_name ) );
853 +
854 + if ( apply_filters( 'wppb_edit_other_users_dropdown_user_list_excludes_admin_approval', false ) &&
855 + wppb_get_admin_approval_option_value() === 'yes' ) {
856 + foreach ( $users as $key => $user ) {
857 + if ( wp_get_object_terms( $user->ID, 'user_status' ) ) {
858 + unset( $users[ $key ] );
859 + }
860 + }
861 + }
862 +
746 863 if( !empty( $users ) ) {
747 864
748 865 /* turn it in a select2 */
749 866 wp_enqueue_script( 'wppb_select2_js', WPPB_PLUGIN_URL .'assets/js/select2/select2.min.js', array( 'jquery' ), PROFILE_BUILDER_VERSION );
@@ -756,9 +873,9 @@
756 873 <option value=""><?php echo esc_html__( 'Select User', 'profile-builder' ); ?></option>
757 874 <?php
758 875 foreach( $users as $user ){
759 876 ?>
760 - <option value="<?php echo esc_url_raw( add_query_arg( array( 'edit_user' => $user->ID ) ) ); ?>" <?php selected( $selected, $user->ID ); ?>>
877 + <option value="<?php echo esc_url( add_query_arg( array( 'edit_user' => $user->ID ) ) ); ?>" <?php selected( $selected, $user->ID ); ?>>
761 878 <?php echo esc_html( apply_filters( 'wppb_edit_other_users_display_name', $user->display_name, $user ) ); ?>
762 879 </option>
763 880 <?php
764 881 }
@@ -772,16 +889,50 @@
772 889 echo '<p id="wppb-no-other-users-to-edit">'. esc_html( apply_filters( 'wppb_no_users_to_edit_message', __( 'There are no other users to edit', 'profile-builder' ) ) ).'</p>';
773 890 }
774 891 }
775 892
893 + public function wppb_admin_edit_roles( $query_args, $form_name ){
894 + $admin_edit_roles = $this->args['admin_edit_roles'];
895 +
896 + $admin_edit_roles = array_filter( array_map( 'trim', explode( ',', (string) $admin_edit_roles ) ) );
897 + $admin_edit_roles = array_map( 'sanitize_key', $admin_edit_roles );
898 + $admin_edit_roles = array_values( array_unique( $admin_edit_roles ) );
899 +
900 + global $wp_roles;
901 + if ( ! $wp_roles ) {
902 + $wp_roles = wp_roles();
903 + }
904 +
905 + $roles = array();
906 + foreach ( $admin_edit_roles as $admin_edit_role ){
907 + if ( isset( $wp_roles->roles[$admin_edit_role] ) )
908 + $roles[] = $admin_edit_role;
909 + }
910 +
911 + if ( empty( $roles ) ) {
912 + return $query_args;
913 + }
914 +
915 + unset( $query_args['role'] );
916 + $query_args['role__in'] = $roles;
917 +
918 + return $query_args;
919 +
920 + }
921 +
776 922 static function wppb_frontend_scripts(){
923 +
924 + wp_register_script( 'wppb_front_end_script', WPPB_PLUGIN_URL. 'assets/js/script-front-end.js', array('jquery'), PROFILE_BUILDER_VERSION, true );
925 +
777 926 $wppb_toolbox_forms_settings = get_option( 'wppb_toolbox_forms_settings' );
778 - if( !isset( $wppb_toolbox_forms_settings[ 'disable-automatic-scrolling' ] ) ){
779 - wp_enqueue_script( 'wppb_front_end_script', WPPB_PLUGIN_URL. 'assets/js/script-front-end.js', array('jquery'), PROFILE_BUILDER_VERSION, true );
780 - wp_print_scripts( 'wppb_front_end_script' );
927 + if( isset( $wppb_toolbox_forms_settings[ 'disable-automatic-scrolling' ] ) ){
928 + wp_add_inline_script( 'wppb_front_end_script', "var wppb_disable_automatic_scrolling = 1;", 'before' );
781 929 }
782 930
783 - if( ( !is_multisite() && current_user_can( 'edit_users' ) ) || ( is_multisite() && current_user_can( 'manage_network' ) ) ){
931 + wp_enqueue_script( 'wppb_front_end_script' );
932 + wp_print_scripts( 'wppb_front_end_script' );
933 +
934 + if( ( !is_multisite() && current_user_can( 'edit_users' ) ) || ( is_multisite() && ( current_user_can( 'remove_users' ) || current_user_can( 'manage_options' ) ) ) ){
784 935 wp_enqueue_script( 'wppb_select_user_to_edit_js', WPPB_PLUGIN_URL. 'assets/js/select-user-to-edit.js', array('jquery'), PROFILE_BUILDER_VERSION, true );
785 936 wp_print_scripts( 'wppb_select_user_to_edit_js' );
786 937 }
787 938
@@ -808,20 +959,22 @@
808 959
809 960 /* set action for automatic login after registration */
810 961 add_action( 'init', 'wppb_autologin_after_registration' );
811 962 function wppb_autologin_after_registration(){
812 - if( isset( $_GET['autologin'] ) && isset( $_GET['uid'] ) && isset( $_REQUEST['_wpnonce'] ) ){
813 - $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 );
814 966
815 967 $arr_params = array( 'autologin', 'uid', '_wpnonce' );
816 968 $current_page_url = remove_query_arg( $arr_params, wppb_curpageurl() );
817 969
818 - 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 ) ) {
819 971 wp_redirect( $current_page_url );
820 972 exit;
821 - } else {
822 - wp_set_auth_cookie( $uid );
823 - wp_redirect( $current_page_url );
824 - exit;
825 973 }
974 +
975 + wppb_get_autologin_user_id( $nonce, true );
976 + wp_set_auth_cookie( $uid );
977 + wp_redirect( $current_page_url );
978 + exit;
826 979 }
827 980 }