MyBB Community Forums

Full Version: Usergroup Check.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been trying to setup a usergroup check to determine which upgrades you can purchase. I want it so that if you are in certain groups, you can't upgrade to anything below it. I have most of the page down, but its not reading me being in any groups. I tried adding myself to the elite group and the check does not take effect. The upgrade page is on a template on mybb, but the file is a custom php file in the root of the site directory. Read below.


Well, I happened to finally achieve this after a few hours of work and research, I put two and two together.
Here is how I did it for anyone who might be in the same situation as me.

For whatever template you are trying to add the group check to, put this line of code towards the top(I put mine under the headerinclude code)

function IsCurrentUserInGroup ($groups="") {
    global $mybb;
    
    if ( in_array($mybb->user['usergroup'],explode(",",$groups)) || array_intersect(explode(",",$mybb->user['additionalgroups']),explode(",",$groups))) {
        return true;
    }
    return false;    
}

Once you have entered that code, for wherever you want to add your group check, enter the following:
if ( IsCurrentUserInGroup("GROUPID,GROUPID,GROUPID") )
{
YOUR CODE HERE IF GROUP CHECK IS A SUCCESS
}
else {
YOUR CODE HERE IF GROUP CHECK IS A FAIL
}

Where it says groupid, simply put the id of the group you want to check for.
There's no certain amount of groups you can list, so don't worry.
You can also put your custom code where it says "YOUR CODE HERE" for each.
I hope this has helped someone out. Good Luck!!  Big Grin
Mybb 1.8 has an included function for that => is_member()
(2015-11-07, 10:33 AM)SvePu Wrote: [ -> ]Mybb 1.8 has an included function for that => is_member()

Welp had no clue of that existing.
Might be good for future reference.
No point in changing it now Toungue
Thanks for the response!