Created
December 26, 2013 20:53
-
-
Save aaronjorbin/8138584 to your computer and use it in GitHub Desktop.
Example of an update routine for a plugin
This file contains hidden or 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 | |
/* | |
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