Getting Started
The following steps show how to create a hook function in WISECP.
Create Your Hook File
Hooks are in the files (or in core file of a module) under /coremio/hooks/ directory.
Begin with creating a file named hello.php :
touch ~/coremio/hooks/hello.php
Add Your Hook Function
There is a sample hook below that will be executed when a client account creation event occurs.
/**
* Example hook function for client register
* @param string $name Name of the hook to be called
* @param integer $priority Priority for hook function
* @param callable|array You can send a callable function or an array, example as follows:
* [
* 'function' => 'function name',
* 'class' => 'class name',
* 'method' => 'public method name in class', // class -> function
* 'method::static' => 'static method name in class', // class :: function
* ]
*
* @return void
*/
Hook::add("ClientCreated",1,function($params=[]){
$name = $params['name'];
$surname = $params['surname'];
$email = $params['email'];
$phone = $params['phone'];
/** Write the code here... */
});
A series of variables will be transferred to your hook point. The variables you receive depend on the action being called and the available data.
Some hooks also allow you to return a value, and in some cases, the response you provide may modify the program flow to override the default behavior.
Note:
When using a named function, we recommend that you include a prefix specific to your function name and your code to avoid possible naming conflicts with future code.
When using a named function, we recommend that you include a prefix specific to your function name and your code to avoid possible naming conflicts with future code.