MyBB Community Forums

Full Version: Hooks vs. Plugins?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
What's the difference? And what does each do/what's it's purpose??
Plugin... I'm guessing you know what one is.

Hooking is a technique typically used in plugins to inject code into various places.
So for example..If you have...
<?php
$hook = new Hookname;
$hook->placeCode($text);
?>
The hook for 'Hookname', would place whatever is inside the "placeCode()" function?(ex: placeCode($text) { echo $text; })
No, the hooks in MyBB are places where you find code like:
$plugins->run_hooks('hook_name');

Plugins "attach" themselves to hooks by running:
$plugins->add_hook('hook_name', 'callback_function_to_run');

When the MyBB code reaches the run_hooks, the plugin system will find all the functions that were "attached" to the hook, and run those functions. Then it will continue the rest of the code.
Sorry, but I'm confused..
You could look up function pointers, but that might hurt you head more.
http://bisqwit.iki.fi/story/howto/php/#FunctionPointers

Think of a hook as a named callback. Essentially, you just register a function to be "called back" when the MyBB code hits the hook with the a certain name. Quite clever really, I never knew PHP could handle function pointers until now. (I know they're not "real" function pointers in PHP, but they behave in a similar way - also note the title of that webpage was "A guide into the PHP language for C++ programmers" - that's me Toungue).
So basically, a hook is a call to a plugins function that places code/html/a query result, etc, etc. - onto the page where the hook coding is placed in the file? Sorry to keep asking, but I just need a clarification..
Yes, a hook will call a plugin's function. The function itself can do pretty much anything, the hook itself just acts like a trigger.
And where is this function that would be called?
(2008-06-10, 03:45 AM)dikidera Wrote: [ -> ]And where is this function that would be called?

In the plugin file.
Pages: 1 2