Aleš Sýkora / July 11, 2019 / 0 comments

Auto login after creating new user with Toolset user form

Post summary: Snippet from our fan.

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() );
}
}
}
}

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

0 comments

Share Your Thoughts