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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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