User avatar preference spontaneously changing to "Custom picture"

Yes, the problem I’m seeing is when a user has an existing account on both Discourse and WordPress, but the accounts have not yet been synced. In that case, when the user first logs in with SSO, if the avatar_url is present in the SSO parameters, the job download_avatar_from_url is enqueued. This checks for the user’s uploaded_avatar_id. If that isn’t present, then the avatar_url from the SSO parameters is used. This happens whether or not the SiteSetting sso_overrides_avatar has been set.

We can get around this in the wp-discourse plugin by adding a ‘SSO overrides avatar’ setting. If it is not set, then the WordPress avatar_url won’t be sent with the SSO parameters. If it is set, the avatar_url will be sent with the SSO parameters, and also force_avatar_update can be added to the parameters and set to true. Doing that will make it possible for avatars to be updated on Discourse when the Gravatar image is changed through WordPress.

What I can’t figure out is a good way to check on WordPress if the default avatar (usually the mystery person) is being used. I think in most cases, people would rather keep the default Discourse avatar instead of having it overridden with this: