There’s sort of an existing solution for this. Discourse can be configured to be the DiscourseConnect provider for WordPress (the opposite of the usual configuration). It’s easy to setup. When enabled, there’s an optional setting that allows WordPress/Discourse accounts to be synced based on the user’s email address.
There’s even a link added to the user’s profile page:
(edit: can an image be captioned without ai?)
Testing it now, clicking the link on the profile page is not filling in the Discourse Username field. It should. Clicking the “Log in with Discourse” link that can be added to the login page does cause the Discourse Username field to be automatically updated.
I think the point of syncing accounts is to update the Discourse Username field in a secure way, so it’s probably worth looking at what’s going on with this. It also looks like there’s an issue where accounts that have an “unverified” email address on WordPress are allowed to sync their accounts with Discourse. That probably shouldn’t be allowed by default.
For your case, you might not want to allow users to login to WordPress via Discourse. It should be possible to just use the link on the profile page to allow users to sync their accounts so that their Discourse username field gets automatically filled in. You shouldn’t have to enable logging into WordPress via Discourse for this to work.
A possible downside of this approach is that users will have to initiate it. It wouldn’t provide a button that admins could click to get a user’s Discourse username.
