MyBB Community Forums

Full Version: Hooks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I don't fully understand the whole Hooks System. I tried looking through plugins to see if that helps, but I get confused when an admin page calls a hook that wasn't created in the 'functionname_activate()' function.

Like, for example, the Inventory Shop plugin. It calls the hook 'inventory_shop_admin_modify', but, in the inventoryshop.php file, it doesn't add that.

Plus, I'm not sure what, in essence, this does:

$plugins->add_hook("global_end", "foo_functionname");

Does that add the function 'foo_functionname' to the hook 'global_end'? If it does, what would happen if you called the hook 'global_end'? Would, along with all the other code it executes, execute the functions 'foo_functionname'?

I'm really confused. Any help would be greatly appreciated!
Quote:Does that add the function 'foo_functionname' to the hook 'global_end'? If it does, what would happen if you called the hook 'global_end'? Would, along with all the other code it executes, execute the functions 'foo_functionname'?
Yes, when the global_end hook is called (or any other hook for that matter), all of the "hooked in functions" (plugins which add hooks to it) are all executed.

So for example:

$plugins->add_hook("global_end", "my_function");
$plugins->add_hook("global_end", "my_second_function");

function my_function()
{
 echo "Hello<br />";
}

function my_second_function()
{
 echo "Hi again!";
}

That would output "Hello", then on a new line "Hi again!".

More information can be found on our wiki: http://wiki.mybboard.net/index.php/Plugins
Ahhh, okay. Thanks sooo much, Chris. That's really cleared up alot. Thanks!