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

share|improve this question
    
I know HOW to do solve the issue, but I was asking WHY I have to directly against the db instead of through the API. I think it would make more sense for it to be available through the API, because the API could control diffrent things/errors/warnings that could error when changing the username. –  bestprogrammerintheworld Feb 20 at 12:53

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
So basically - you can't do it through the API because that would make the WP - developers responsible? ;-) –  bestprogrammerintheworld Feb 20 at 12:54
    
Kind of. It seems as if they only want to have this feature if it works in every situation with no bad side-effects. But if you want to discuss this, WPSE probably isn't the right place, that is why I added the link to the Trac ticket. –  kraftner Feb 20 at 13:05
    
Ok, thank you! :-) (I asked because I thought there was some real issue with the change of usernames. It seems it's all about taking precaution) –  bestprogrammerintheworld Feb 20 at 13:33

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.

share|improve this answer
    
This is not exactly an answer, because I've already mentioned this in my question. My real issue was WHY it isn't recommended and WHY can't I do it through the Wordpress API? –  bestprogrammerintheworld Feb 20 at 12:37
    
I edited my comment. The first part was the actual answer. The MySql part was just about the only solution there is. –  Ovidiu Iacomi Feb 20 at 12:48

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.