Kirby fires a bunch of events when important things happen in the background. For example when a page is being created or deleted or a file gets uploaded. You can hook into those events and add your own functions that will be executed when those events happen.
Hooks are not restricted to Panel events, but are implemented everywhere: hooks are called no matter if an event happens in the Panel, on the command line or in your own scripts.
In a plugin, hooks are registered with the hooks extension. The extension accepts an array of key/value pairs where the key is the event and the value a function with the code that should be executed before or after an event.
Kirby provides the hook arguments by variable name, not by position (similar to controllers). This allows you to request just the arguments you need in any order. All arguments that are not available will be passed as null:
There is also a special $event argument that contains all information about the event, including the full event name, its individual parts (type, action and state) and all named hook arguments:
You can also define your own custom hook types in plugins, which works just like with the built-in hooks:
As you can see, only the name of the hook has changed. Please make sure to namespace your hooks by including the plugin name in the hook name. Otherwise your hooks might conflict with other plugins or future built-in hooks.
The two main use-cases for custom hooks are communication between two plugins (one plugin triggers an event and another registers a hook to listen for it) and hooks that are registered from the site config to allow users to add custom behavior to plugins.