Skip Navigation

[Resolved] The auto login snippet doesn't work anymoe

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

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 3 replies, has 2 voices.

Last updated by Minesh 3 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1618015

I am trying to:
Auto login my users after sign up with cred form.

Link to a page where the issue can be seen:
hidden link

I expected to see:
Redirect and login

Instead, I got:
It seems the user is being redirected and logged, but not showing as logged in on the front end. At least in Opera.

I've tried disabling all other plugins and deactivated other custom snippets, but still doesn't seem to work.

Here is my code

add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
 
function tssupp_cred_autologin( $post_id, $form_data ){
 
    if ( $form_data['id'] == 3796731  ) { // Edit as required
 
        if ( !empty( $_POST['user_email'] ) && !empty( $_POST['user_pass'] ) ) {
 
            // get the user credentials from the $_POST object
            $user = array(
                'user_login'    =>   $_POST['user_email'],
                'user_password' =>   $_POST['user_pass'],
                'remember'      =>   true
            );
            $login = wp_signon( $user, false );
 
            if ( is_wp_error($login) ) {
                error_log( $login->get_error_message() );
            }
 
        }
    }
}

It was working before, but something has updated or something i'm missing.

#1619353

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I checked on your install and yes I confirm that the code you added with the help of Toolset form API hook cred_save_data for autologin the user is not working.

But the strange thing is that the same code I've added with my test site where I tried to create a user with the same subscriber role using Toolset form and it works without any issue on my test site.

You can create a new user with my test site using the following link: hidden link
- As soon as you create new user, it will be redirected to home page and it will autologin as well.

If you want backend access, you can use: hidden link
User: demo
pass: Admin@123

I've used the following code - which is added to "Custom Code" section of Toolset:
=> hidden link

add_action( 'cred_save_data', 'func_tssupp_cred_autologin', 10, 2);
function func_tssupp_cred_autologin( $post_id, $form_data ){
 
    if ( $form_data['id'] == 1708  ) { // Edit as required
     
 
        if ( !empty( $_POST['user_email'] ) && !empty( $_POST['user_pass'] ) ) {
          
          $user = get_user_by( "email", $_POST['user_email'] );
            
            // get the user credentials from the $_POST object
            $user = array(
                'user_login'    =>   $user->user_login,
                'user_password' =>   $_POST['user_pass'],
                'remember'      =>   true
            );
            $login = wp_signon( $user, false );
 
            if ( is_wp_error($login) ) {
                error_log( $login->get_error_message() );
            }
 
        }
    }
}

As its working with the minimum setup where only Toolset plugins installed with the default theme, I suggest in order to minimize the cause of the issue:
Could you please try to resolve your issue by deactivating all third-party plugins as well as the default theme to check for any possible conflicts with any of the plugins or themes?
- Do you see any difference or found plugin/theme is causing the issue?

#1623609

Hi Minesh,

Thanks so much for your help with this. Have already tried disabling all plugins to no avail. I'm going to use your code and give it ago, will update shortly.

#1623731

Minesh
Supporter

Languages: English (English )

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

Ok fine - As I shared the link to my test site, it works as expected so there must be something going on with third-party plugin/theme or server. You need to check where the issue is.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.