# SSO Avatar Not Updating

**URL:** https://meta.discourse.org/t/sso-avatar-not-updating/25569
**Category:** WordPress
**Created:** [2015年二月23日 15:05 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569 "2015-02-23T15:05:54Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [2015年二月23日 15:05 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/1 "2015-02-23T15:05:54Z")

</div>

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.

Thanks

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [2015年二月27日 16:52 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/2 "2015-02-27T16:52:28Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [2015年三月2日 15:49 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/3 "2015-03-02T15:49:46Z")

</div>

I found out that there is a avatar\_force\_update function that was merged into the master.

[https://github.com/discourse/discourse/pull/2670](https://github.com/discourse/discourse/pull/2670)

Question is how could i call that? Is this something that could possibly be put on a schedule or is it per user?

Sorry not very experienced in this.

---

<div class="post-metadata">

### Author: ![mautematico](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mautematico/32/120926_2.png) [@mautematico](https://meta.discourse.org/u/mautematico)
#### Post date: [2017年五月30日 18:10 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/4 "2017-05-30T18:10:41Z")

</div>

Did you guys found a solution on this topic?

I have the same issue as OP. I am using Wordpress SSO plugin and I configured discourse to use SSO avatar, but it won’t follow up gravatar changes.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2017年五月30日 18:30 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/5 "2017-05-30T18:30:13Z")

</div>

> [@mautematico](#):
>
> it won’t follow up gravatar changes.

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.

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [2017年五月30日 21:55 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/6 "2017-05-30T21:55:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mautematico](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mautematico/32/120926_2.png) [@mautematico](https://meta.discourse.org/u/mautematico)
#### Post date: [2017年五月31日 20:00 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/7 "2017-05-31T20:00:01Z")

</div>

On the wordpress (sso provider) side, do you mean?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2017年五月31日 21:08 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/8 "2017-05-31T21:08:11Z")

</div>

> [@mautematico](#):
>
> On the wordpress (sso provider) side, do you mean?

Yes. I think this can be added as an option to the plugin. Possibly it should be the default behaviour.

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [2017年五月31日 21:11 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/9 "2017-05-31T21:11:13Z")

</div>

yes. i just edited the discourse-sso.php of the Discourse WordPress plugin and added it to the params array there.

---

<div class="post-metadata">

### Author: ![mautematico](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mautematico/32/120926_2.png) [@mautematico](https://meta.discourse.org/u/mautematico)
#### Post date: [2017年五月31日 21:21 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/10 "2017-05-31T21:21:09Z")

</div>

I am using pt-wp-discourse-sso, and also added it to the params array; howerever it won’t work

[https://github.com/mautematico/pt-wp-discourse-sso/commit/365877714e5768429cb85f6ab033b9505be31c7d](https://github.com/mautematico/pt-wp-discourse-sso/commit/365877714e5768429cb85f6ab033b9505be31c7d)

Do you guys have any clue about what am I missing?

Edit: Tried with string instead of boolean (‘true’ instead of true). Did not work either.

Using string ‘true’, I can see logs like this one:

```plaintext
Verbose SSO log: User was logged on <<user>>

nonce: <<nonce>>
name: <<name>>
username: <<username>>
email: <<user@example.org>>
avatar_url: https://www.gravatar.com/avatar/<<hash>>
avatar_force_update: true
require_activation: 
bio: 
external_id: 1
return_sso_url: 
admin: 
moderator: 
suppress_welcome_message: 
title: 
add_groups: 
remove_groups: 

```

Howerever, avatar is not refreshed.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2017年六月1日 00:13 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/11 "2017-06-01T00:13:35Z")

</div>

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

```plaintext
add_filter( 'wpdc_sso_params', 'my_namespace_force_avatar_update' );
function my_namespace_force_avatar_update( $sso_params ) {
    $sso_params['avatar_force_update'] = 'true';

    return $sso_params;
}

```

---

<div class="post-metadata">

### Author: ![sunnyt7](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sunnyt7/32/71920_2.png) [@sunnyt7](https://meta.discourse.org/u/sunnyt7)
#### Post date: [2017年六月2日 15:28 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/12 "2017-06-02T15:28:05Z")

</div>

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.

Thanks!

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2017年六月2日 23:01 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/13 "2017-06-02T23:01:46Z")

</div>

> [@sunnyt7](#):
>
> Does this work with custom Profile Builders at all? That have their own avatar upload feature built in?

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?

---

<div class="post-metadata">

### Author: ![sunnyt7](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sunnyt7/32/71920_2.png) [@sunnyt7](https://meta.discourse.org/u/sunnyt7)
#### Post date: [2017年六月2日 23:21 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/14 "2017-06-02T23:21:02Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2017年六月3日 20:32 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/15 "2017-06-03T20:32:37Z")

</div>

Which plugin are you using for setting the avatars on WordPress? If it’s free, I’ll try it out.

---

<div class="post-metadata">

### Author: ![sunnyt7](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sunnyt7/32/71920_2.png) [@sunnyt7](https://meta.discourse.org/u/sunnyt7)
#### Post date: [2017年六月3日 23:37 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/16 "2017-06-03T23:37:10Z")

</div>

It’s using [Best WordPress User Registration Plugin: Profile Builder Pro](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).

Would be happy to provide access if it helps.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2017年六月4日 02:58 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/17 "2017-06-04T02:58:08Z")

</div>

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’: [Avatar Upload Field](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.

```plaintext
add_filter( 'wpdc_sso_avatar_url', 'my_namespace_use_custom_avatar', 10, 2 );
function my_namespace_use_custom_avatar( $avatar_url, $user_id ) {
    if ( get_user_meta( $user_id, 'custom_field_57', true ) ) {
        $avatar_url = get_user_meta( $user_id, 'custom_field_57', true );
    }

    return $avatar_url;
}

```

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.

---

<div class="post-metadata">

### Author: ![sunnyt7](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sunnyt7/32/71920_2.png) [@sunnyt7](https://meta.discourse.org/u/sunnyt7)
#### Post date: [2017年六月4日 03:53 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/18 "2017-06-04T03:53:15Z")

</div>

> [@simon](#):
>
> There’s a filter in the wp-discourse plugin that you can use to change the avatar that’s sent to Discourse…

Thanks for helping out on this! Still no luck with the above code, so I dug into the database a bit to see what was coming up.

- The avatar user metadata is actually whatever you set it. In my case, it’s “custom\_field\_avatar”
- Tried swapping that in, but still nothing
- I looked in the db as to what was in that field. Instead of returning a URL, the meta\_value returns something like “348”
- 348 is the ID for the image attachment in wp\_posts
- in that field, the full image URL is displayed under “guid”

Any ideas on how to make that adjustment? Thanks again!

---

<div class="post-metadata">

### Author: ![sunnyt7](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sunnyt7/32/71920_2.png) [@sunnyt7](https://meta.discourse.org/u/sunnyt7)
#### Post date: [2017年六月4日 04:06 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/19 "2017-06-04T04:06:53Z")

</div>

Btw, I also looked at how Learnpress stored theirs in case it might help anyone in the future.

They have a custom field in wp\_usermeta called “\_ lp \_ profile\_picture” (without the spaces). That stores a value of something like “learn-press-profile/2/b89f8d0b9ee2dd95d8d4f4020f941cf8.jpg”, which is the portion of “[yoursite.com](http://www.yoursite.com/wp-content/uploads/learn-press-profile/2/b89f8d0b9ee2dd95d8d4f4020f941cf8.jpg)”.

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

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2017年六月4日 04:28 UTC](https://meta.discourse.org/t/sso-avatar-not-updating/25569/20 "2017-06-04T04:28:42Z")

</div>

You can get the upload URL from it’s ID with `wp_get_attachment_url( $attachment_id );`

This might work:

```plaintext
add_filter( 'wpdc_sso_avatar_url', 'my_namespace_use_custom_avatar', 10, 2 );
function my_namespace_use_custom_avatar( $avatar_url, $user_id ) {
    if ( get_user_meta( $user_id, 'my_avatar_custom_field', true ) ) {
        $avatar_id = get_user_meta( $user_id, 'my_avatar_custom_field', true );
        $avatar_url = wp_get_attachment_url( $avatar_id );
    }

    return $avatar_url;
}

```

[下一頁](https://meta.discourse.org/t/sso-avatar-not-updating/25569.md?page=2)
