MyBB Community Forums

Full Version: Plugin Hooks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm new to authoring plugins and I don't understand what exactly are hooks and how to use them. I was wondering if someone could explain me how to use hooks and what hooks actually do. Someone told me that even though I'm denied support I can receive help regarding this.
Hooks are basically an asset which allows you to create and run some function on specific part of site.

For example, if you created a function which does something or want to show something on index page, then the hook 'index_start' or 'index_end' is used. So that function runs on the index page.

Similar is the scenario with all other hooks. Unless you hook your function, they won't work.
Thanks guys but how do I exactly know when to use a specific hook?
Basically just look for the function/file that you think you need to use in order to make your plugin work the way you want it to. The best way is either browsing the hook list and looking through the files around where the hook is run, or just by downloading plugins that have similar features to what you want to do and mimicking their code.
I second the last opinion. Reading a code is great way to learn rather than reading a book or tutorial. Download the existing plugins, open the source codes and read. You will soon be understanding much more about plugin hooks and their functionality.
Thanks guys, I will try downloading plugins and start reading their hooks. What kind of plugins should I start from? I mean which ones are easy to create?
In order for a plugin to do anything, a function of the plugin has to be called at the right time. And that's what the hooks do. There's a hook for when the page loads, a hook for when someone posts something, a hook for when someone views a private message, etc. Without hooks, your plugin would simply sit there and do nothing.

If you want to experiment with hooks without writing a full plugin, you could check out my Hooks plugin. Which lets you define PHP code that runs in hooks.
Thanks for the help everyone.