Skip Navigation

[Resolved] Automatic Login Upon CRED User Form Submission

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to auto login after CRED user form submission or after user created using CRED form

Solution:
You can use CRED hook cred_save_data to perform such custom actions after CRED user form is submitted and to auto login the user.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/automatic-login-upon-cred-user-form-submission/#post-902725

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 6 years, 6 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 3 voices.

Last updated by Dallin Chase 6 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#902586

I am trying to: Automatically log in the user after they've submitted the user creation CRED form.

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

For context, I attempted the solution presented here: https://toolset.com/forums/topic/automatically-log-in-user-after-created/#post-621650

Not exactly sure what I'm doing wrong, but it didn't quite work as expected.

I'm just trying to have a seamless transition between account creation via the frontend user CRED form, and access to a post CRED form.

In my functions.php, I replaced "if ( 6 ==" with "if ( 820 ==" thinking that the "6" represented the form ID.

#902725

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Could you please check now. The issue was user_login field is not available on your CRED form.

That is why we need to adjust the code you added to your current theme's functions.php file - as given under:


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

I can see now, when you register the user - its successfully logged in. Couldy ou please confirm it works at your end as well.

#903176

Thank you very much. It works like a charm.

#1322619

Works great. Thank you!