Shauny is seeking to programmatically update avatars in Discourse when users change their avatars on a WordPress site using Ultimate Member. angus provides a solution using the DiscourseConnect SSO functionality, suggesting the use of DiscourseUtilities::sync_sso_record with the avatar_force_update parameter to force an avatar update. Shauny confirms the approach works but notes that the um_after_upload_db_meta_profile_photo hook fires before the avatar file is moved, resulting in the old avatar being sent. The discussion highlights the integration between WordPress and Discourse via SSO, with a focus on automating avatar updates.
I have this all set up and working so if someone changes their avatar on my WordPress site and then logs out of the forum and logs in again, it updates the avatar on Discourse.
But people don’t know to log out, and that’s quite annoying, so I’d like to trigger it myself. I have a hook that fires when someone updates their avatar. What can I add for it to send the new avatar to Discourse directly?
use WPDiscourse\Utilities\Utilities as DiscourseUtilities;
add_action("um_after_upload_db_meta_profile_photo", "um_custom_after_upload_profile_photo", 10, 1 );
function um_custom_after_upload_profile_photo( $user_id ){
$avatar_url = // Ultimate Member avatar URL
$params = array(
'external_id' => $user_id,
'avatar_url' => $avatar_url,
'avatar_force_update' => 'true'
)
DiscourseUtilities::sync_sso_record( $params, $user_id );
}
You’ll need to figure out the URL for the avatar on Wordpress (you’ll perhaps find this in the Ultimate Member documentation) and set that to the variable $avatar_url.