MyBB Community Forums

Full Version: preferred method for passing variables between hooks in the plugin?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My plugin uses the showthread_start and postbit hooks.

When the former is called, it queries the database and assembles a multidimensional array.

Each time the latter is called, that multidimensional array is compared to the current postbit's author and some HTML is displayed (or not).

As such, the data collected at thread start needs to be available when each postbit is written. Currently I am just dumping it into $_SESSION['somekey'] and pulling it back out again for examination in each postbit, but I figured there was probably a "right myBB way" of doing this.

Is there?
Instead of running a query, you can simple check both the persons (post author and end user) like this;
if ($post['username'] == $mybb->user['username'])
{
   // do somthing
}
use globals.

function for_showthread_hook()
{
    global $myvariable;

    //do stuff to fill $myvariable
}

function for_postbit_hook()
{
    global $myvariable;

    //do stuff with $myvariable

}