Skip Navigation

[Resolved] Redirect after login fails intermittently

This support ticket is created 2 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 1 reply, has 2 voices.

Last updated by Minesh 2 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2256457

I am using the toolset user form to auto-login and redirect users after registration. It works fine for many new users but I am also hearing from some new users that they are not redirected after registration.

I have tried this on my end and cannot replicate the issue.

 
add_action( 'cred_save_data', 'cred_autologin_V2', 10, 2 );
    
function cred_autologin_V2( $post_id, $form_data ){
  if ( 37260 == $form_data['id'] || 10365 == $form_data['id'] ) { // Edit as required
    if ( !empty( $_REQUEST['user_email'] ) && !empty( $_REQUEST['user_pass'] ) ) {
        
      // get the user credentials from the $_POST object
      $user = array(
        'user_login' => substr( $_REQUEST['user_email'], 0, strpos( $_REQUEST['user_email'], "@")),
        'user_password' => $_REQUEST['user_pass'],
        'remember' => true
      );
      $login = wp_signon( $user, false );
      if ( is_wp_error($login) ) {
        error_log('error during auto login, user_login was: ' . substr( $_REQUEST['user_email'], 0, strpos( $_REQUEST['user_email'], "@")));
        error_log( $login->get_error_message() );
      }
    }
  }
}

The user is redirected to the career goals page using the form set up - hidden link

I also have a redirection code to redirect logged-out users away from the career goals page to the homepage. In the cases where the process does not work, the user is indeed directed to the homepage. This means
1. The user is created -- because the registration email is sent to the user
2. The user is redirected to the homepage -- it means the user was not auto-logged in.

My assumption is that cred_save_data runs before any redirection activity on the form. If that's the case, why would some users not be able to auto-login on registrations while others can?

#2257111

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I'm not sure what could be the issue as you already acknowledged that it works for some users and not for others.

I see in your code you are trying to get username using the email and I think there might be the issue.

Could you please try to use the code shared with the following reference ticket:
=> https://toolset.com/forums/topic/automatically-log-in-user-after-registration/#post-629044