PrimeTimeCode / pt-wp-discourse-sso

PT WordPress + Discourse Single Sign On
GNU General Public License v2.0
17 stars 5 forks source link

Is it possible to add group option to SSO? #5

Open becahp opened 4 years ago

becahp commented 4 years ago

Hi!

I'm using this plugin as of now (May 2020) to integrate my WP website to my Discourse forum. I had some performance issues with the popular WP Discourse plugin and the PrimeTime one has proved to be a solid choice so far.

Now, as my WP website is evolving, I wish I could assign a Discourse group based on my WP user role when the user logs with the SSO. Something like what's discussed here:

https://meta.discourse.org/t/managing-discourse-group-membership-with-wp-discourse-sso/74724

I'm searching for a solution to work on my functions.php , but it would be much more elegant at the plugin itself.

Thanks!

etcook commented 4 years ago

@becahp hey there - I’m glad this is working well for you.

I haven’t used the other plugin in years. Is the group(s) set within the Plugin’s settings?

becahp commented 4 years ago

Thanks for your reply!

Unfortunately, I'm not sure.

becahp commented 4 years ago

Hi! I found the implementation to add the user to a discourse group on the other plugin:

public static function add_user_to_discourse_group( $user_id, $group_names ) {
    $options = self::get_options();
    if ( empty( $options['enable-sso'] ) ) {
        return new \WP_Error( 'wpdc_sso_error', 'The add_user_to_discourse_group function can only be used when SSO is enabled.' );
    }
    $user       = get_user_by( 'id', $user_id );
    $sso_params = self::get_sso_params(
        $user,
        array(
            'add_groups' => $group_names,
        )
    );
    return self::sync_sso_record( $sso_params );
}

It's in this file: utilities.php

There's also a function to remove the user from a discourse group.

etcook commented 4 years ago

I did see that, which is why I was asking where the group_names configuration variable comes from. I was planning on installing it sometime next week to drill down a bit and see if would be a straightforward implementation.

If you haven't heard from me in a week or two, ping me to remind me. We'll get it done.