1. 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?

Discussion in 'XenForo Development Discussions' started by AUSFIFA, Mar 30, 2016.


    AUSFIFA Member

    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!
  2. Snog

    Snog Well-Known Member

    XenForo_Model_User -> addUserGroupChange or use the user datawriter.
    alexD likes this.

    AUSFIFA Member

    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?
  4. Snog

    Snog Well-Known Member

    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.
    LPH likes this.

Share This Page