The discussion is about syncing avatars from Discourse to WordPress automatically. Shauny initially asked how to achieve this, as they want to use Discourse’s avatar system instead of WordPress’. Shauny later found a solution using Webhooks and shared the general steps:
creating a Discourse webhook that posts to a PHP file when a profile is updated,
saving the avatar URL as a custom meta field in WordPress, and
updating the WordPress code to return the meta field as the user avatar. jrgong and jrgong asked Shauny to share the code snippets used, to add to the WP/SSO documentation or community tutorials, which Shauny agreed to do once they have access to their computer.
I’ve tried searching but find topics about doing this the other way round but not this way…
My WordPress website is a DiscourseConnect Provider to my Discourse forum, so people log into the forum with their WordPress account.
I used to have it so you went to the website to update your avatar, using a plugin, and it uploaded that to Discourse, but I’d like to switch this around because the Discourse avatar stuff is so much nicer. I’d like it so the website grabbed the avatar from the Discourse forum on login, or whenever it changes.
Away from computer at the moment but here’s the steps I took, you should be able to do it if you read about the various things I used:
Create a Discourse webhook that posts to a PHP file in your plugin/theme any time someone updates their profile
On the PHP page, get the payload which includes the User ID. Get the avatar URL from that, and save it as a custom meta field against the user in WordPress
Update the code in WordPress that returns a user avatar with a function that instead returns that meta field