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).