Skip to content

Instantly share code, notes, and snippets.

@A5hleyRich
Last active August 29, 2015 14:11
Show Gist options
  • Save A5hleyRich/8747d4c842a287c2640d to your computer and use it in GitHub Desktop.
Save A5hleyRich/8747d4c842a287c2640d to your computer and use it in GitHub Desktop.
Post: Upgrade Procedure for WordPress Plugin Developers
<?php
define( 'MYPLUGIN_VERSION', '1.6.1' );
if ( is_admin() ) {
include_once( plugin_dir_path( __FILE__ ) . 'includes/admin/upgrades.php' );
}
<?php
function myplugin_check_upgrades() {
$version = get_option( 'myplugin-version' );
/**
* Version 1.4
*/
if ( version_compare( $version, '1.4', '<' ) ) {
// Actions to perform
}
/**
* Version 1.5
*/
if ( version_compare( $version, '1.5', '<' ) ) {
// Actions to perform
}
// Update version numbers
if ( $version !== MYPLUGIN_VERSION ) {
// Previous version installed, save prior version to db
if ( false !== $version ) {
update_option( 'myplugin-prior-version', $version );
}
update_option( 'myplugin-version', MYPLUGIN_VERSION );
}
}
add_action( 'plugins_loaded', 'myplugin_check_upgrades' );
<?php
function myplugin_check_upgrades() {
}
add_action( 'plugins_loaded', 'myplugin_check_upgrades' );
<?php
$version = get_option( 'myplugin-version' );
<?php
/**
* Version 1.4
*/
if ( version_compare( $version, '1.4', '<' ) ) {
// Actions to perform
}
/**
* Version 1.5
*/
if ( version_compare( $version, '1.5', '<' ) ) {
// Actions to perform
}
<?php
// Update version numbers
if ( $version !== MYPLUGIN_VERSION ) {
// Previous version installed, save prior version to db
if ( false !== $version ) {
update_option( 'myplugin-prior-version', $version );
}
update_option( 'myplugin-version', MYPLUGIN_VERSION );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment