Difference between revisions of "Hooks"

From WHMCS Documentation

m
Line 10: Line 10:
 
  add_hook("ClientAdd",1,"create_forum_account");
 
  add_hook("ClientAdd",1,"create_forum_account");
  
*The first part defines the hook point.  This must be one of the values from below: ClientAdd, AddInvoicePayment, TicketOpen, etc...
+
*The first part defines the hook point.  This must be one of the hook points in the categories below: ClientAdd, AddInvoicePayment, TicketOpen, etc...
 
*The number defines the priority so if you have more than 1 hook for the ClientAdd function, the order in which the hooks should run
 
*The number defines the priority so if you have more than 1 hook for the ClientAdd function, the order in which the hooks should run
 
*The third argument tells WHMCS which function to run at this hook point and so this is the name of the function which you have written in your hook file
 
*The third argument tells WHMCS which function to run at this hook point and so this is the name of the function which you have written in your hook file

Revision as of 16:14, 5 July 2011

Action hooks allow you to add your own code that will run when specific actions occur in WHMCS. For example, this can be used for things like performing other actions when an order is placed, sending an SMS message when a support ticket is opened, updating a users details in another application when a change is made in WHMCS, and many more...

How It Works

Hooks work by creating a file in the includes/hooks folder. Within the file, you need to declare a function that performs the action you want to run. That function will be passed variables from WHMCS, and the values you get depend on the hook being called. All hooks and the variables they will be passed are listed below. After defining your function, you then add the hook to WHMCS which is done by calling the add_hook function:

function create_forum_account($vars) {
    print_r($vars);
}
add_hook("ClientAdd",1,"create_forum_account");
  • The first part defines the hook point. This must be one of the hook points in the categories below: ClientAdd, AddInvoicePayment, TicketOpen, etc...
  • The number defines the priority so if you have more than 1 hook for the ClientAdd function, the order in which the hooks should run
  • The third argument tells WHMCS which function to run at this hook point and so this is the name of the function which you have written in your hook file

Two example hook files are included which you'll find in the hooks folder - one basic example showing the file format and another providing a fully working example of a ClientAdd hook to validate an entered Tax/VAT ID Number.

Hook Points

Hooks are separated into categories to help you decide which hook point you should use.