4

Ok this should be pretty simple I feel! But I can't find the documentation for it.

I can set assign a user to a user group within a plugin with:

craft()->userGroups->assignUserToGroups($userid, $groupid);

How do I do the reverse and remove a user from a user group?

Cheers.

4

assignUserToGroups has $groupIds parameter (int / array) preset to null. From the docs:

assignUserToGroups($userId, $groupIds = null)

So calling the function without that parameter set should do it:

craft()->userGroups->assignUserToGroups(1);
3
  • Ok thanks that does the job. Do you know if there is a way to remove the user from a specific group? Just forward thinking here. Cheers – Lettie May 18 '15 at 11:30
  • 1
    Get all group IDs the user is assigned to and remove one group ID from that array, before passing it to assignUserToGroups. – carlcs May 18 '15 at 11:32
  • That'll work cheers – Lettie May 18 '15 at 11:35

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.