Back to Programming Articles

[vBulletin|PHP]vBulletin options and conditionals
by Ziki 24 Dec 2006

Want to bring your new product onto a new level and use vBulletin options as well?Here we go

To create a simple on/off option just enter the vBulletin option admincp.Now insert the values for your desired option,when you get to the type sellect boolean.I won't describe the other types here.Boolean returns values true/1 if the condition was correct and false/0 if it wasn't.

So the variable for a vb option is $vbulletin->options['OPTIONNAME'] in plugins and php code and for templates use $vboptions[OPTIONNAME] (notice,no apostrophes in templates).So to make a simple condition:

PHP Code:
if ($vbulletin->options['OPTIONNAME'])
{
echo 
"Correct";
}
else
{
echo 
"False";

If specifies the condition inside the brackets.If you use just the variable without the comparism sign (==) then it will think that you are checking if it is 1.

Oh I forgot,Yes = 1 and No = 0

Did you notice the else?That is executed if the condition is anything else than what we are checking with.But you can extend your code with another elseif

PHP Code:
if ($vbulletin->options['OPTIONNAME'] == '1')
{
echo 
"Correct";
}
elseif (
$vbulletin->options['OPTIONNAME'] == '0')
{
echo 
"False";
}
else
{
echo 
'This will never happen :)';

This was a very basic introduction into using PHP conditionals with vBulletin boolean (Yes/No) options .

vblts.ru supports vBulletin®, 2022-2024