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

A few questions and some notes

However they will be the same on new signups, as you’re using DiscourseConnect. I’m assuming you’re ok with that, and you’re just concerned about syncing per se (i.e. after account creation)?

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?

Note that the “Update Userdata” webhook (see “Webhooks” in the WP Discourse settings) will update the Discourse Username in Wordpress when it’s changed in Discourse. That’s one part of the two way sync you’re envisaging.

So specifically what you’re after is just for the WP Discourse plugin to update the user’s Discourse username when it changes, yes?

Now, that field is used by different people for different purposes. Some people want to be able to edit that field without updating the username of the Discourse user associated with the account they use with DiscourseConnect.

However, there’s a relatively straightforward solution. We could just add an action somewhere around here 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 method in the WP Plugin’s Utilities, i.e.

use WPDiscourse\Utilities\Utilities as DiscourseUtilities;
$path = ''
$args =  array(
);
$response = DiscourseUtilities::discourse_request( $path, $args );

Using both the Webhook and action callback, you’d have a two-way sync in the way you’re envisaging, assuming you’ve accounted for the two questions I raised above.

Happy to review and merge a PR with an additional action along those lines.

4 Likes