Last active
August 29, 2015 14:11
-
-
Save A5hleyRich/8747d4c842a287c2640d to your computer and use it in GitHub Desktop.
Post: Upgrade Procedure for WordPress Plugin Developers
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 | |
define( 'MYPLUGIN_VERSION', '1.6.1' ); | |
if ( is_admin() ) { | |
include_once( plugin_dir_path( __FILE__ ) . 'includes/admin/upgrades.php' ); | |
} |
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 | |
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' ); |
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 | |
function myplugin_check_upgrades() { | |
} | |
add_action( 'plugins_loaded', 'myplugin_check_upgrades' ); |
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 | |
$version = get_option( 'myplugin-version' ); |
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 | |
/** | |
* Version 1.4 | |
*/ | |
if ( version_compare( $version, '1.4', '<' ) ) { | |
// Actions to perform | |
} | |
/** | |
* Version 1.5 | |
*/ | |
if ( version_compare( $version, '1.5', '<' ) ) { | |
// Actions to perform | |
} |
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 | |
// 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