Hooks: How to Write an Addon that Adds Variables to the NavBar?
I am trying to figure out how hooks work, but I don't understand what each part of the code does.
#^https://framagit.org/hubzilla/addons/-/tree/master/skeletonWhat does this stuff mean, and how do you write a hook that inserts variables into the navbar?
/**
* * This function registers the hook.
* ? We don't have any documentation on what this actually does.
* We can guess based on the variables it has though:
* @param construct_page = not sure what this actually refers to. I'm guessing it refers to something that constructs the page?
* @param addon/exampleplugin/exampleplugin.php = this file
* @param exampleplugin_construct_page = the function defined below called exampleplugin_construct_page
* @param addon/exampleplugin/Mod_Exampleplugin.php = Not sure. Perhaps the file or page being modifed? This refers to a module included with the addon.
* @param exampleplugin = Not sure. The name of this hook, or the name of the addon calling the hook?
*/
function exampleplugin_load(){
Hook::register('construct_page', 'addon/exampleplugin/exampleplugin.php', 'exampleplugin_construct_page');
Route::register('addon/exampleplugin/Mod_Exampleplugin.php','exampleplugin');
}
// * This function unregisters the hook.
// ? We don't have any documentation on what this actually does.
function exampleplugin_unload(){
Hook::unregister('construct_page', 'addon/exampleplugin/exampleplugin.php', 'exampleplugin_construct_page');
Route::unregister('addon/exampleplugin/Mod_Exampleplugin.php','exampleplugin');
}
// * This function runs when the hook is called.
function exampleplugin_construct_page(&$b){
// some code here
}
If anyone could help me understand how hooks work, that would be appreciated.