Hook System
addAction, addFilter, priority, callbacks
What it is
The hook system allows addons to run code at specific points in WHMDC without modifying core files. You register callbacks for actions (run code when something happens, e.g. invoice created) or filters (modify data before it is used, e.g. handle a custom domain action).
Actions vs filters
- Actions: Run code at a point in the flow. Your callback receives data but does not return a value. Use for notifications, logging, syncing to external systems.
- Filters: Modify a value. Your callback receives the value and optional args, and must return the (possibly modified) value. Use when you need to intercept and change behaviour (e.g. handle a custom domain manage action).
Registering hooks
In your addon's hooks.php, use HookManager::addAction() or HookManager::addFilter(). The third parameter is priority (default 10); lower numbers run first.
Example: Action (run code when invoice is created)
<?php
// In modules/addons/myaddon/hooks.php
HookManager::addAction('slack_invoice_created', function($data) {
$invoiceId = $data['invoice_id'] ?? null;
$clientId = $data['client_id'] ?? null;
// Send to CRM, log, etc.
error_log('Invoice created: ' . $invoiceId);
}, 10);
Example: Filter (handle custom domain action)
<?php
HookManager::addFilter('client_domain_manage_action', function($handled, $manageAction, $domain, $domainId, $registrar, $client) {
if ($manageAction !== 'my_custom_action') {
return $handled;
}
// Do your custom logic, return true if you handled it
return true;
}, 10, 6);
Example: Output HTML before footer
<?php
HookManager::addAction('client_footer', function() {
echo '<!-- My addon loaded -->';
}, 10);
Full hook list
See the Hooks Reference for a complete list of every action and filter, when they fire, and what parameters they receive.
Was this helpful?