Search code examples
phphookwhmcs

Understanding WHMCS hook priorities


I'm working on a module for WHMCS that needs to execute a few functions after the daily cron job. This isn't too hard to do, but I'm having some issues understanding hook priorities, since the functions need to be executed in a specific order.

I've looked online, but haven't found a definitive answer yet, and the WHMCS documentation is severely lacking in this aspect.

I'm looking for the following information:

  • Are hook actions executed by ascending or descending priority?
  • Are duplicate priorities for the same hook allowed?

Thanks!


Solution

    • Hooks are executed ascending. 1 before 2 before 3, and so on.
    • Duplicate priorities are supported. Hooks are then called in the order they are registered.

    I have seen some older reports that duplicate priorities override each other, but I tested in whmcs version 7.0 and verified that at least this code is executed as expected:

    <?php
    
    add_hook('ClientAreaPage', 1, function(){
       echo "First hook call";
    });
    
    add_hook('ClientAreaPage', 1, function(){
       echo "Second hook call";
    });