Skip Navigation

[Resuelto] Automatic Login Upon CRED User Form Submission

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 6 años, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 3 respuestas, tiene 3 mensajes.

Última actualización por Dallin Chase hace 6 años, 6 meses.

Asistido por: Minesh.

Autor
Mensajes
#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: enlace oculto

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

Idiomas: Inglés (English )

Zona horaria: 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!