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!



1 Answer 1


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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.