Could you update user avatar for wordpress plugin sso?

Hey @cmdntd :slight_smile:

It sounds like you have Discourse setup as the DiscourseConnect provider for Wordpress via the WP Discourse plugin? Is that right?

Wordpress doesn’t actually have custom user avatars out of the box. You need to use a Wordpress avatar plugin. This is partly why the WP Discourse plugin doesn’t just have a setting to sync Discourse avatars when Discourse is the DiscourseConnect provider, as the way custom avatars are handled will depend on the way a Wordpress implements that kind of custom feature.

However, the WP Discourse plugin gives you a filter you can use to access the Discourse avatar url: wpdc_sso_client_updated_user. This filter will be applied every time the user logs in to Wordpress using DiscourseConnect.

add_filter( 'wpdc_sso_client_updated_user', 'my_wpdc_sso_client_updated_user', 10, 2 );
function my_wpdc_sso_client_updated_user( $updated_user, $query ) {
	## use $query['avatar_url']
}

So, if you use a Wordpress avatar plugin to allow users to set custom avatars in Worpress and this filter you can set Wordpress user’s avatars as their Discourse avatar when Discourse is the DiscourseConnect Provider.

2 Likes