Created
December 12, 2014 17:31
-
-
Save zanematthew/f8440442df8524a9dff0 to your computer and use it in GitHub Desktop.
Storing plugin version number on activation and deleting it during plugin deactivation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Manging of version numbers when plugin is activated | |
*/ | |
function MYPLUGIN_install() { | |
// Add Upgraded From Option | |
$current_version = get_option( MYPLUGIN_NAMESPACE . '_version' ); | |
if ( $current_version ) { | |
update_option( MYPLUGIN_NAMESPACE . '_version_upgraded_from', $current_version ); | |
} | |
update_option( MYPLUGIN_NAMESPACE . '_version', MYPLUGIN_VERSION ); | |
// Bail if activating from network, or bulk | |
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { | |
return; | |
} | |
// Add the transient to redirect | |
set_transient( '_' . MYPLUGIN_NAMESPACE . '_activation_redirect', true, 30 ); | |
} | |
register_activation_hook( MYPLUGIN_PLUGIN_FILE, 'MYPLUGIN_install' ); | |
/** | |
* Manging of version numbers when plugin is activated | |
*/ | |
function MYPLUGIN_deactivate() { | |
delete_option( MYPLUGIN_NAMESPACE . '_version', MYPLUGIN_VERSION ); | |
} | |
register_deactivation_hook( MYPLUGIN_PLUGIN_FILE, 'MYPLUGIN_deactivate' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment