Navigation überspringen

[Gelöst] Automatic Login Upon CRED User Form Submission

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 vor 6 Jahren, 7 Monaten. 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)

Dieses Thema enthält 3 Antworten, hat 3 Stimmen.

Zuletzt aktualisiert von Dallin Chase vor 6 Jahren, 7 Monaten.

Assistiert von: Minesh.

Author
Artikel
#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: versteckter 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

Sprachen: Englisch (English )

Zeitzone: 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!