# 将 Discourse 中的 Avatar 自动同步到 Wordpress

**URL:** https://meta.discourse.org/t/sync-avatar-from-discourse-to-wordpress-automatically/329386
**Category:** SSO
**Created:** [2024年十月4日 17:43 UTC](https://meta.discourse.org/t/sync-avatar-from-discourse-to-wordpress-automatically/329386 "2024-10-04T17:43:54Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Shauny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shauny/32/362012_2.png) [@Shauny](https://meta.discourse.org/u/Shauny)
#### Post date: [2024年十月4日 17:43 UTC](https://meta.discourse.org/t/sync-avatar-from-discourse-to-wordpress-automatically/329386/1 "2024-10-04T17:43:54Z")

</div>

我尝试搜索过，但只找到了关于反向操作的主题，而没有找到关于这个方向的……

我的 WordPress 网站是 [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) 提供商，我的 Discourse 论坛，所以人们用他们的 WordPress 账户登录论坛。

我以前是这样设置的：你访问网站来更新你的头像，使用一个插件，它会将头像上传到 Discourse，但我希望反过来，因为 Discourse 的头像功能好用得多。我希望网站在登录时，或者头像更改时，从 Discourse 论坛抓取头像。

这可能吗？

谢谢！

---

<div class="post-metadata">

### Author: ![Shauny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shauny/32/362012_2.png) [@Shauny](https://meta.discourse.org/u/Shauny)
#### Post date: [2024年十月4日 19:59 UTC](https://meta.discourse.org/t/sync-avatar-from-discourse-to-wordpress-automatically/329386/2 "2024-10-04T19:59:45Z")

</div>

没关系，我用 Webhooks 自己解决了！

---

<div class="post-metadata">

### Author: ![jrgong](https://avatars.discourse-cdn.com/v4/letter/j/c57346/32.png) [@jrgong](https://meta.discourse.org/u/jrgong)
#### Post date: [2025年四月22日 13:36 UTC](https://meta.discourse.org/t/sync-avatar-from-discourse-to-wordpress-automatically/329386/3 "2025-04-22T13:36:49Z")

</div>

嘿 Shaun

你能分享一下你的解决方案吗？我们也想实现同样的目标，我很想知道你是怎么做到的。🙂  
此致  
Jr

---

<div class="post-metadata">

### Author: ![Shauny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shauny/32/362012_2.png) [@Shauny](https://meta.discourse.org/u/Shauny)
#### Post date: [2025年四月22日 13:52 UTC](https://meta.discourse.org/t/sync-avatar-from-discourse-to-wordpress-automatically/329386/4 "2025-04-22T13:52:25Z")

</div>

暂时离开电脑，但这是我采取的步骤，你应该能够做到，如果你阅读我使用的各种内容：

1. 创建一个Discourse的Webhook，每当有人更新他们的个人资料时，将信息发布到你的插件/主题中的一个PHP文件
2. 在PHP页面上，获取载荷其中包括用户ID。从中获取头像URL，并将其作为自定义元字段保存到WordPress中的用户
3. 更新WordPress中返回用户头像的代码，用一个函数替代返回该元字段

就是这样！

---

<div class="post-metadata">

### Author: ![jrgong](https://avatars.discourse-cdn.com/v4/letter/j/c57346/32.png) [@jrgong](https://meta.discourse.org/u/jrgong)
#### Post date: [2025年四月22日 14:24 UTC](https://meta.discourse.org/t/sync-avatar-from-discourse-to-wordpress-automatically/329386/5 "2025-04-22T14:24:16Z")

</div>

我倒是想知道你是否能分享你使用的代码片段，然后我们可以将它们添加到 WP / SSO 文档或社区教程中？🙂

---

<div class="post-metadata">

### Author: ![Shauny](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shauny/32/362012_2.png) [@Shauny](https://meta.discourse.org/u/Shauny)
#### Post date: [2025年四月22日 14:38 UTC](https://meta.discourse.org/t/sync-avatar-from-discourse-to-wordpress-automatically/329386/6 "2025-04-22T14:38:50Z")

</div>

好的，一旦我能访问我的电脑 😀
