Why can’t I update username through WordPress API?

I’m just wondering about usernames… Why isn’t is possible to change this through WordPress API? (I understand why a user in the admin dashboard can’t change username(s) but that isn’t really same thing!?)

Code below does just ignore the user_login – setting.

Read More
$pupil_obj= get_post($postid_pupil);

$user_login = $pupil_obj->post_name;
$user_nicename = $pupil_obj->post_name;

$user_args = array(
    'ID'            =>  $current_user->ID,
    'user_email'    =>  $email,
    'user_login'    =>  $user_login,
    'user_nicename' =>  $user_nicename                    
);                
wp_update_user( $user_args ) ;

I could update the username to the database directly through $wpdb. This makes no sense to me. Can someone explain?

Related posts

2 comments

  1. Looking on Trac I found a ticket that discusses exactly this issue: Administrator should be able to change usernames

    This is what it all boils down to:

    Changing usernames could break permalinks

    To prevent this a lot more than just changing the username in the DB would need to be done. E.g. redirection from old usernames.

    Caching Issues

    I quote from the aforementioned Ticket:

    “One problem you could get, if you do this using the db while using
    memcached, is the the old value remains in the store until memory runs
    out.”

    Denis-de-Bernardy

    TL;DR

    It may cause various problems and therefore is intentionally difficult to do.
    In case you think of this differently fell free to join the discussion in the corresponding ticket.

  2. There is a note on the wp_udate_user function codex page: http://codex.wordpress.org/Function_Reference/wp_update_user. And that is:

    Please note that we cannot change the usernames through this function, in fact the usernames cannot be changed from the admin dashboard as well since WordPress does not allow the usernames to be updated.
    

    So you can’t change the username using wordpress built in functions because WordPress developers think it’s not a good practice. There really are not any other explinations to this besides the one listed in the Note.

Comments are closed.