Hooks for activation and deactivation provide you ways to do things when plugins are turned on or off.
- Plugins can execute a program to add custom database tables, alter rules, or default option values upon activation.
- Plugins can execute a procedure to delete temporary information, including cache and temporary files and folders, upon deactivation.
Sometimes people mistake the deactivation hook for the uninstall hook. The uninstall hook works best for permanently erasing all data, including custom tables and plugin settings.
Activation Hook
Use the register_activation_hook() function to configure an activation hook:
Deactivation Hook
Use the register_deactivation_hook() function to configure an deactivation hook:
The primary plugin file, where the plugin header comment is located, is the file that is referenced by the first parameter in each of these functions. These two functions will often be called from the main plugin file; if they are in another file, you will need to change the first parameter to properly point to the main plugin file.