MyBB Community Forums

Full Version: Not validating both groups despite correct syntax.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
In the plugin which I'm writing, there is a situation where am using:

if($groups != '' && $cond2 != '')
{
if(!in_array($mybb->user['additionalgroups'], $groups) || !in_array($mybb->user['usergroup'], $groups) && $var >= $var2)
{
error("Error");
}

}

But the problem is that it's not checking for additional groups. I've also tried using array_map/trim function to eliminate the possibilities of while space being left like:

$groups = array_map('trim', $group);

Still no luck. Have never encountered anything like this so far, unsure what's causing the issue.

Any idea?
I do believe $mybb->user['additionalgroups'] is a string of IDs separated by commas. Therefor you'll need to explode() it to use it as an array.
That's true, sure thing. But for testing purpose, I've only set 1 additional group, so no comma separated values involved, though, I'll give this a try. Thank you.
Any chance you could explain what EXACTLY you're trying to do? Variables like $var1 and $var2 really don't help. Maybe post the code in context of the rest of the script?
The plugin which I'm writing is private hence I'm just renaming variables to $var for example. However, they are just integer value (not multiple values, hence they aren't comma separated value). For example it checks a value for a column and matches it against the setting value as specified to check if it's greater than or equal to that setting value.

Btw, I tried making additional groups array as well, but no luck still.
What exact logic are you trying to perform in the level 2 if statement? Have you tried bracketing it up?

if ((!in_array($mybb->user['additionalgroups'], $groups) OR !in_array($mybb->user['usergroup'], $groups)) AND $var >= $var2) {

I always find separating my logic into brackets helps me understand what exactly is going on
Also, why not use empty() instead:

if (!empty($groups) AND !empty($cond2)) {
    if ((!in_array($mybb->user['additionalgroups'], $groups) OR !in_array($mybb->user['usergroup'], $groups)) AND $var >= $var2) {
        error("Error");
    }
} 

Much cleaner IMO.
I'm having so much settings (that $cond2 != '' is not actually a check for query but settings) so that I'm checking for a lot of aettings to make sure to output the correct error in proper order.

The logic is correct actually, I tried the way you mentioned well before, no luck still.
Have you ensured the first condition is correct then? Just chuck a die() in there and see if it's evaluated.
First condition as in you're talking about $groups from this line?:

if($groups != '' && $cond2 != '')

or the additional groups one from the second if?
Pages: 1 2