How to link wordpress avatars with discourse?


(Ryan Collins) #1

Hi folks,

I have a wordpress site connected to my discourse forum via SSO.

The users on my wordpress site upload avatars using the Profile Builder Pro plugin, and these avatars appear throughout my website. However these avatars do not appear on my discourse forum, even though I have checkmarked the “sso overrides avatar” option.

I think the issue might have something to do with the " external system avatars url" but I am not sure. Right now that url reads /letter_avatar_proxy/v2/letter/{first_letter}/{color}/{size}.png

Do I need to replace that url with a url for my wordpress avatar database? If yes, any idea what that might look like or where I can find that url?

Thanks so much for any insight and advice.

Best,

Ryan


(Simon Cossar) #2

It can be done. You might find the information you need in this post and the posts below it: SSO Avatar Not Updating.


(Ryan Collins) #3

Ok great, I will give that a try.

Thanks Simon.


(Ryan Collins) #4

@Simon_Cossar thanks again for the help.

Where should I put this filter in my discourse forum? Is there a specific place within my discourse admin settings where I should copy/paste this code?

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_1', true ) ) {
        $avatar_url = get_user_meta( $user_id, 'custom_field_1', true );
    }

    return $avatar_url;
}

(Simon Cossar) #5

That code needs to be added to your WordPress code, not to Discourse. The easiest place to add it is to your theme’s functions.php file. There is some risk in editing your functions.php file on a live site. Before you do it you should be sure that you can access you have some way of accessing your theme’s files in case you make a mistake.


(Ryan Collins) #6

Ok, sounds good.

I will test it out on a copy of my live site first.

Much appreciated!