if(! function_exists('register_hook')) {
-function register_hook($hook,$file,$function) {
+function register_hook($hook,$file,$function,$priority=0) {
$r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
dbesc($hook),
if(count($r))
return true;
- $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ",
+ $r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`) VALUES ( '%s', '%s', '%s', '%s' ) ",
dbesc($hook),
dbesc($file),
- dbesc($function)
+ dbesc($function),
+ dbesc($priority)
);
return $r;
}}
function load_hooks() {
$a = get_app();
$a->hooks = array();
- $r = q("SELECT * FROM `hook` WHERE 1");
+ $r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC");
if(count($r)) {
foreach($r as $rr) {
if(! array_key_exists($rr['hook'],$a->hooks))
$a = get_app();
if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
+ logger('call_hooks ' . print_r($a->hooks[$name],true) , LOGGER_DEBUG);
foreach($a->hooks[$name] as $hook) {
@include_once($hook[0]);
if(function_exists($hook[1])) {