# Accessing Discourse user avatar in WP functions.php

**URL:** https://meta.discourse.org/t/accessing-discourse-user-avatar-in-wp-functions-php/95390
**Category:** WordPress
**Created:** [22.Август.2018 09:47:58 UTC](https://meta.discourse.org/t/accessing-discourse-user-avatar-in-wp-functions-php/95390 "2018-08-22T09:47:58Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [08.Сентябрь.2018 01:27:42 UTC](https://meta.discourse.org/t/accessing-discourse-user-avatar-in-wp-functions-php/95390/5 "2018-09-08T01:27:42Z")

</div>

In the latest version of the plugin (1.7.5), I’ve added a `wpdc_after_sync_sso` action hook that you can use to retrieve information from the Discourse user object. This hook will only work if you are using your WordPress site as the SSO Provider for Discourse, and have also enabled the `Create or Sync Discourse Users on Login` option. Next week I will look into adding a similar hook for when WordPress is functioning as the SSO Client.

Any function that you hook into `wpdc_after_sync_sso` will be passed up to two parameters: the Discourse user object, and the WordPress user’s ID.

You can use the hook to save the user’s Discourse avatar URL by adding something like this to a plugin, or to your theme’s `functions.php` file:

```php
add_action( 'wpdc_after_sync_sso', 'wpdc_custom_action_after_sync_sso', 10, 2 );
function wpdc_custom_action_after_sync_sso( $discourse_user, $user_id ) {
    // You could just substitute your Discourse URL here, instead of getting it from the options array.
    $discourse_url = \WPDiscourse\Utilities\Utilities::get_options()['url'];
    $avatar_template = str_replace( '{size}', '60', $discourse_user->avatar_template );
    $avatar_url = esc_url_raw( "{$discourse_url}{$avatar_template}" );
    update_user_meta( $user_id, 'discourse_avatar_template', $avatar_url );
}

```

---

_[View the full topic](https://meta.discourse.org/t/accessing-discourse-user-avatar-in-wp-functions-php/95390)._
