MyBB Community Forums
IF Condition for Version - Printable Version

+- MyBB Community Forums (
+-- Forum: Extensions (
+--- Forum: Plugins (
+---- Forum: Plugin Support (
+---- Thread: IF Condition for Version (/thread-230137.html)

IF Condition for Version - Fontane - 2020-11-11


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.

RE: IF Condition for Version - effone - 2020-11-11

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;

RE: IF Condition for Version - Fontane - 2020-11-11

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?

RE: IF Condition for Version - doylecc - 2020-11-11

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) {

RE: IF Condition for Version - Fontane - 2020-11-11

Thank to all, it works perfect.