XF 2.3 Removing a user from a user group

Take a look at the XF\Service\User\UserGroupChangeService ... this core service allows you to define a usergroup change that applies to a user or group of users - and then removing users from that usergroup is as simple as removing the usergroup change - either for an individual user, or for a group of users, all at once. The service takes care of all the behind the scenes usergroup changes required.

This is what is used when you make someone an admin or a moderator and put them in extra user groups in the process - they get a usergroup change - you can see them all defined in the xf_user_group_change table.

Of course, this doesn't work with manual usergroup changes that are made by editing a user's profile directly - it assumes that usergroups have been assigned to a user programmatically - so you can then remove them programmatically as well.

If you instead need to directly remove a user from a group without using the UserGroupChangeService - you can dig into the service and find out how they do it.
 
Back
Top Bottom