Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define ( 'MY_PLUGIN_VERSION', '2.0.0');
- register_activation_hook(__FILE__, 'my_plugin_activation'));
- register_deactivation_hook(__FILE__, 'my_plugin_deactivation'));
- function my_plugin_activation() {
- // Initialize some stuff for my_plugin
- }
- function my_plugin_deactivation() {
- // Welp, I've been deactivated - are there some things I should clean up?
- }
- function my_plugin_activation() {
- $version = get_option( 'my_plugin_version' );
- if( version_compare($version, '2.0.0', '<')) {
- // Do some special things when we update to 2.0.0.
- }
- update_option( 'my_plugin_version', MY_PLUGIN_VERSION );
- return MY_PLUGIN_VERSION;
- }
- function my_plugin_is_current_version(){
- $version = get_option( 'my_plugin_version' );
- return version_compare($version, MY_PLUGIN_VERSION, '=') ? true : false;
- }
- if ( !my_plugin_is_current_version() ) my_plugin_activation();
- add_action('activated_plugin', 'my_plugin_activation_error');
- my_plugin_activation_error() {
- file_put_contents( plugin_dir_path(__FILE__) . '/error_activation.html', ob_get_contents());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement