MyBB Community Forums

Full Version: IF Condition for Version
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I want to create an IF condition in a PlugIn which uses the current MyBB version as a basis for different hint texts.

Example (which does not work)
if (mybb->version > 1820) {
echo "$lang->text1";
} else {
echo "$lang->text2";
}

Can anyone tell me what the IF condition must be exactly?

Thanks in advance for any tips and hints.
Have you taken $mybb to global scope?

Also, you are missing the dollar ($) sign of object name:
if ($mybb->version > 1820)

Also, the represented version contains dot ( . ) in between, for example : 1.8.20, you may like to trim out the dots:
$version = preg_replace('/[^0-9]+/', '', $mybb->version);
echo (int)$version > 1820 ? $lang->text1 : $lang->text2;
First of all, thank you very much for your commitment to help me.

The "$" I have unfortunately missed to write here and is of course available.

Your default with the "echo" works perfectly for pure text output.  Thanks for that.

Sorry for not being clear enough, I thought with "$lang->text" I can already execute the function. Therefore now a little bit clearer:
if ($mybb->version < 1824) {
// execute a function
echo "$lang->text1";
} else {
// execute a function
echo "$lang->text2";
}
How do I get a) the IF condition in function so that b) the different functions are executed?
Like effone said, $mybb->version contains dots.
You either have to trim the dots or you can instead use $mybb->version_code:

 
if ($mybb->version_code < 1824) {
    ...
Thank to all, it works perfect.