Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created December 12, 2014 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zanematthew/f8440442df8524a9dff0 to your computer and use it in GitHub Desktop.
Save zanematthew/f8440442df8524a9dff0 to your computer and use it in GitHub Desktop.
Storing plugin version number on activation and deleting it during plugin deactivation.
<?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