Hi-
I'm wondering if someone can provide some definitive information on how to properly add/remove secondary user groups to/from a user in an addon. So far, I've consulted these threads:
My understanding is that you should use the user group change service like this:
As pointed out in another thread, this methodology doesn't work if you don't know the change set key for when the group was added. I basically need to be able to arbitrarily add a group to a user and later remove it (without knowing anything about how/when it may have been added). If the group is added via ACP, I still need to be able to remove it. I would have done this by directly modifying secondary_group_ids but another thread said that's not advisable and won't always work...
Any suggestions would be much appreciated. Thanks
I'm wondering if someone can provide some definitive information on how to properly add/remove secondary user groups to/from a user in an addon. So far, I've consulted these threads:
XF 2.1 - Add secondary usergroup
I'm looking to add a secondary usergroup to a xenforo user from my site's code. I've figured out how to get user details and check if the user already has the usergroup $dir = "/path"; require($dir . '/src/XF.php'); XF::start($dir)...
xenforo.com
XF 2.1 - Remove secondary usergroup
I'm trying to remove a secondary usergroup. I used the following code to add it: /** @var \XF\Service\User\UserGroupChange $userGroupChange */ $userGroupChange = \XF::service('XF:User\UserGroupChange'); $userGroupChange->addUserGroupChange($user->user_id, '', []); However...
xenforo.com
XF 2.1 - UserGroupChange not working
Hello 🤚 UserGroupChange service doesn't work correctly. AddUserGroupChance: $userGroupChangeService = \XF::app()->service('XF:User\UserGroupChange'); $userGroupChangeService->addUserGroupChange($user->user_id, 'goldenThreadPromo', $promoGroupId); RemoveUserGroupChance: $userGroupChangeService...
xenforo.com
XF 2.1 - Removing a user from a group
I am working on an add-on that adds / removes users from secondary groups. Adding a user works fine, but I have some problems with removing them from a group. So for adding a user, I use this existing service: $userGroup=5; /** @var UserGroupChange $userGroupChange */ $userGroupChange =...
xenforo.com
My understanding is that you should use the user group change service like this:
PHP:
$userGroupChangeService = \XF::app()->service('XF:User\UserGroupChange');
// TO ADD
$userGroupChangeService->addUserGroupChange($user_id, 'some_key', $group_id);
// TO REMOVE
$userGroupChangeService->removeUserGroupChange($user_id, 'some_key');
As pointed out in another thread, this methodology doesn't work if you don't know the change set key for when the group was added. I basically need to be able to arbitrarily add a group to a user and later remove it (without knowing anything about how/when it may have been added). If the group is added via ACP, I still need to be able to remove it. I would have done this by directly modifying secondary_group_ids but another thread said that's not advisable and won't always work...
Any suggestions would be much appreciated. Thanks