Skip Navigation

[Resolved] Set username as user password – CRED save data

This thread is resolved. Here is a description of the problem and solution.

Problem:

How to update WordPress user login name?

Solution:

There isn't such kind of built-in feature even WordPress core, you might try custom codes, for example, below similar thread, which update username with SQL query:

Relevant Documentation:

https://stackoverflow.com/questions/46972779/unable-to-update-an-username-in-wordpress#answer-46972861

This support ticket is created 2 years, 1 month ago. 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Paul 2 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#2319259

Hello there,

I have the following code. However this is only setting the User Nickname as the email address, I need it to set the actual username. What would I need to change?

Many thanks

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'] ) );
        }
    }
}
#2320211

Hello,

I assume you are going to change user's password value to user's email. If it is, you can try WordPress function wp_set_password(), for example:

wp_set_password( $_POST['user_email'],  $post_id);

More help:
https://developer.wordpress.org/reference/functions/wp_set_password/

#2320591

Hi there,

Thanks for the reply but no, I want to set the username as the user_email. The current code added by the supporter just seems to set the Nickname and doesn't update the username

Many thanks

#2322327

There isn't such kind of built-in feature even WordPress core, you might custom codes, for example, below similar thread, which update username with sql query:
https://stackoverflow.com/questions/46972779/unable-to-update-an-username-in-wordpress#answer-46972861

For your reference.

#2322783

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.