Actions and Triggers are awesome, and they made it into core with Drupal 6. The combination of the modules creates an event and responder system for Drupal. On a basic level, Triggers are like events in (for instance, creating a comment). Actions are then the responding procedure that Drupal takes based on that Trigger.
Triggers, on the other hand, have little documentation on how to create new ones. There are many built in triggers that provide a lot of events to attach actions to. But, when creating any critical modules, it is important to be able to set events so that logging and notifying can happen at the right points.
So, here is some example code for creating your own trigger.
Example
Permissions
This hook is not necessary to implement. But as I think it is good practice to implement specific permissions, I am including it. There is also a bug/problem with the trigger module, which restricts access control to triggers based on module name. Which I volunteered to patch and have not followed through with; my apologies. Nonetheless, we can work around this with hook_menu_alter().
Menu Alter
We want the permissions for administering our trigger to be unique, so we implement this hook.
Hook Info
This hook tells the trigger module about our triggers.
Attaching Actions
The next step is to define which actions will be able to be run with our triggers. We will add two actions that are already provided: the Message and Email actions. We don’t want to step on any other trigger toes. If we are not careful, we will make it so that actions will only be allowed on our trigger. So, we implement some basic conditional logic.
Invoke Wrapper
This is unnecessary, but helps a lot. We want to make sure that all modules know whats going on when we call our trigger, so we create this wrapper function.
Calling Our Trigger
This is just a sample function where we call our new trigger.