Remove A User From All The Groups They Belong To

Hello, I am trying to write a plugin that will remove a user from all of the groups that they belong to.

Currently, I can get the plugin to remove a user from a specified group with the following code:

GroupManager groupManager = GroupManager.getInstance();

Group group = groupManager.getGroup(groupName);

group.getMembers().remove(userName);

/code

Is there any way to do something like above, but for all the groups a user is a member of?

Thanks.

Hi Caleb,

There’'s no “delete user from all groups” method but doing so can be done in just a few lines of code:

GroupManager groupManager = GroupManager.getInstance();

for (Group group : groupManager.getGroups()) {

group.getMembers().remove(userName);

}

/code

Hope that helps,

Ryan

Thanks for the quick response. That code will work work great for what I am trying to accomplish in my plugin.