From ddf28801e4720b9d7888b9bca5daf6be14d3720c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Apr 2013 17:26:22 +0400 Subject: [PATCH] implement plugin API version compatibility check --- classes/plugin.php | 6 ++++++ classes/pluginhost.php | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/classes/plugin.php b/classes/plugin.php index 60f12763..8fbacf36 100644 --- a/classes/plugin.php +++ b/classes/plugin.php @@ -3,6 +3,8 @@ class Plugin { private $dbh; private $host; + const API_VERSION_COMPAT = 1; + function init($host) { $this->dbh = $host->get_dbh(); $this->host = $host; @@ -20,5 +22,9 @@ class Plugin { function get_prefs_js() { return ""; } + + function api_version() { + return Plugin::API_VERSION_COMPAT; + } } ?> diff --git a/classes/pluginhost.php b/classes/pluginhost.php index d51f7021..dc75e31f 100644 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -13,6 +13,8 @@ class PluginHost { private $last_registered; private static $instance; + const API_VERSION = 1; + const HOOK_ARTICLE_BUTTON = 1; const HOOK_ARTICLE_FILTER = 2; const HOOK_PREFS_TAB = 3; @@ -137,6 +139,13 @@ class PluginHost { if (class_exists($class) && is_subclass_of($class, "Plugin")) { $plugin = new $class($this); + $plugin_api = $plugin->api_version(); + + if ($plugin_api < PluginHost::API_VERSION) { + user_error("Plugin $class is not compatible with current API version (need: " . PluginHost::API_VERSION . ", got: $plugin_api)", E_USER_WARNING); + continue; + } + $this->last_registered = $class; switch ($kind) { -- 2.39.5