There’s a helper function in the Utilities
file for this:
DiscourseUtilities::sync_sso_record( $sso_params );
Yesterday I posted an example of how to use it: I cannot add user to the discouse forum from a wordpress website when user added in a membership - #10 by simon. The tricky part is to create the array for the sso_params
argument. That array must contain the external_id
field. It is set to the user’s WordPress ID:
$sso_params = array(
'external_id' => $user_id,
);
You can include any fields from this list in the payload: discourse/lib/discourse_connect_base.rb at 8f52fd1051e20fdff41321c5cff99fda05af86c1 · discourse/discourse · GitHub. Note the BOOLS
array that is shown just under the ACCESSORS
list that I linked to. It indicates which of the possible options are booleans
(true/false). When making requests from WordPress, any boolean fields must be set with the strings 'true'
or 'false'
, not with the PHP true
or false
values.
For updating the avatar, set the avatar_url
field in the $sso_params
array and also set the avatar_force_update
field to 'true'
.
There’s a bio
field that can be used for setting the bio.
The WP Discourse plugin is already setting the bio
and avatar_url
fields. It also has a “Force Avatar Update” setting in its SSO settings. The problem might be that these settings are only updated when a user logs into Discourse via the WordPress site. The sync_sso_record
function updates the fields immediately, without requiring the user to login to Discourse.
Also, if you’re finding that users bios are not getting set as on Discourse, it could be that they aren’t being set on your WordPress site where the plugin is expecting them to be: wp-discourse/lib/plugin-utilities.php at 99325e15190f3a705284dbf582f1c4b2c0b21492 · discourse/wp-discourse · GitHub. If Woocommerce has a different field for bios, you could access that field and use it in a call to sync_sso_record
.