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.

$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?

2 s
2

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.

Leave a Comment