2

Anyone had experience of assigning a user group when saving or registering a user via a plugin?

Tried various combinations of $user->group = 1, $user->group = [1], $user->setGroups([$group]) and $user->setGroups($group) (where $group is the group I want to assign the user to) but whilst the user is being saved fine the user group is not assigned.

Any thoughts appreciated!

Cheers,

Cole

Cole Henley
  • 1,741
  • 11
  • 20

1 Answers1

3

So it seems the only way to achieve this is to assign the user to the group, not the other way round (assign the group to the user).

So once my user has saved I can call following:

craft()->userGroups->assignUserToGroups($user->id, $groupId);

Cole Henley
  • 1,741
  • 11
  • 20