DiscourseConnect and user time zone / location

Hey @troygrady, sorry about the slow reply (I field questions on the WP Discourse plugin). I’ll address the timezone and location settings separately (they’re unconnected).

Timezone

Could you just clarify if you mean that you want user’s activity to display to them in their local time? If so, unlike in Wordpress, that’s currently the default in Discourse (without any use of DiscourseConnect), and will automatically update if not set by the user. For example, I recently went from the timezone Australia/Perth to Europe/Oslo. I haven’t touched the timezone setting in my profile here on meta, and it now reads

Do you want behaviour different from this?

Location

You can sync a location set in a Wordpress user profile with the location field in the user’s profile on Discourse. It doesn’t sync by default as there isn’t a standard field in Wordpress that’s equivalent to the location field in Discourse. You need to add some code in here. In your theme’s functions.php file or another spot you can add code, you need to add something like following, the key bit using the use of the wpdc_sso_params filter.

function sync_discourse_location( $params, $user ) {
    $location = get_user_meta( $user->ID, 'user_location_meta', true );
    if ( $location  ) {
        $params['location'] = $location;
    }
    return $params;
}
add_filter( 'wpdc_sso_params', 'sync_discourse_location', 10, 2 );

Note that you’ll need to substitute ‘user_location_meta’ with whatever user meta field is being used to store the user’s location on your Wordpress instance (i.e. whatever field is being used by the plugin you’re using to add user locations to Wordpress).

Also note that the Discourse location field is just a “string” field, which means that it will just display whatever is put into it literally. It has no affect on the user’s timezone and is not a geolocation (i.e. connected with mapping in any way).

1 Like