Hooks now have a 'priority' value, default to 0.
The hooks are retrieved from the database by descending priority. As a result they are run in the same order.
This commit is contained in:
parent
96c47a6577
commit
d6c600ce11
1 changed files with 6 additions and 4 deletions
|
@ -111,7 +111,7 @@ function reload_plugins() {
|
||||||
|
|
||||||
|
|
||||||
if(! function_exists('register_hook')) {
|
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",
|
$r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
|
||||||
dbesc($hook),
|
dbesc($hook),
|
||||||
|
@ -121,10 +121,11 @@ function register_hook($hook,$file,$function) {
|
||||||
if(count($r))
|
if(count($r))
|
||||||
return true;
|
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($hook),
|
||||||
dbesc($file),
|
dbesc($file),
|
||||||
dbesc($function)
|
dbesc($function),
|
||||||
|
dbesc($priority)
|
||||||
);
|
);
|
||||||
return $r;
|
return $r;
|
||||||
}}
|
}}
|
||||||
|
@ -145,7 +146,7 @@ if(! function_exists('load_hooks')) {
|
||||||
function load_hooks() {
|
function load_hooks() {
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
$a->hooks = array();
|
$a->hooks = array();
|
||||||
$r = q("SELECT * FROM `hook` WHERE 1");
|
$r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC");
|
||||||
if(count($r)) {
|
if(count($r)) {
|
||||||
foreach($r as $rr) {
|
foreach($r as $rr) {
|
||||||
if(! array_key_exists($rr['hook'],$a->hooks))
|
if(! array_key_exists($rr['hook'],$a->hooks))
|
||||||
|
@ -161,6 +162,7 @@ function call_hooks($name, &$data = null) {
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
|
|
||||||
if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
|
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) {
|
foreach($a->hooks[$name] as $hook) {
|
||||||
@include_once($hook[0]);
|
@include_once($hook[0]);
|
||||||
if(function_exists($hook[1])) {
|
if(function_exists($hook[1])) {
|
||||||
|
|
Loading…
Reference in a new issue