MyBB Hacks

Full Version: Plugin Hooks for a PHP application
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I can understand that fine - you use it as an aray kinda thing, and make each value a function. I rarely use foreach, but I have used it before and understand it.

Sessions and regexp are all I have trouble with. I think my main problem with this was I asked about 5 coders on MSN, plus hre and on another forum, and each person told me different ways to do things, so I got confused.

Anyway, thanks a tonne - and for $var() - never knew that was possible.

BP
It doesn't really matter how you call the function.  $var() is the easiest, but call_* whatever works, as well as eval().
You get an error when the hook has not been added, I fixed this with:

PHP Code:
<?php
class plugins{
function add_hook($hook, $function)
{
 global $hooks;
 $hooks[$hook][] = $function;
}

function run_hooks($hook)
{
	global $hooks;
if(!is_array($hooks[$hook])){}
else{
foreach($hooks[$hook] as $function) 
{
$function();
}
}
}
}
?>

I don't think it produces an error?  Thought it would produce a "Notice".

If you didn't change the error reporting level, then yes, you'd have to add that check.
Well, it produces a "Warning", yeah. Either way, that way works, so I;m happy Tongue
Pages: 1 2
Reference URL's