Plugin Active & Deactive
Plugins will be on inactive status by default. We can click on the activate link under the plugin name to activate the plugin. Once the plugin is successfully activated, its features will get effected to your website.
Also you should be able to see deactivate link instead of activate link after a successful activation. Clicking the deactivate link will revert the status of the plugin to its original inactive status.
WordPress provides a concept called hooks, where you can trigger certain tasks to add new behavior or modify existing behavior. So let’s look into the code for activation and deactivation hooks.
function fwds_slider_activation() {
}
register_activation_hook(__FILE__, 'fwds_slider_activation');
function fwds_slider_deactivation() {
}
register_deactivation_hook(__FILE__, 'fwds_slider_deactivation');
Above code contains two functions called fwds_slider_activation and fwds_slider_deactivation.
Then we have the two hooks called register_activation_hook and register_deactivation_hook.
Following is a list of possible things we can do inside plugin activation/deactivation.
- Create custom database tables on activation to store data and remove tables on deactivation.
- Create custom options for plugins and activation and reset in deactivation.
- Validate other dependent plugin on activation.
- Any other necessary task you need to execute in activation.