There are a couple of ways that users can be added to and removed from groups. The easiest way to do it is to use the add_groups
and remove_groups
SSO parameters. That approach is outlined here: Bring over permission level from WordPress MemberPress - #2 by simon. The issue with this approach is that it requires users to log out and log back in again before their group memberships will get updated.
The other approach is to use the add_user_to_discourse_group
and remove_user_from_discourse_group
functions that are outlined in this topic: Manage group membership in Discourse with WP Discourse SSO. The benefi of that approach is that it’s not dependant on the user logging out - their membership levels will be changed as soon as the functions are called.