Here you go. I have also tried with a manual password field. The user is being created and the form is redirecting to the correct page, but not with the new user in a logged in state.
Thank you. That makes perfect sense. However, I have also tried this with a manual password field in place, but the result was the same. The user was registered and correctly redirected, but not in a logged in state. You can test here: hidden link
I have not got this working but I have changed the architecture of my journey. I am now using the mailchimp sign-up form, pre-populating the email field on my Toolset registration form as a second step via a url query.
This has allowed me to acheive my goal, perhaps slightly more elegantly, too.
Happy to see that you were able to continue working on your site. I also must apologize for the delay in response. My shift had ended when the response was submitted.
However should you require this in the future the modified code below should get it working for you.
/**
* Auto-login new CRED user
*/
add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
function tssupp_cred_autologin( $post_id, $form_data ){
if ( 12788 == $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( $login->get_error_message() );
}
}
}
}
Just replace the 12788 with the id of your form and this should login the user after they register.
Still can't get it working with the solution you have provided. I have an email and password field and am using your code with the form ID changed. It is successfully registering users but still failing to log them in.
Please can you assist? Perhaps you would like to activate hidden fields here, so that I may give you access.