Jump to content

How to add module hooks, where to place them?


Recommended Posts



My ultimate goals is call a function based on the PreModuleCreate and AfterModuleCreate hook functions. http://docs.whmcs.com/Hooks:Products/Services#Products.2FServices_Hooks


According to WHMCS hooks documentation, http://docs.whmcs.com/Action_Hooks#Module_Hooks, I'm required to add a ""hooks.php" file within the module folder". I assume that the PreModuleCreate and AfterModuleCreate are module hook functions. So I've added a "hook.php" file to the relevant module/server path (/var/www/whmcs/modules/servers/modulename). I've also performed the instructed command of re-saving the module settings as per the WHMCS documentation.


After no success, I've then tried to dump the hooks.php file in the /var/www/whmcs/includes/hooks, still no luck executing these PreModuleCreate and AfterModuleCreate functions.


Am I missing something obvious? Is the Product/Service hooks (http://docs.whmcs.com/Hooks:Products/Services#Products.2FServices_Hooks) not module hooks?


The code for my hook files are:


function hook_websitepanel_premodulecreate($vars) {

$file = fopen(dirname(__FILE__) .'/logs/random.log', 'a');

fwrite($file, $vars['params']['pid']);




function hook_websitepanel_aftermodulecreate($vars) {

$file = fopen(dirname(__FILE__) .'/logs/random.log', 'a');

fwrite($file, $vars['params']['pid']);




add_hook("PreModuleCreate", 1, "hook_websitepanel_premodulecreate", "");

add_hook("AfterModuleCreate", 1, "hook_websitepanel_aftermodulecreate", "");


As you can see from the above, I'm simply writing the 'pid' value to a log file. The pid variable should be available as per http://docs.whmcs.com/Hooks:Products/Services#Products.2FServices_Hooks.


Where do I dump the hooks file :(?


Appreciate any help, thanks.



I Quote:


Module Hooks


As of WHMCS V4.4, addon modules support hooks being defined that relate to a module within the module directory in /modules/addons/

And as of WHMCS V5.0, both product/server/provisioning modules and domain registrar modules also support hooks being defined within the relevant modules directories.

To define hooks as part of a module, simple create a file named "hooks.php" within the module folder, and include all module specific hook related code within that file.

Note to Developers: Hook files in module folders are only called for active modules. And active modules that contain hooks are cached. So if you add a hooks file to a module retrospectively, once the module is already active, then before the system will detect and start running that module, you must edit and resave either the addon module configuration, product configuration or domain registrar configuration for the respective module for it to be detected.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated