nBill allows you to add your own files of PHP code to be executed when a particular event occurs (eg. when a user record is created, when a backup is generated, when an order status is changed, etc.). There are over 50 events that you can hook into. It is very easy - all you have to do is add your PHP file to the appropriate event folder. Files are executed in alphabetical order by file name. The event folders are held here:


If you look in that folder, you will see a separate sub-folder for each event that is supported by nBill. Inside each event folder is a readme text file which tells you what parameters are available to any scripts that are added there. The files are included (in the PHP sense of the word) when the event is fired, so your scripts will have access to nBill's built-in functions, as well as the API of the CMS itself (so you can run database queries etc.).

You can access parameters using the $params array that is populated before your script is called. For example, $params['id'] would usually return the relevant primary key, depending on the event.

Typically, an event will be handed an ID parameter (or a list of IDs) that will allow you to load a related record from the database. For example on the client_deleted event, a the client IDs of the records being deleted is passed in as a comma-separated list - you can load the rest of the client details from the database yourself, as they will not be passed in to your script. For a 'deleted' event, the event is fired immediately before the record is deleted, whereas for an 'added' or 'updated' event, the event is fired immediately after the record is added or changed.

Order Form Events

In addition to the events folders, there are some events that are form-specific - ie. you can define different code for the same event on different forms. See theĀ advanced tab of the order form editor for more information.