# Memberpress: how to add users to groups upon Sign up

**URL:** <https://meta.discourse.org/t/memberpress-how-to-add-users-to-groups-upon-sign-up/83478>\
**Category:** WordPress\
**Created:** [March 21, 2018, 1:48pm UTC](https://meta.discourse.org/t/memberpress-how-to-add-users-to-groups-upon-sign-up/83478 "2018-03-21T13:48:54Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [April 3, 2018, 3:49pm UTC](https://meta.discourse.org/t/memberpress-how-to-add-users-to-groups-upon-sign-up/83478/8 "2018-04-03T15:49:29Z")

</div>

I formatted your code so that it’s easier to see what’s going on.

`$params['remove_groups]` keeps getting redefined. As an example, if a user had been initially added to the ‘ForeverFree’ group on WordPress, and had then been removed from it, when the function is called for that user `$params['remove_groups']` will first get set to ‘ForeverFree’, but in the next `if` statement it will get set to ‘CreativeLicense’… By the end of the function `$params['remove_groups']` will probably have been set to ‘TransformPlus’.

There are a few ways you could approach this. We can’t get too into helping with PHP code on this forum, but you could try creating a `$remove_groups` variable that is an array:

```plaintext
$remove_groups = array();

```

and then in each `if` statment, add the group name to `$remove_groups` array:

```plaintext
	if ( current_user_can( 'mepr-active','memberships:47281' ) ) {
		$params['add_groups'] = 'ForeverFree';
	} else {
		$remove_groups[] = 'ForeverFree'; // Adds the groupname to the array.
	}

	if ( current_user_can( 'mepr-active','memberships:47295,47297' ) ) {
		$params['add_groups'] = 'CreativeLicense';
	} else {
		$remove_groups[] = 'CreativeLicense';
	}

    // ...

```

At the end of the function, join the `$remove_groups` array with a comma and assign it to `$params['remove_groups']`

```plaintext
$params['remove_groups'] = join( ',', $remove_groups ); // Converts the array into a comma separated string.

```

If it’s possible for users to be _added_ to more than one group at a time, you might need to take a similar approach with `$params['add_groups']`.

If you’re testing this with an admin user, I think that `current_user_can( 'mepr-active', ... )` will always return `true` for an admin user. It’s something to watch out for.

---

_[View the full topic](https://meta.discourse.org/t/memberpress-how-to-add-users-to-groups-upon-sign-up/83478)._
