Troubleshooting Hooks
During the development process, you may need to verify whether your hooks are working correctly. This can include checking whether hooks are loading properly, triggering the desired hook point, and running the expected hook code.
Check Hook Loading
To check whether your hooks are loading properly, enable debugging for them.
To do this:
- Go to the Other tab at Configuration () > System Settings > General Settings.
- Check Hooks Debug Mode.
- Click Save Changes.
- Perform the action that should trigger the action hook point.
- Go to Configuration () > System Logs.
- Examine the most recent log entries for
Hook File Loaded
messages:
Check Hook Triggering
If your hooks are loading properly, you can proceed to checking whether the hook point is triggering.
To do this:
- Enable Hooks Debug Mode (if it is not already enabled) and perform the hook action (above).
- Go to Configuration () > System Logs.
- Examine the most recent log entries for
Called Hook Point
messages:
In the example above, the system successfully called the AdminAreaFooterOutput
hook point.
Check Hook Execution
If your hooks are loading properly and triggering, you can proceed to checking whether your code is executing.
To do this, you can use the logActivity()
function. This method allows you to debug the results to check which variables are present when the hook triggers:
Add the following line at the end of your code:
logActivity('Hook variables: '.print_r($vars, true));
For example:
<?php if(!defined('WHMCS')) { die('This hook should not be run directly'); } add_hook('AdminAreaFooterOutput', 1,function($vars) { logActivity("AdminAreaFooterOutput hook has run. Posted Vars: ". print_r($vars, true)); });
Enable Hooks Debug Mode (if it is not already enabled) and perform the hook action (above).
Go to Configuration () > System Logs.
Examine the most recent log entries. The variables will display in the log entries.
Module Hooks
Typically, the system will load hook files on every page load.
- Exact hook behavior depends on the specific module.
- The system triggers hook code every time a module command runs for any module for which the hook is active.
Hook Changes After Module Activation
The system detects hook files when you activate the module. If the module is already active when you add or modify a hook file, you will need to perform additional steps:
- For server and provisioning modules, go to the Module Settings tab for an applicable product at Configuration () > System Settings > Products/Services and click Save Changes.
- For domain registrar modules, go to that domain registrar at Configuration () > System Settings > Domain Registrars and click Save Changes.
- For addon modules, go to that addon module at Configuration () > System Settings > Addon Modules and click Save Changes.
Last modified: October 30, 2024