Changing a username

22 views
Skip to first unread message

Mike Witt

unread,
Oct 30, 2020, 7:47:28 PM10/30/20
to manchester-word...@googlegroups.com
Does anyone know of any reason that I can't change a username simply by
editing user_login in the users table in the database?

I have always been under the impression that "you can't change a
wordpress user name" but as far as I can tell, it only appears in the
users table and the ID is what's actually used everywhere else.

Am I missing something? Any caveats?

Mike Little

unread,
Oct 31, 2020, 12:32:47 PM10/31/20
to Manchester WordPress WordPress User Group (MWUG)
You can change a user name directly in the database, I've done it many times. 

Just be careful that some (badly written) plugin hasn't used the name instead of the id somewhere. That happened to me once.

I would do a search for the username in a SQL dump of the database just to check it isn't referenced anywhere. 


Stay safe and healthy.
Best regards,

Mike Little
WordPress Specialist
https://mikelittle.org
Sent from my 'phone, please excuse any brevity and any auto-correct mistakes.

--
See the group blog at https://mwug.uk

You received this message because you are subscribed to the Google
Group "Manchester WordPress User Group".

To post to this group, send email to
manchester-word...@googlegroups.com

For more options, visit this group at
https://groups.google.com/group/manchester-wordpress-user-group
---
You received this message because you are subscribed to the Google Groups "Manchester WordPress User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to manchester-wordpress-...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/manchester-wordpress-user-group/1604101646.25939.75%40Vector.

Mike Witt

unread,
Oct 31, 2020, 1:40:33 PM10/31/20
to manchester-word...@googlegroups.com
Mike, Great advice about searching the dump. I hadn't thought of that.
Thanks!

On 10/31/2020 10:32:26 AM, 'Mike Little' via Manchester WordPress User
> https://groups.google.com/d/msgid/manchester-wordpress-user-group/CAMb54M2VsHhZik-BqDhtcNW9Dy3U1XfE7tMSAMC-UE3rYSYD-w%40mail.gmail.com.
>

Mike Witt

unread,
Nov 2, 2020, 1:13:09 PM11/2/20
to Manchester WordPress User Group
Some follow up on this. Apparently I was wrong when I said that the username only appeared in the users table. After taking Mike's advice and greping through the database dump I found it other places. When I went back to phpMyAdmin and searched the live database *correctly* I also found it there :-)

It appears, for example in the comments table (if that users has ever commented on a post). And potentially other places.

So maybe I'm just confused somehow. Mike: when you did this, did you have issues with comments? Or else maybe this isn't a good way to go about changing a username.

I've also done a bit of searching on this, and found a number of places (wp stackexchange for example) where a number of people say a simple change of user_login in the users table  *does* do the trick. There are also some plugins which claim to change a name. Wonder exactly what they do?

I also wonder how foolproof it actually is to delete a user and reassign their content to a new users. I wonder if that really gets everything?

In terms of plugins making use of the user_login (rather than the ID), it definitely appears that BuddyPress uses the user_login string rather than the ID for some things. And maybe bbPress. Again, unless I'm somehow very confused, which is certainly possible.

Mike Little

unread,
Dec 13, 2020, 2:00:48 PM12/13/20
to Manchester WordPress WordPress User Group (MWUG)
Sorry, I missed this reply for some reason.

In the comments table if a user is logged in then it will store their user ID in the appropriate column, so the relationship between a user and their comments will remain. However as you have seen it also stores the name in there specifically for non logged in commenters. So you would have to change it their to for consistency.

This is sufficient for standard WordPress and likely most cases to change it in the database as most references to a users should be stored via their unique ID which won't change. However there are cases where the user login is stored. Sometimes that is to save having to do a database lookup when displaying the name e.g. comments and possibly some parts of BuddyPress.

It is always down to the individual site and the plugins, themes, and custom code running on there. If I were to be doing it I would do the search in the DB dump as you have done and investigate each occurence I found to figure out what the impact would be of changing it. 

To be honest, I would be tempted to firstly, work on a copy of the site. Take a backup of the DB, then do the search and replace. Then check all the places where you saw the username had been used.






  



--
Stay safe and healthy, best regards,

Mike



-- 
Mike Little
WordPress Specialist

Twitter: @mikelittlezed1

Founder and Director
Zed1.com Limited
https://zed1.com
Registered in England & Wales, no. 6745562

Mike Witt

unread,
Dec 13, 2020, 3:10:39 PM12/13/20
to Manchester WordPress User Group
No problem.

It turns out that there are enough issues with plugins (BuddyPress for example) that I'm not going to be able to do this, at least not with the amount of work I can afford. I'm just going to tell people they'll have to rejoin with a new login and have wordpress reassign the content that it's capable of (which is quite a bit).
Reply all
Reply to author
Forward
0 new messages