Difference between revisions of "Hooks"

From WHMCS Documentation

m
(Replaced content with "<div class="docs-alert-info"> <span class="title">Note</span><br /> This page has moved to [https://developers.whmcs.com/hooks/ https://developers.whmcs.com/hooks/] </div>")
 
(17 intermediate revisions by 4 users not shown)
Line 1: Line 1:
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...
+
<div class="docs-alert-info">
 
+
<span class="title">Note</span><br />
==How It Works==
+
This page has moved to [https://developers.whmcs.com/hooks/ https://developers.whmcs.com/hooks/]
 
+
</div>
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.
 
 
 
{{Hook_Categories}}
 

Latest revision as of 10:45, 4 January 2017

Note
This page has moved to https://developers.whmcs.com/hooks/