• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Add user to secondary user group function?

#1
I want to be able to programmatically add a user to a secondary group through a PHP script once they've upgraded to premium on my website.

I'm looking in Xenforo/Model/UserGroup.php for a function to add a secondary group to a user, but I can't seem to find one.

I can find changePrimaryUserGroupForUsers() and removeSecondaryGroupFromUsers() but there doesn't seem to be a function to add secondary groups.

Any help would be appreciated. Thanks!
 
#3
XenForo_Model_User -> addUserGroupChange or use the user datawriter.
Does the key variable have to be anything specific? Or can I just make up my own? For example if I want to add the "Premium" group to a user, I just use "premium" as the key?
 

Snog

Well-known member
#4
The key can be anything you like. But be sure it's unique because the key is what is used to remove the user group change when it's passed without $addgroups. If you use something that's too common, your changes could be removed by something else.