Log in

View Full Version : $ismod function - I want something similar?


N9ne
02-10-2003, 08:22 PM
I have 5 separate usergroups for banned users, now what I want to do is instead of having to write out long if statements, just say $isbanned...how can I do this? I looked in functions.php but didn't find much to help me.

Xenon
02-11-2003, 11:10 AM
create a function in functions.php
function isbanned($userid=-1) {
if ($userid==-1) {
$usergroupid=$bbuserinfo[usergroupid];
} else {
$user=$DB_site->query_first("SELECT usergroupid FROM user where userid=$userid");
$usergroupid=$user[usergroupid];
}
return in_array($usergroupid, array(8,9,12,13));
}

replace the 8,9,12,13 with the usergroupids of your banned usergrous..

Dean C
02-11-2003, 03:21 PM
Geez your too clever with that in_array function xenon ;)

- miSt

N9ne
02-11-2003, 03:29 PM
And that will make $isbanned work globally right? It's just that I don't see any 'global' in there :p

Xenon
02-11-2003, 04:03 PM
it's a function, so it would always work globaly.

it's like ismoderator.

so your $ in front is incorrect!

also, please change your sig to fit with the rules!

N9ne
02-11-2003, 04:30 PM
So if it's a function, I can't use it as a variable? I'd have to use isbanned() wouldn't I? Is there a way I could use it like you can use $ismod...I want to use $isbanned instead.





edited my sig, completely forgot about the rules :o.

Xenon
02-11-2003, 04:39 PM
thx

i don't see why you want to use it as a variable, it has no sense normally...
if use use a var or the function it's equal..

but you can do this:
$isbanned=isbanned();

that's the way it's done with $ismod, it's just because of a caching feature...

N9ne
02-11-2003, 05:13 PM
In an if statement, which of the following can I do then?


if ($isbanned=isbanned();) {
echo("blah");
}

if($isbanned) {
echo("blah");
}

if(isbanned()) {
echo("blah");
}

N9ne
02-11-2003, 05:14 PM
Grr, it keeps parsing a smilie, the first one eshould be:

if ($isbanned=isbanned()__)__{
echo("Blah");
}

Just remove the underscores.

Xenon
02-11-2003, 05:21 PM
use this:
if(isbanned()) {
echo("blah");
}

N9ne
02-11-2003, 05:22 PM
ok, i'll give it a try :). Thanks for all the help!