MyBB Community Forums

Full Version: Plugin Display Data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do I display data created through a php function. If I add it to a global_start hook, then my plugin details are displayed at top of the forum but I want to choose the exact place where I want to display the plugin like insert into templates {$displaymypluginhere}. So how can I add lots of data into that global variable ?
Basically you would do something like this:

$plugins->add_hook('global_start','your_function_name_comes_here_with_no_parenthesis');

Then at your function you would have something like this:

function your_function_name_comes_here_with_no_parenthesis()
{
    global $db, $mybb, $templates, $templatelist, $lang;
    $templatelist .= ",your_template_name";
    // do your code here to add lots of stuff into the variable
    eval('$displaymypluginhere = "'.$templates->get('your_template_name').'";');
}

And just like any other template, if inside your template you have a variable called say, {$something['test']} you would have to have that inside your function or coming from the settings to fill it.

For example:

function your_function_name_comes_here_with_no_parenthesis()
{
    global $db, $mybb, $templates, $lang;
    // do your code here to add lots of stuff into the variable
    $something['test'] = 'This variable will print this, when the template loads';
    eval('$displaymypluginhere = "'.$templates->get('your_template_name').'";');
}

I am not an expert in mybb so, perhaps some one will point out any mistakes, but that is the gits of it pretty much.
You need to point out the precise hook in which you inject the function to. There isn't a rule for this as you need to crawl through the MyBB's core code; generally speaking, if you want to let your code be accessible in a particular template (let's say, member_profile) you would need to search for it in the code and search for a hook placed before that. Possibly, the hook should be outside any conditional statement that would restrict its usage to very few cases.

if ($this == true) {

   $plugins->run_hooks('my_awesome_hook'); // Good one!
   
   if ($somethingelse == false) {
      $plugins->run_hooks('another_hook_but_not_that_awesome'); // Dependent on $somethingelse's value, not very good
   }

   $templates->get('member_profile'); // Here's the target template

}

This is an utterly simplified scheme which should clarify the whole mechanism a bit. I would recommend using Crossreference to browse MyBB's latest core code.
^^ http://docs.mybb.com/1.8/development/plugins/hooks/ also has a list of hooks (as of 1.8.6, if I remember correctly, so it should be up to date) if that helps at all.