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?
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:
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.
There is a note on the wp_udate_user function codex page: http://codex.wordpress.org/Function_Reference/wp_update_user. And that is:
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.