Navigation überspringen

[Gelöst] Automatically log-in after user is created

This support ticket is created vor 4 Jahren, 5 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

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

Zuletzt aktualisiert von Lara vor 4 Jahren, 5 Monaten.

Assistiert von: Shane.

Author
Artikel
#1719987

Tell us what you are trying to do?
1. Create new user through CRED form
2. Automatically log-in after the CRED form is submitted

TOOLSET SETTINGS

/**
* Auto-login new CRED user
*/
add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
    
function tssupp_cred_autologin( $post_id, $form_data ){
    
if ( 8377 == $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( $login->get_error_message() );
}
    
}
}
}

CODE USER CREATION CRED FORM

[creduserform]
[cred_field field='form_messages' class='alert alert-warning']

[cred_field field='first_name' class='cuteberry-register-inputfield' placeholder='Vorname' output='bootstrap']

[cred_field field='last_name' class='cuteberry-register-inputfield' placeholder='Nachname' output='bootstrap']

[cred_field field='user_email' class='cuteberry-register-inputfield' placeholder='E-Mail' output='bootstrap']

[cred_field field='telefonnummer-benutzer' force_type='field' class='cuteberry-register-inputfield' output='bootstrap']

[cred_field field='strase-des-benutzers' force_type='field' class='cuteberry-register-inputfield' output='bootstrap']

[cred_field field='hasunummer-des-benutzers' force_type='field' class='cuteberry-register-inputfield' output='bootstrap']

[cred_field field='postleitzahl-des-benutzers' force_type='field' class='cuteberry-register-inputfield' output='bootstrap']

[cred_field field='stadt-des-benutzers' force_type='field' class='cuteberry-register-inputfield' output='bootstrap']

[cred_field field='user_pass' class='cuteberry-register-inputfield' output='bootstrap']

[cred_field field='recaptcha' class='' output='bootstrap']

[cred_field field='form_submit' output='bootstrap' value='Registrieren' class='cutberry-registrieren-button-blau']
[/creduserform]

Additionally I made sure, that the passwort is not auto-generated. Username and Nickname are auto-generated. I feel like, that there is a little bug somewhere and I can't see it.

Is there any documentation that you are following?
https://toolset.com/forums/topic/autologin-after-user-registration-not-working/
I tried some of the other documentations regarding this topic, too - without success.

Is there a similar example that we can see?
In the documentation

What is the link to your site?
versteckter Link

#1720047

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Lara,

Thank you for getting in touch.

Would you mind allowing me to have admin access to the website as well as a link to the page where the form is so that I can have a look to see why its not allowing you to auto log in ?

Thanks,
Shane

#1720805

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Lara,

The code actually works. The problem was that you didn't activate it.

Your users should now be logged in after they have registered on your form.

Thanks,
Shane

#1720959

Many thanks Shane 🙂