# New Wordpress users connecting to existing Discourse users

**URL:** https://meta.discourse.org/t/new-wordpress-users-connecting-to-existing-discourse-users/213550
**Category:** WordPress
**Created:** [December 31, 2021, 9:19pm UTC](https://meta.discourse.org/t/new-wordpress-users-connecting-to-existing-discourse-users/213550 "2021-12-31T21:19:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jord8on](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jord8on/32/166809_2.png) [@jord8on](https://meta.discourse.org/u/jord8on)
#### Post date: [December 31, 2021, 9:19pm UTC](https://meta.discourse.org/t/new-wordpress-users-connecting-to-existing-discourse-users/213550/1 "2021-12-31T21:19:00Z")

</div>

tl;dr - When a new WordPress user places an order or signs up, they appear to somehow be overwriting or connecting with existing users in Discourse. Not sure how to troubleshoot.

Background:

- We are using the wp-discourse plugin for SSO where Wordpress is the [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) Provider.
- We launched our Discourse community, hosted on a Digital Ocean droplet
- When we launched the discourse community and connected to SSO with the wp-discourse plugin, we were hosting WordPress on AWS Lightsail, using Plesk as our control panel
- We migrated to Nexcess WordPress managed hosting, earlier this year and the Discourse connector seemed to remain intact.
- We did not migrate our users when we moved to our new WordPress installation. They were exported, and we plan to import them soon.
- Our WordPress site has been closed down for a bit as we’ve been making some big adjustments

Over the past few months, we’ve had a lot of people placing orders on WordPress (WooCommerce), and we noticed something peculiar… that when you look at a user account in WordPress and look at the **Discourse Username** field, that their username is showing as those of existing users from Discourse. Somehow our connection to Discourse seems to be messed up. A user just signed up today and their **Discourse Username** is _tennisdpm_ which you can see is an [existing user](https://forums.pickleballist.com/u/tennisdpm/summary), who signed up back in 2020. 🤔

We are soon going to be migrating (adding) all of the users who had accounts on our old WordPress instance, and adding them to our new instance, but seeing how there seems to be some conflict with existing users and new users signing up, we want to had a plan of action that would prevent continued conflicts and sync existing WP users (via email as unique identifier) with Discourse users, and provision new SSO Discourse accounts, when new WP users come on board.

Would really appreciate some help and direction on how we should proceed!

Existing **wp-discourse** connect SSO settings:

 ![Monosnap 2021-12-31 13-37-54](https://global.discourse-cdn.com/meta/original/3X/b/2/b2fafc472e67273011157148c0f4d214729527ff.jpeg)

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [December 31, 2021, 9:36pm UTC](https://meta.discourse.org/t/new-wordpress-users-connecting-to-existing-discourse-users/213550/2 "2021-12-31T21:36:58Z")

</div>

> [@jord8on](#):
>
> We did not migrate our users when we moved to our new WordPress installation.

Sounds like your new WP users are getting user IDs which correspond to existing [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) External IDs.

 ![external-id](https://global.discourse-cdn.com/meta/original/3X/9/8/98f4d4a1e3e49d9d9e7e5327aa0bc7be0294477c.jpeg)

---

<div class="post-metadata">

### Author: ![jord8on](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jord8on/32/166809_2.png) [@jord8on](https://meta.discourse.org/u/jord8on)
#### Post date: [December 31, 2021, 10:31pm UTC](https://meta.discourse.org/t/new-wordpress-users-connecting-to-existing-discourse-users/213550/3 "2021-12-31T22:31:06Z")

</div>

Oh my!! Thanks for the heads up @omarfilip! Is there a way to reset this or prevent this from continuing to happen? Or maybe we could/should turn this off until we’re done migrating all former users.

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [December 31, 2021, 10:43pm UTC](https://meta.discourse.org/t/new-wordpress-users-connecting-to-existing-discourse-users/213550/4 "2021-12-31T22:43:10Z")

</div>

I’m really not sure what the best way to approach it would be. How many records are there that need to be fixed?

---

<div class="post-metadata">

### Author: ![jord8on](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jord8on/32/166809_2.png) [@jord8on](https://meta.discourse.org/u/jord8on)
#### Post date: [January 1, 2022, 5:57pm UTC](https://meta.discourse.org/t/new-wordpress-users-connecting-to-existing-discourse-users/213550/5 "2022-01-01T17:57:41Z")

</div>

We have about 80 users in WP right now that need to be “detached” from the current Discourse users with whom they seem to be associated. Then we also have about 750 users that we need to import, from our old instance, and be sure they are not having the same issue that we’re having right now.

I was hoping that accounts in WP were linked with Discourse account based on email address as the unique identifier… not external/user IDs.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [January 7, 2022, 2:41am UTC](https://meta.discourse.org/t/new-wordpress-users-connecting-to-existing-discourse-users/213550/6 "2022-01-07T02:41:38Z")

</div>

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

```plaintext
./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.

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

```

> For future folks reading this, if you use [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) 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.
