Aleš Sýkora wrote

Auto login after creating new user with Toolset user form

11. 7. 2019 in

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Multistep form with Toolset Forms and Bootstrap Accordion
19. 9. 2018 in
Need to make long form simple to use? Use the accordion module from bootstrap and Toolset forms. Try it now! We provide you code snippets & easy tutorial.
Read More
Aleš Sýkora wrote
Disable WordPress admin bar for all except admins
17. 6. 2021 in
If you have your custom administration for users made with Toolset, you will propably need to hide the admin bar for your users except administrators. So if you have this question: “When you are logged in, the black wordpress top bar is showing up – is it possible to hide this bar for all users […]
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram