Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building a plugin that will have a custom sign up process built in. I would like the users to be able to change their username if needed, since I am using their email address as the username. I have set up a custom role that is assigned to them on sign up. I won't be using posts at all for these roles, it's a donation plugin so it will be storing transactions and other info all in the user meta table. I just want to know if there are any drawbacks, issues, with changing the username?

Here is the function I will be using to change the username:

function change_username( $user_id, $username ) {

    global $wpdb;

    $wpdb->update( 
        $wpdb->users, 
        array( 
            'user_login'    => $username,
            'user_email'    => $username,
            'user_nicename' => preg_replace( "![^a-z0-9]+!i", "-", $username )
        ),
        array( 
            'ID' => $user_id
        )
    );

}

Any input is greatly appreciated, thanks!

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.