Skip to content

Instantly share code, notes, and snippets.

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 scofennell/b3a5cebf9d3da44a341c to your computer and use it in GitHub Desktop.
Save scofennell/b3a5cebf9d3da44a341c to your computer and use it in GitHub Desktop.
WordPress Function to Perform Plugin Update Routine
<?php
/**
* Establish a routine of tasks to perform when this plugin is updated.
*
* @package WordPress
* @subpackage sjf-et
* @since SJF ET 1.5.5
*/
function sjf_et_admin_update_init() {
new SJF_Ecwid_Admin_Update();
}
add_action( 'plugins_loaded', 'sjf_et_admin_update_init' );
class SJF_Ecwid_Admin_Update {
function __construct() {
add_action( 'admin_init', array( $this, 'dump_transients' ) );
}
/**
* Determine if our plugin is in need of maintenance tasks as a result of having been updated.
*
* @return boolean Returns TRUE if our plugin has been updated since the last check, else FALSE.
*/
function is_old() {
// Build a key to refer to the plugin version in the database.
$namespace = SJF_Ecwid_Helpers::get_namespace();
$key = $namespace . '_version';
// Grab the plugin version from the database.
$db_v = get_option( $key );
/**
* Compare the db version to the file version.
* We're assuming that we remember to update the file version when we update the plugin.
*/
if( SJF_ET_VERSION != $db_v ) {
// Update the db version to mimic the file version.
update_option( $key, SJF_ET_VERSION );
wp_die(45);
// Return TRUE -- yes, we need to run update tasks.
return TRUE;
// No, we don't need to run update tasks.
} else {
return FALSE;
}
}
/**
* One of the tasks we perform upon updating is to dump our transients, which includes flushing rules.
*/
function dump_transients() {
if( ! $this -> is_old() ) { return FALSE; }
$transients = new SJF_Ecwid_Transients( FALSE );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment