Menu

Plugin Hooks

Akram Deshwali

Plugin Hooks

Ok, now that you have a general idea about the default functions lets move on to hooks. As you may understood from the previous pace the default function only provide information and get executed in the plugin manager since they are used to store plugin info and some default actions in certain moments(install,activate,deactivate,uninstall etc..). But obviously we need more then that and hooks are here to help us. The general idea for our plugins is that if you need to do something make a function for it.
How do plugins work?
When you activate a plugin, its codename (the first part of its file name before _plugin.php) is saved in an array in the mysql database.

All the active plugins are 'included' at the start of each page. (Thus, if you have many plugins installed, the speed of your site may decrease slightly, depending on the nature of your plugins). The hooks that each plugin uses is stored in memory.
When a hook is 'run' when a page is being executed, the array mentioned earlier is searched to see if there are functions from the plugins loaded earlier associated with this hook. If there are, each function is executed.
You can think of it sending function to a certain location. You do nothing more then defining them in the plugin and they get called(or executed) in the address you sent it to.
Track the hooks.
In order to track hooks you need to look on a page after 2 functions. (All the plugins related functions are stored in the object $plugins)

$plugins->run_hook("index_top");
or
$tpl->grab('index.tpl','index');

I took those from /index.php file. Now what do they mean and what is the difference between those two ? The first one it will just run the assigned function at the moment that it is called and it won't provide and arguments for the function. Basically nothing gets in the function it will just run it as a void arguments function(example do_stuff();). The argument value that you see index_top represents the address witch you will use to assign function to be executed in that place On the second one you may notice that we don't have the object $plugins but it is used in the template class. Now apart from the object how is this different from the first one ? The difference is in the arguments. If the first one will call your function like this do_stuff(); the second one will do something like this do_stuff($value); where $value is a string that represents the content of a tpl file. You may notice 2 arguments on this one. The first one is the tpl file that will be loaded on the page and the second one represents the address(name) of the hook. You can find the tpl files in /tpl.
You can find a list of all the hooks and their files in /plugins/hook_list.txt . You can also download it from Here So now you know the hooks also. Lets [Assign functions to hooks]!


Related

Wiki: AD AutoIndex Plugins Documentation