Skip to content

Instantly share code, notes, and snippets.

@aaronjorbin
Created December 26, 2013 20:53
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 aaronjorbin/8138584 to your computer and use it in GitHub Desktop.
Save aaronjorbin/8138584 to your computer and use it in GitHub Desktop.
Example of an update routine for a plugin
<?php
/*
Plugin Name: update versioning
Description: Example of an update routine for a plugin
Author: Aaron Jorbin
Version: 0.1
Author URI: http://aaron.jorb.in
*/
add_action('admin_init', 'jorbin_update_routine');
function jorbin_update_routine(){
$version = get_option( 'jorbin_db_version', null);
if ( is_null($version) ) {
add_option('jorbin_db_version', 0, '', 'yes');
return;
} else {
// Cast to integer so we can do simple comparisons
$version = (int) $version;
}
if ( $version < 1 ) {
jorbin_update_1();
$new_version = 1;
}
if ( $version < 2 ) {
jorbin_update_2();
$new_version = 2;
}
// If we updated the options, save our new version
if ( isset($new_version) && $new_version !== $version ) {
update_option( 'jorbin_db_version', $new_version );
}
}
function jorbin_update_1(){
// update options blah blah blah
}
function jorbin_update_2(){
// update options blah blah blah
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment