-
Notifications
You must be signed in to change notification settings - Fork 5
Register Plugin Hook
ecorica edited this page Jul 23, 2021
·
1 revision
If you want to add hooks for activation and deactivation of the plugin you need to generate the class Plugin.php
1. Create your Plugin class
<?php
namespace BEA\PB;
/**
* The purpose of the plugin class is to have the methods for
* - activation actions
* - deactivation actions
* - uninstall actions
*
* Class Plugin
* @package BEA\PB
*/
class Plugin {
/**
* Use the trait
*/
use Singleton;
public static function activate(): void {
}
public static function deactivate(): void {
}
}
2. Add the registry activation and deactivation hook in the '.php' root file of your plugin (ex : my-plugin.php).
// Plugin activate/deactivate hooks
register_activation_hook( __FILE__, array( '\BEA\PB\Plugin', 'activate' ) );
register_deactivation_hook( __FILE__, array( '\BEA\PB\Plugin', 'deactivate' ) );
To keep consistency with the old boilerplate you can add it before :
add_action( 'plugins_loaded', 'init_bea_pb_plugin' );