# Two-way Sync Between WP Discourse Username and Discourse Username?

**URL:** <https://meta.discourse.org/t/two-way-sync-between-wp-discourse-username-and-discourse-username/220018>\
**Category:** WordPress\
**Created:** [March 4, 2022, 12:53am UTC](https://meta.discourse.org/t/two-way-sync-between-wp-discourse-username-and-discourse-username/220018 "2022-03-04T00:53:36Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![dbwhite](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dbwhite/32/247431_2.png) [@dbwhite](https://meta.discourse.org/u/dbwhite)\
**Post date:** [March 7, 2022, 2:50am UTC](https://meta.discourse.org/t/two-way-sync-between-wp-discourse-username-and-discourse-username/220018/6 "2022-03-07T02:50:34Z")

</div>

> [@angus](#):
>
> However they will be the same on new signups, as you’re using [DiscourseConnect](https://meta.discourse.org/t/13045). I’m assuming you’re ok with that, and you’re just concerned about syncing per se (i.e. after account creation)?

We are actually overriding this behavior with the `wpdc_sso_params` filter hook because our SSO system integrates Firebase and everyone’s WP username defaults to their Firebase UID, so we are changing the Discourse default to be `memberXXX` (with XXX being a number). We actually want to change this default to be the user’s `Firstname_Lastname` at some point as well. But yes our primary concern is users being able to change their username easily via their profile page within our Wordpress site.

> [@angus](#):
>
> How are you envisaging the case when a user creates a Wordpress account and has not yet signed in to Discourse? No Discourse account will exist. In that case the Discourse Username field would not be editable?

In this case I am thinking we can either store the username field and have it sync when the account is created (via the `wpdc_sso_params` filter hook on the first SSO), or we could force a Discourse account to be created for every member when they sign up on our Wordpress site via the Discourse API. The second option would probably be more advantageous because we would know that everyone has a Discourse account and there would thus be fewer special cases of some users having accounts and others not. But we are really going for a seamless experience, so we want this username to be what the user thinks of as their username for our entire platform. We want it to always be editable, and in the future we will probably use it for more than just Discourse (i.e. in leaderboards, etc.).

> [@angus](#):
>
> So specifically what you’re after is just for the [WP Discourse](https://github.com/discourse/wp-discourse) plugin to update the user’s Discourse username when it changes, yes?

Yes this is exactly what we need!

> [@angus](#):
>
> However, there’s a relatively straightforward solution. We could just add an [action](https://developer.wordpress.org/reference/functions/add_action/) somewhere around [here](https://github.com/discourse/wp-discourse/blob/main/admin/user-profile.php#L131) so that you could use a PUT request to Discourse to update the username on Discourse, i.e. like you are now. I’d just add that the easy way to do that is to use the abstracted [discourse\_request](https://github.com/discourse/wp-discourse/blob/main/lib/plugin-utilities.php#L364) method in the WP Plugin’s Utilities, i.e.

Understood! Thanks for this direction, my team and I will work on testing this with our implementation first and should make a PR soon!

---

_[View the full topic](https://meta.discourse.org/t/two-way-sync-between-wp-discourse-username-and-discourse-username/220018)._
