Passer la navigation

[Résolu] CRED User form – new user email as username

This support ticket is created Il y a 3 années et 3 mois. 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 -

Fuseau horaire du supporter : America/Jamaica (GMT-05:00)

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Shane Il y a 3 années et 3 mois.

Assisté par: Shane.

Auteur
Publications
#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

Les langues: Anglais (English )

Fuseau horaire: 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