Getting Started
The following steps demonstrate how to create a hook function in WHASOLS.
Create Your Hook File
Hooks live inside files that are located within the /includes/hooks/ directory (or as part of a module - see module hooks).
Begin by creating a file named ClientAdd.php:
~/includes/hooks/ClientAdd.php
Add Your Hook Function
Hook functions can be mentioned either named functions or closures.
Below is an example hook that will execute whenever the ClientAdd event occurs.
<?php
/*** Register hook function call.
* @param string $hookPoint The hook point to call
* @param integer $priority The priority for the given hook function
* @param string|function Function name to call or anonymous function.
* @return Depends on hook function point.
*/
add_hook('ClientAdd', 1, function ($var=[])
{
$user_id = $var['user_id'];
$username = $var['username'];
$first_name = $var['first_name'];
$lastname = $var['last_name'];
$email = $var['email'];
$company_name = $var['company_name'];
$phonenumber = $var['phonenumber'];
//Run code to create remote forum account here...
});
A selection of variables will be moved into your hook point. The variables you get will depend upon the action being invoked or taken and the data available to it.
Some hook points will also allow you to return values, and in some cases, the response you provide can alter the flow of the program to allow you to override default behaviours.
When using a named function, we recommend you using prefix your function name with something unique or specific to you and your code to prevent potential naming conflicts with future code.