I am using the toolset user form to auto-login and redirect users after registration. It works fine for many new users but I am also hearing from some new users that they are not redirected after registration.
I have tried this on my end and cannot replicate the issue.
add_action( 'cred_save_data', 'cred_autologin_V2', 10, 2 );
function cred_autologin_V2( $post_id, $form_data ){
if ( 37260 == $form_data['id'] || 10365 == $form_data['id'] ) { // Edit as required
if ( !empty( $_REQUEST['user_email'] ) && !empty( $_REQUEST['user_pass'] ) ) {
// get the user credentials from the $_POST object
$user = array(
'user_login' => substr( $_REQUEST['user_email'], 0, strpos( $_REQUEST['user_email'], "@")),
'user_password' => $_REQUEST['user_pass'],
'remember' => true
);
$login = wp_signon( $user, false );
if ( is_wp_error($login) ) {
error_log('error during auto login, user_login was: ' . substr( $_REQUEST['user_email'], 0, strpos( $_REQUEST['user_email'], "@")));
error_log( $login->get_error_message() );
}
}
}
}
The user is redirected to the career goals page using the form set up - hidden link
I also have a redirection code to redirect logged-out users away from the career goals page to the homepage. In the cases where the process does not work, the user is indeed directed to the homepage. This means
1. The user is created -- because the registration email is sent to the user
2. The user is redirected to the homepage -- it means the user was not auto-logged in.
My assumption is that cred_save_data runs before any redirection activity on the form. If that's the case, why would some users not be able to auto-login on registrations while others can?