Hook mechanism explained

Hook mechanism explained
Tillreetree@fc7e1f5a Wednesday 7th June 2023, 03:44:13Flatboard's Hook mechanism can be confusing when you first get started, so I'll try to explain it clearly.
The hook method in the Plugin class takes two parameters: $name is the name of the hook to be executed, $param is the parameter to be passed to the hook function. It iterates through all the enabled plugins, uses the isValidHook method to determine if there is a corresponding hook function, and if so, uses the myHook method to execute the function and adds the return value to the $out variable (so that multiple plugins can use the same hook), and finally returned the $out string.
Based on incomplete testing, the order of the Hook may be related to the name of the plugin.
Example
When myPlugin is enabled, it can be accessed in the main app via
to call myDemoHook in the myPlugin.
The output may resemble:
The hook method in the Plugin class takes two parameters: $name is the name of the hook to be executed, $param is the parameter to be passed to the hook function. It iterates through all the enabled plugins, uses the isValidHook method to determine if there is a corresponding hook function, and if so, uses the myHook method to execute the function and adds the return value to the $out variable (so that multiple plugins can use the same hook), and finally returned the $out string.
Based on incomplete testing, the order of the Hook may be related to the name of the plugin.
Example
<?php
function myPlugin_myDemoHook($param) {
return 'Hello ' . str_shuffle($param);
}
?>
When myPlugin is enabled, it can be accessed in the main app via
$out .= Plugin::hook('myDemoHook', 'parameter');
OR
echo Plugin::hook('myDemoHook', 'parameter');
to call myDemoHook in the myPlugin.
The output may resemble:
Hello trermeapa
Last modified by Tillreetree@fc7e1f5a on Wednesday 7th June 2023, 03:48:00
Replies 2


Suggested Topics

Ben@84171e7c
started Emjois will pop up automatically in the wrong places: URLS and Code
Bug reports

cborne#11fae1
started ๐ซ๐ท Installation du 7 mai
International Discussions

Var@4c5764c3
started Two minor tweaks/enhancements request
Feature Requests

AlexanderLiebrecht@5e3cf8af
started ๐ฉ๐ช What about the use of the new flatboard theme?
General Questions