SSO Avatar Not Updating

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’: 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.

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.

1 Like