I have SSO setup with WordPress and have the SSO Avatar override setting set on discourse so that it uses the avatar URL from my WordPress site. However it does not seem to update if the person is using Gravatar and changes their Gravatar image.
If I look at the users profile SSO Info on Discourse I see the URL for the Gravatar icon and dropping that URL into my browser brings up the updated Gravatar.
I know Discourse caches these so that it does not have to make so many calls to Gravatar. How often does Discourse check for updates on this? Since I have the override with SSO set there is no way to refresh the Gravatar from the profile edit screen.
i also noticed if poeple go from a custom uploaded avatar or the default on my WP site then swtich to Gravatar the discourse forum does not update. It keeps the original avatar. Shouldn’t relogging in re-grab the avatar url and update?
I think the problem is that when a person changes their gravatar image, it doesn’t change the gravatar URL, so Discourse has no way of knowing that the avatar has changed. If a person wants their updated gravatar image to be used on Discourse, they need to go to their profile and edit their avatar. There is an option there to refresh the gravatar image.
What i did was add the avatar_force_update = true to the array parameters on the sso login string that is generated. This causes it to redownload the avatar each time the user logs in.
So far, I can’t get it working either. This works on a live site, I haven’t been able to get it working in my development environment. The SSO params that are sent to Discourse now have a filter applied to them, so you don’t need to override the plugin’s code.
Adding something like this to your functions.php file should work.
Does this work with custom Profile Builders at all? That have their own avatar upload feature built in?
My user avatars have the URL of something like"…/wp-content/uploads/…" but it doesn’t seem to update on Discourse, even with the avatar_force_update code above.
From looking at the Discourse code, it seems like it should work. Do you have the Discourse setting ‘sso overrides avatar’ enabled? If not, could you try enabling it and see if that makes a difference?
Yeah I have that enabled. I also tried creating a new account, setting the avatar, then navigating to Discourse to log in and complete the forum registration, but it still didn’t grab it then either.
It’s using https://www.cozmoslabs.com/wordpress-profile-builder/, which unfortunately isn’t free. I was using Learnpress’ Eduma theme earlier for profiles, and it wasn’t grabbing the avatar either (it was also saving to a custom folder).
There’s a filter in the wp-discourse plugin that you can use to change the avatar that’s sent to Discourse. From looking at the wordpress-profile-builder docs, it looks like they save the custom avatar as user metadata. From the example on this page, they are saving the avatar URL under the key ‘custom_field_57’: https://www.cozmoslabs.com/docs/profile-builder-2/manage-user-fields/avatar-upload-field/
Assuming that what is saved in that field is the absolute URL of the avatar, something like this will work. I’ve tested this on a live site by saving the string http://example.com/wp-content/uploads/my-profile-pic.jpg as user metadata. If it’s not an absolute URL that’s saved in that field, it will take a bit more work to put it together.
If you enable verbose sso logging on your forum, you’ll be able to see what values are being sent with the sso payload.
Edit: before trying this, enable the verbose sso logging setting on Discourse and take a look at the Discourse logs to see what URL is currently being sent as the avatar_url with the SSO payload.
In that case, I think you would need to use Simon’s code above, replace “custom_field_57” with “_ lp _ profile_picture” (again without the spaces), and add the first part of your URL (which I’m not quite sure how to do).