Skip Navigation

[Resolved] I am trying to install code to auto log in after user form but it doesn’t work

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 1 year, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2646905

When a user sign up form is actioned I would like it to auto log in.

I have found multiple codes on other forums that I have tried but don’t seem to be working. I could do with some detailed instructions on what code to add and how to get it to work.

My form ID is 7016 on toolset.

I would want to use the email as the user log in.

I have tried using code snippet to add the code and the custom code section in toolset settings.

Thank you in advanced.

#2647023

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Assuming that you have user email and password fields are available on the user form. What if you try to use the following code:
- you can add the following code to "Custom Code" section offered by Toolset or functions.php file of your current theme:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
function tssupp_cred_autologin( $post_id, $form_data ){
   
    if ( $form_data['id'] == 7016 ) {
   
        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() );
            }
        }
    }
}

If above code does not work then please share problem URL where I can see the user form as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.