Solved: 8 Months, 2 Weeks, 4 Days ago IF Condition for Version
#1
Solved: 8 Months, 2 Weeks, 4 Days ago
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.
Reply
#2
Solved: 8 Months, 2 Weeks, 4 Days ago
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;
Reply
#3
Solved: 8 Months, 2 Weeks, 4 Days ago
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?
Reply
#4
Solved: 8 Months, 2 Weeks, 4 Days ago
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) {
    ...
Reply
#5
Solved: 8 Months, 2 Weeks, 4 Days ago
Thank to all, it works perfect.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)