Like other users before, Im trying to automatically log in the user after submitting cred registration form.
After following similar threads on this forum, I have the following:
add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
function tssupp_cred_autologin( $post_id, $form_data ){
if ( 64710 == $form_data['id'] ) { // Edit as required
if ( !empty( $_POST['user_email'] ) && !empty( $_POST['user_pass'] ) ) {
$user_login = explode("@",$_POST['user_email']);
// get the user credentials from the $_POST object
$user = array(
'user_login' => $user_login[0],
'user_password' => $_POST['user_pass'],
'remember' => true
);
$login = wp_signon( $user, false );
if ( is_wp_error($login) ) {
error_log( $login->get_error_message() );
}
}
}
}
I have checked my form ID and has the necessary fields:
<div class="col-md-8">
<div class="row">
<div class="col-md-6">
<label for="%%FORM_ID%%_first_name">[cred_i18n name='user_first_name']First Name[/cred_i18n]</label>
[cred_field field='first_name' class='form-control' output='bootstrap']
</div>
<div class="col-md-6">
<label for="%%FORM_ID%%_last_name">[cred_i18n name='user_first_name']Last Name[/cred_i18n]</label>
[cred_field field='last_name' class='form-control' output='bootstrap']
</div>
<div class="col-md-6">
<label for="%%FORM_ID%%_user_email">[cred_i18n name='user_email-label']Email[/cred_i18n]</label>
[cred_field field='user_email' class='form-control' output='bootstrap']
</div>
<div class="col-md-6">
<label for="%%FORM_ID%%_user_pass">[cred_i18n name='user_pass']Password[/cred_i18n]</label>
[cred_field field='user_pass' class='form-control' output='bootstrap']
</div>
I can see that the user is being registered, but not logged in. From the error log, I can see that there is a problem with the password:
"Error: the password you entered for the username xxx is incorrect.
We generally don't provide support to custom coding, however based on the layout of your code it should work given that i've checked the POST request payload and saw the correct values there.
Can you disable all your non-toolset plugins and try testing it again as it appears that maybe another plugin is preventing the user from logging in.
Thanks,
Shane
The topic ‘[Closed] automatically log in user on cred registration form submit’ is closed to new replies.