I’m testing implementing SSO with WP as my provider but it automatically changes users avatars to the default avatar on my site (basically the site logo), is it possible to not bring the avatar across and just use the Discourse letters if the user has the default?
AI-generated summary
Don’t update avatar if default
dylanb is testing Single Sign-On (SSO) with WordPress as the provider but found that Discourse changes users’ avatars to the site logo (default avatar). simon clarified that this issue might be caused by a plugin and suggested using the default WordPress Gravatar avatars, which should pass a d=404 parameter to display a letter avatar in Discourse.
dylanb revealed that he is using the WP User Avatar plugin, which sets a default avatar, likely causing the issue. simon provided a solution using the 'wpdc_sso_avatar_url' filter in the WP Discourse plugin. By adding code to the theme’s functions.php file, it’s possible to return an empty string for users with the default avatar, preventing the default avatar from being sent to Discourse.
dylanb successfully implemented the solution and reported that it worked perfectly.
Are you using a plugin for avatars, or are you using the default WordPress Gravatar avatars? When the default WordPress Gravatars are being used, the expected behaviour is that an avatar URL with the parameter d=404 will be passed from WordPress to Discourse during SSO login. The d=404 parameter will cause Discourse to display a letter avatar for users who have not set a Gravatar.
This is working correctly when I test it. If it’s not working correctly for you, any details about your avatar setup would be helpful.
Yep, I am using WP User Avatar which sets a default avatar. I assume that is what is causing the issue and I’d have to add something custom to ignore it?
That will be the problem. The WP Discourse plugin has a 'wpdc_sso_avatar_url' filter that can be used to filter the avatar URL that is passed to Discourse. The filter is passed two parameters: $avatar_url, and $user_id.
To avoid sending the default avatar to Discourse, you’d need to add some code to your theme’s functions.php file that hooks into the filter and returns an empty string for users who have the default avatar:
add_filter( 'wpdc_sso_avatar_url', 'wpdc_custom_sso_avatar_url', 10, 2 );
function wpdc_custom_sso_avatar_url( $avatar_url, $user_id ) {
if ( /* some condition that returns true for users with the default avatar */ ) {
return '';
}
return $avatar_url;
}
That worked perfectly, thanks.