The WHMCS hook documentation is quite minimal and does not comprehensively list all the variables passed by the system to each hook. As a result, developers often have to guess or take inspiration from code written by others (who likely guessed before us, until they discovered the right variable...).
However, there’s a very simple way to discover and document all the variables passed to a specific hook. For example, to inspect the PreRegistrarRegisterDomain
hook, you can simply create and run the following hook:
add_hook('PreRegistrarRegisterDomain', 1, function($vars) {
$results = logActivity(json_encode($vars),0);
});
The result will be a line in the WHMCS log file with a string in JSON format, containing all available variables and their corresponding values.
NOTES:
-
The log entries generated this way can be quite large and heavy; it’s recommended to delete or disable the hook right after obtaining the needed information.
-
The single-line JSON format in the log file is not very readable; for better readability, it’s a good idea to paste it into a tool like https://jsonformatter.org/json-parser.
-
The line of code
logActivity(json_encode($vars), 0);
can also be useful within any hook code for debugging purposes, to discover the exact values of the variables passed to a specific hook.