New Wordpress users connecting to existing Discourse users

Hey @jord8on, the way the matching works on the discourse end of things is that it first tries to match the external id (which in your case now point to different users as you’ve changed your Wordpress database), and then tries to match using the email address. There are some good reasons for using ID first. Email is not a great decentralised identifier.

So what you need to do is delete the single sign on records in discourse created when you were using your old wordpress database. You can use a datetime to identify them, e.g. you’d do something like this on your discourse instance

./launcher enter app
rails c
SingleSignOnRecord.where("created_at < ?", 1.month.ago) // check if this matches your expectations
SingleSignOnRecord.where("created_at < ?", 1.month.ago).delete_all

The old users being imported to the new db will be matched on the basis of email to their existing discourse accounts (as their new wordpress id won’t match any sso records).

I would also remove all discourse_username data on wordpress and let it be automatically re-synced via the user webhook. You’ll need to run this (perhaps using WP CLI), which deletes all entries for the discourse_username meta field.

delete_metadata( 'user', 0, 'discourse_username', '', true );

For future folks reading this, if you use DiscourseConnect with one Wordpress database, then move to an entirely new Wordpress database without a migration, you’re going to have this kind of issue. You should seek assistance before doing this kind of change.

2 Likes