Saltar navegación

[Resuelto] CRED User form – new user email as username

This support ticket is created hace 2 años, 10 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.

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)

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Shane hace 2 años, 10 meses.

Asistido por: Shane.

Autor
Mensajes
#2311253

Hi there,

Can you help me with a function that will set the new user "username" as the email address when the form saves?

Many thanks

#2311327

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Paul,

Thank you for getting in touch.

add_action('cred_save_data', 'update_username',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12)
    {
        if (isset($_POST['user_email']))
        {
           wp_update_user( array( 'ID' => $post_id, 'user_login' => $_POST['user_email'] ) );
        }
    }
}
 

Please try the above code and let me know if it helps. Replace the 12 with the ID of the form that you want this code to be triggered for.

Finally this code can be added to Toolset -> Settings -> Custom Code and ensure that its activated.

Please let me know if this helps.
Thanks,
Shane