# ユーザーがグループステータスを失っていますか？

**URL:** <https://meta.discourse.org/t/users-losing-group-status/96790>\
**Category:** WordPress\
**Created:** [2018 年 9 月 9 日午後 2:09 UTC](https://meta.discourse.org/t/users-losing-group-status/96790 "2018-09-09T14:09:59Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2018 年 9 月 14 日午前 3:51 UTC](https://meta.discourse.org/t/users-losing-group-status/96790/15 "2018-09-14T03:51:09Z")

</div>

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.

```php
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;
}

```

---

_[View the full topic](https://meta.discourse.org/t/users-losing-group-status/96790)._
