Activated, Deactivate, Uninstall Methods

Three functions to do this:

register_activate_hook()register_deactivation_hook()register_uninstall_hook()

Let’s create the three methods in the main class.

public function activate(){}
public function deactivate(){}
public function uninstall(){}

Could call these in the constructor but we will put them in our main code right before the class is created so it looks like this:

 

if(! class_exists('Wib_Slider')){
class Wib_Slider{
function __construct(){
$this->define_constants();
}
public function define_constants(){
define ('WIB_SLIDER_PATH') = plugin_dir_path(__FILE__);
define ('WIB_SLIDER_URL') = plugin_dir_url(__FILE__);
define ('WIB_SLIDER_VERSION','1.0.0');
}
public static function activate(){}
public static function deactivate(){}
public static function uninstall(){}
}
}

if(class_exists('Wib_Slider')){
register_activation_hook(__FILE__, array('Wib_Slider', 'activate'));
register_deactivation_hook(__FILE__, array('Wib_Slider', 'deactivate'));
register_uninstall_hook(__FILE__, array('Wib_Slider', 'uninstall'));
$wib_slider = new Wib_Slider();
}

 

We pass an array to the hooks because our functions are in a class.  Our functions became static so they can be used outside of the class.