MyBB Community Forums

Full Version: If/else with usergroups
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm attempting to display a different message to the user according with his usergroups.
Right now I want the user to see the messages:

-"licensedBLS" if he's inside Super Moderators and Administrators groups at the same time
-"licensedGEN" if he's inside Super Moderators only
-"UNLICENSED" if he isn't inside any of them (Super Mods and Admins)

Can somebody check my code?
It always prints the text "licensedGEN" even if I'm inside both groups (Admin is primary and S.Mods secondary)


<?php 
$groups = $mybb->user['usergroup'];
if($mybb->user['additionalgroups'])
{
$groups.= "," . $mybb->user['additionalgroups'];
}
$explodedgroups = explode(",", $groups);
$canview  = 0;
$allowedgroups = array(3);
$allowedgroups2 = array(4);
foreach($explodedgroups as $group)
if(in_array($group, $allowedgroups, $allowedgroups2)) 
{
$canview  = 1;
echo 'licensedBLS';
} else {
if(in_array($group, $allowedgroups)) 
{
$canview  = 1;
echo 'licensedGEN';
}
}
if(!$canview)
{
echo'UNLICENSED';
}
?>
Moved to Plugin Support.
Use the is_member() function:
<?php 
if(is_member('3') && is_member('4'))
{
	echo 'licensedBLS';
}
if(is_member('3'))
{
	echo 'licensedGEN';
}
if(!is_member('3,4'))
{
	echo 'UNLICENSED';
}
?>
(2015-10-31, 07:47 PM)SvePu Wrote: [ -> ]Use the is_member() function:
<?php 
if(is_member('3') && is_member('4'))
{
	echo 'licensedBLS';
}
if(is_member('3'))
{
	echo 'licensedGEN';
}
if (!is_member('3,4'))
{
	echo 'UNLICENSED';
}
?>

It keeps printing both Sad
OK, sorry .... pls try this:
<?php 
if(is_member('3') && is_member('4'))
{
	echo 'licensedBLS';
}
if(is_member('3') && !is_member('4'))
{
	echo 'licensedGEN';
}
if(!is_member('3,4'))
{
	echo 'UNLICENSED';
}
?>
(2015-10-31, 07:55 PM)SvePu Wrote: [ -> ]OK, sorry .... pls try this:
<?php 
if(is_member('3') && is_member('4'))
{
	echo 'licensedBLS';
}
if(is_member('3') && !is_member('4'))
{
	echo 'licensedGEN';
}
if(!is_member('3,4'))
{
	echo 'UNLICENSED';
}
?>

Now it works!!!
Thank you!