[wp-hackers] hook availability
Andy Skelton
skeltoac at gmail.com
Mon Jan 9 04:40:34 GMT 2006
On 1/8/06, David House <dmhouse at gmail.com> wrote:
> On 08/01/06, Amit Gupta <wp at igeek.info> wrote:
> > is there a way by which a plugin can check whether a hook is available or
> > not?
>
> http://trac.wordpress.org/ticket/1579
>
> I'd like to see this committed, although it's probably not up to date.
> Mark Jaquith, this is your baby, can this be updated to 2.0?
I would advise against committing this patch as-is. There are already
some hooks that only exist if the theme author was keen enough to use
them, such as wp-head and wp-footer. We saw a significant fraction of
themes missing these hooks since 1.5 and we'll see more.
There is also the remote possibility that another plugin purposefully
interferes with any given hook by removing all actions/filters from
it, rendering that hook useless. Remote, but not inconceivable.
It is unfortunate that hooks are not centrally registered. Your most
robust option is to work with Robert's scheme, like so:
add_action('some_hook', 'test_some_hook');
function test_some_hook() {
$hooks = get_setting('hooks_test');
$hooks[] = 'some_hook';
update_option('hooks_test');
}
add_action('some_filter', 'test_some_filter');
function test_some_filter($input) {
// See above
return $input;
}
Just don't do this on every page load or you'll run up the query count
needlessly!
Andy
More information about the wp-hackers
mailing list