Skip to content

Instantly share code, notes, and snippets.

@dgmstuart
Last active August 29, 2015 14:10
Show Gist options
  • Save dgmstuart/b232ec418f4724917b64 to your computer and use it in GitHub Desktop.
Save dgmstuart/b232ec418f4724917b64 to your computer and use it in GitHub Desktop.
A class for detecting when the plugin has updated (WordPress)
<?php
// ...
register_activation_hook( __FILE__, array( "dxw_security_Update_Checker", 'record_version' ));
if (dxw_security_Update_Checker::updated() ) {
dxw_security_Cron::schedule_tasks();
dxw_security_Update_Checker::record_version();
}
// ...
?>
<?php
defined('ABSPATH') OR exit;
class dxw_security_Update_Checker {
private static $version_key = "dxw_security_plugin_version";
public static function updated() {
return self::previous_version() != self::current_version();
}
public static function record_version() {
update_option(self::$version_key, self::current_version());
}
private static function previous_version() {
return get_site_option(self::$version_key);
}
private static function current_version() {
// TODO: is this OK or should we use get_plugin_data?
return DXW_SECURITY_PLUGIN_VERSION;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment