Bring over permission level from WordPress MemberPress

There are a couple of ways to do it. The easiest way is to add the Discourse group names to the SSO payload. You can do this by hooking into the wpdc_sso_params filter. Setting it up this way will add and remove users from groups when they login to Discourse. You’ll need to figure out the condition to check the user against to know which groups to add or remove them from. Memberpress fires an action when a membership level is added or removed. You could hook into that action and add some user metadata to a user when they are added or removed from a group. You could then test for that with the function below.

add_filter( 'wpdc_sso_params', 'wpdc_custom_sso_params', 10, 2 );
function wpdc_custom_sso_params( $params, $user ) {
    if ( $user /* some condition based on the user to add groups */ ) {
        $params['add_groups'] = 'comma,separated,group,names'; // Don't use spaces between names.
    }

	if ( $user /* some condition based on the user to remove groups */ ) {
		$params['remove_groups'] = 'comma,separated,group,names'; // Don't use spaces between names.
	}

    return $params;
}

The other approach is to use the wp-discourse add_user_to_discourse_group and remove_user_from_discourse_group functions. This way users can be added and removed from Discourse groups without them first having to login to Discourse. There is some information about using the functions here: Managing Discourse group membership with WP Discourse.

I’m working for Discourse now, so I can’t take on any contract work. Setting this up is fairly straightforward. If you find someone to do the work, and they get stuck, have them post on here and we can sort it out.

7 Likes