Change Username, Email in External DB
-
Another question – my client wants to be able to modify Username and Email fields in the external DB and have the WP users table updated as well. Is this something I need to write into my Ext DB GUI (forms) or is there a way to modify your plugin to allow for this? Note that we can now update passwords in the external GUI and these also update in WP but updating email did not. Currently, username in the external db UI is also non-editable like WP.
-
Hey @rjjacob,
When an e-mail address is changed in the external DB, it will be updated in WordPress the next time the user logs in. I’ve just double checked this on my local install but if you’re not experiencing this please let me know.
Regarding username – this gets a lot more complicated as this is the users unique identifier. Because of this I know one company that will not allow this default in the admin areas but will manually make the change on the database in extenuating circumstances.
The reason this gets tricky is because when logging in, the external database is queried to find the username and then checks the password to authenticate. This username is what ties the external database to the WordPress one. In WordPress, (like a lot of user systems), the username can not be changed by default in the admin area however their display name can be modified.
If you did want this functionality there is a fair bit or work involved as the only way I can currently think of to solve this would be to:
1) Add another setting to the settings page to use another field from the external DB as the unique identifier. Hopefully it has a userID field or something similar in the users table.2) Have additional checks at login that if this functionality is chosen, it checks all users meta data for this value to see if the userID is already used.
3) Check to see if the username they are trying to change to is already in use as this will also have to be unique for WordPress to function correctly (would need to double check this).
4) If write some custom code to modify the user (including their username). Then allow WordPress to continue with its normal login process.
This is a relatively big feature. I welcome your thoughts incase you think I’ve missed anything?
Thank you for your quick and thorough reply.
Updating email in external DB is not updating in WP table. I tried updating email then logged out of user account then logged back in with email and no go. Tried logging in with username first, then logging out, then logging in with new email and still no go.
I understand the username issue and the hassle to change that WP functionality. I kind of figured as much because the IDs in the WP table were auto-incremental and not lining up with the IDs in the external users table. Also, no additional tables were created with your plugin which mapped them. Just thought I’d check. We can stick with a “no change” policy except at the db level by someone with access to phpMyAdmin or whatever.
Hey @rjjacob,
Won’t be able to check until tomorrow as at a family event. This is a good excuse to escape for 5mins ??
I could see the db change on my end this morning, however I hadn’t tried logging in with the e-mail (I always use the username) to make sure that logging in with email would work.
The only other thing I would ask you to do when testing this is to turn off the setting that falls back to the WP database for logging in if the external database isn’t available. On the off chance the external db connection failed on the test it would hide the issue and keep the current user details.
I will test this again tomorrow to confirm we’re getting different results but if you can check the above in the mean time that’d be great.
Regarding the username. If your client is happy that sounds great. If not, get back in contact and I can add it to the backlog but I’ve got a handful of other feature requests to cater for first.
In the meantime, let’s definitely fix this email updating issue ??
Tom
Hey @rjjacob,
I think I know what the e-mail problem is! My plugin only allows you to login with a username at the moment.
This means that you must have used the username once to get the user across in the first place. Then, when using e-mail to login, it is falling back to use the local WordPress database for logging in and thus not getting new data from the external one.
I will make e-mail addresses work for you for logging in in my next release.
Do you have a deadline for when you need this by?
Thanks,
Tom
I had this issue so I mapped the user and email together. This effectively made email the only option to login. I’m glad to see it will be addressed in the next release.
Great point @johnfisher2!
If it’s just an e-mail address that your external system uses for logging in you can make that the “username” field as well as the e-mail field in table mapping.
The thing the plugin doesn’t support is the ability to log in with either username or password for your users.
My initial thought was this is not abnormal but I then remembered WordPress does support this and asks for “Username or Email Address” in the default login screen.
I’ve started planning how I’ll solve this.
Will try and keep progress updates in this thread but let me know if you’ve got a deadline you need to meet as I feel this is something I should have thought about.
Thanks for the update. I don’t have a deadline to meet – we can make do with the username only for now.
I guess now is the time for a deadline – updating a role in the external table is not updating it in the WP table. Is there a way to fix this so that updating fields in the external tables will also update them in the WP tables? Isn’t that what the plugin should be doing anyway?
Thanks in advance!
Hey @rjjacob,
I think the thing that feels initially strange about this flow is that WordPress uses the Username as the unique identifier. For this reason I am doing the same.
By setting the username to the e-mail and then wanting this to be able to be updated, as a unique identifier, doesn’t make sense.
I welcome your opinion on the way this would be solved but my current thought is:
- You set the username in WordPress to be the primary key of the external Users table (assuming this is what that system uses to uniquely identify users. This would need testing as I don’t know how grumpy WordPress will get if your primary key is an integer.
- This would still require that external login would support e-mail as a (as well as username) when logging in.
Again your opinion is welcomed.
Tom
- The topic ‘Change Username, Email in External DB’ is closed to new replies.