Activate / Deactivate Hooks in WordPress
Step 3
There are 3 Core Hooks in WordPress Plugin
- Register_activation_hook ();
- Register_deactivation_hook ();
- Register_uninstall_hook ();
But we can’t use Register_uninstall_hook () instead of this we create a new file with name uninstall. php within same folder
And write the below code to delete the plugin
<?php
Defined(‘ABSPATH’) || die Plugin deleted successfully “);
?>
Above 3 hooks has 2 parameter first is file name and second one is callback or anonymous function, while passing these parameters now plugin work smoothly as given below
<?php
/**
* Plugin Name: Shairy Plugin
* Author: Er. Shairy Kalra
* Author uri: https://ershairykalra.com/
* Version:1.0.0
* Description: This is the basic plugin to understand the functionality how a plugin is created
*/
if(!defined(‘ABSPATH’)):
die(“You can’t access this file directly”);
endif;
register_activation_hook(__FILE__,function(){
add_option(‘updateTitle’,’This is Mine Title !’);
});
register_deactivation_hook(__FILE__,’deactivate_option’);
function deactivate_option(){
delete_option(‘updateTitle’,’This is Mine Title !’);
}
?>
Now you can check from this URL; a new title is added on activation of plugin
http://localhost/shairy_portfolio/wp-admin/options.php