WORDPRESS - Oxygen - toolset

Auto login after creating new user with Toolset user form

Author: Aleš Sýkora, 11. 7. 2019

Snippet from our fan, who do not give us his name :-D, just call him Unknown Toolset Fan.

You must update the id to your login form id.

// Auto log-in new user
add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
function tssupp_cred_autologin( $post_id, $form_data ){
// Set login form ID (in this case mine is 1187)
if ( 1187 == $form_data['id'] ) {

if ( !empty( $_POST['user_email'] ) && !empty( $_POST['user_pass'] ) ) {

$user = get_user_by( "email", $_POST['user_email'] );

$signon = array(
'user_login' => $user->user_login,
'user_password' => $_POST['user_pass'],
'remember' => true
);

$login = wp_signon( $signon, false );

if ( is_wp_error($login) ) {
error_log( $login->get_error_message() );
}
}
}
}