MyBB Community Forums

Full Version: PHP Conditionals
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im trying to do this in my templates while using the PHP plugin.

This Code Doesnt Work With The Variable
<if (strpos($GLOBALS['mybb']->user['additionalgroups'], "4") == true) then></if>

This Code Works Without The Variable
<if (strpos("5,7,1,4", "4") == true) then></if>

In the end im trying to get something that hides if a gid is found in a users additional groups, which is why im not using the simple "<if $GLOBALS['mybb']->user['usergroup'] == 1 then>".
If you dont know why this wont work, its because 9/10 times the additional groups will not contain a single number and will contain 5,7,3,6 for example.

Any ideas?
Thanks
You need to explode each additional group and then run a loop through the array and find if the group is in there. I don't know exactly how you'd type this in a template but the idea is the same and this would work in a normal PHP plugin file:
$groups = explode(",", $mybb->user['additionalgroups']);
if(in_array("4", $groups))
{
    //TRUE -> run your code if they have additionalgroup of 4
}

Hope that helps!
Thanks, i guess that would work but I got this answer from ZingaBurga
<if strpos(','.$GLOBALS['mybb']->user['additionalgroups'].',', ',4,') !== false then>
Which works, thanks