View Full Version : What Conditional do I need to specify *Secondary* User Groups?
Ocean
08-30-2004, 01:50 PM
If I want a section of code in a PHP file to apply to Administrators (Group ID 6) only, I might use the following conditional:
if ($bbuserinfo[usergroupid]==6)
{
}
However, that conditional only works if the Primary User Group for a user is Group ID 6.
How does this conditional need to be modified so that it also works if a user's Secondary User Group is Group ID 6?
Thanks!
$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups))
{
}
or, if you want to combine...
$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups) OR $bbuserinfo['usergroupid'] == 6)
{
}
Zachery
08-30-2004, 02:14 PM
$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups))
{
}
or, if you want to combine...
$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups) OR $bbuserinfo['usergroupid'] == 6)
{
}
OIr if your connected to vBulletin just use is_member_of
Ocean
08-30-2004, 02:31 PM
OIr if your connected to vBulletin just use is_member_of
Hi, Zachery! Out of curiosity, what do you mean by "if your connected to vBulletin"? Do you mean if I'm talking about the vB PHP files as opposed to generic PHP coding in general?
If so, than I can tell you that I am talking about the vB PHP files. And in that case, could you give me an example of the proper syntax to use with "is_member_of"?
Thanks!
Ocean
08-30-2004, 02:32 PM
$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups))
{
}
or, if you want to combine...
$groups = fetch_membergroupids_array($bbuserinfo);
if(in_array(6, $groups) OR $bbuserinfo['usergroupid'] == 6)
{
}
Hi, Rake! Thanks for replying! Out of curiosity, is there any reason to combine the two conditionals the way you did on your second example? Wouldn't the first one catch both Primary as well as Secondary groups?
Hey Ocean.
Yes, you're right in fact. I was under the impression that the function only gets the secondary group ids, but it also fetches the primary group, by default function fetch_membergroupids_array($user, $getprimary = true)
For the is_member_of function:
function is_member_of($userinfo, $usergroupid)
Zachery
08-30-2004, 02:53 PM
Hi, Rake! Thanks for replying! Out of curiosity, is there any reason to combine the two conditionals the way you did on your second example? Wouldn't the first one catch both Primary as well as Secondary groups?
IF you included vBulletins global.php you can use its functions
so is_member_of($var, x) will work :)
Ocean
08-30-2004, 03:25 PM
IF you included vBulletins global.php you can use its functions
so is_member_of($var, x) will work :)
This would be for code added to ShowThread.php and Misc.php - so I am assuming that there wouldn't be a problem, yes?
And that being the case, is this the proper syntax?
if (is_member_of($bbuserinfo, 6)
{
}
Or am I formatting it wrong?
should be:
if (is_member_of($bbuserinfo, 6))
{
}
Ocean
08-30-2004, 03:33 PM
should be:
if (is_member_of($bbuserinfo, 6))
{
}
I got caught by the trailing parenthesis! Thanks, rake and Zachery. I appreciate all of your help! :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.