Hook mechanism explained

Tillreetree
Hook mechanism explained
Tillreetree@fc7e1f5a Wednesday 7th June 2023, 03:44:13

Flatboard's Hook mechanism can be confusing when you first get started, so I'll try to explain it clearly.


The [i]hook[/i] method in the [i]Plugin [/i]class takes two parameters: [i]$name[/i] is the name of the hook to be executed, [i]$param[/i] is the parameter to be passed to the hook function. It iterates through all the enabled plugins, uses the [i]isValidHook[/i] method to determine if there is a corresponding hook function, and if so, uses the [i]myHook[/i] method to execute the function and adds the return value to the [i]$out[/i] variable (so that multiple plugins can use the same hook), and finally returned the [i]$out[/i] string.


Based on incomplete testing, the order of the Hook may be related to the name of the plugin.


[color=#7bd148]Example[/color]



<?php
function myPlugin_myDemoHook($param) {
return 'Hello ' . str_shuffle($param);
}
?>


When [i]myPlugin[/i] is enabled, it can be accessed in the main app via



$out .= Plugin::hook('myDemoHook', 'parameter');
OR
echo Plugin::hook('myDemoHook', 'parameter');


to call [i]myDemoHook[/i] in the [i]myPlugin[/i].


The output may resemble:


Hello trermeapa


Last modified by Tillreetree@fc7e1f5a on Wednesday 7th June 2023, 03:48:00

Replies 2
SurveyBuilder-Admin
SurveyBuilder-Admin  Wednesday 7th June 2023, 16:20:50

Very well explain to new users for never used it before. I have done 4 years of web application development so good job explaining it 😊.

Software engineer, creates plugins for Flatboard, checks source codes, and answers any software errors questions and contributes on the GitHub page as well

Ben
Ben@84171e7c  Tuesday 18th July 2023, 17:07:29

Thank you for this Tillreetree@fc7e1f5a, very nicely done.


Suggested Topics
started
66.3K 0
Fred
Fred started Backup
Resources
6.8K 7
mk
mk@b8500609 started Login
General Questions
6.2K 18
Want to read more? Browse all categories or view latest topics.