Users losing group status?

There are a couple of errors in the code. $user_sub = 1 will always return true. It needs to be == or ===.

Here’s the logic I think you want:

The Accessors group is for subscribers who have a membership level of ‘1’ or for spectators who have a membership level of ‘2’.

The Providers group is for subscribers who have a membership level of ‘2’.

The Members group is for any user who has a membership level of ‘3’, ‘4’, or ‘6’.

See if this code works. If users are still being removed from groups, you’ll need to look at the logic in the function and make sure it’s correct. Users will be removed from a group if they don’t meet the condition in the if statement.

add_filter( 'wpdc_sso_params', 'wpdc_custom_sso_params', 10, 2 );
function wpdc_custom_sso_params( $params, $user ) {
	$add_groups = array();
	$remove_groups = array();
	$user_sub = in_array( 'subscriber', $user->roles );
	$user_spec = in_array( 'spectator', $user->roles );

	if (  ( pmpro_hasMembershipLevel( '1',  $user->ID ) && $user_sub ) || ( pmpro_hasMembershipLevel( '2', $user->ID ) && $user_spec ) ) {
		$add_groups[] = 'Assessors';
	} else {
		$remove_groups[] = 'Assessors';
	}

	if ( pmpro_hasMembershipLevel( '2',  $user->ID ) && $user_sub ) {
		$add_groups[] = 'Providers';
	} else {
		$remove_groups[] = 'Providers';
	}

	if ( pmpro_hasMembershipLevel( '3',  $user->ID ) ||  pmpro_hasMembershipLevel( '4',  $user->ID ) ||  pmpro_hasMembershipLevel( '6', $user->ID ) ) {
		$add_groups[] = 'Members';
	} else {
		$remove_groups[] = 'Members';
	}

	$params['add_groups'] = join( ',', $add_groups );
	$params['remove_groups'] = join( ',', $remove_groups );

	return $params;
}