provide a Hook method to unregister all hooks with a given filespec component. This will be useful in upgrading plugins to use new interfaces, as you won't have to individually unregister hook declarations that you are no longer using in the code.

This commit is contained in:
redmatrix 2016-04-27 22:44:06 -07:00
parent bdef71bda0
commit 2ddd03f597

View file

@ -20,6 +20,15 @@ class Hook {
if($r)
return true;
// To aid in upgrade and transition, remove old settings for any registered hooks that match in all respects except
// for priority or hook_version
$r = q("DELETE FROM `hook` where `hook` = '%s' and `file` = '%s' and `function` = '%s'",
dbesc($hook),
dbesc($file),
dbesc($function),
);
$r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`, `hook_version`) VALUES ( '%s', '%s', '%s', %d, %d )",
dbesc($hook),
dbesc($file),
@ -46,6 +55,18 @@ class Hook {
return $r;
}
// unregister all hooks with this file component.
// Useful for addon upgrades where you want to clean out old interfaces.
static public function unregister_by_file($file) {
$r = q("DELETE FROM hook WHERE `file` = '%s' ",
dbesc($file),
);
return $r;
}
/**
* @brief Inserts a hook into a page request.