[wp-hackers] Getting the name of the hook triggered
John Ellmore
jnellmore at gmail.com
Sun Mar 25 23:49:46 UTC 2012
Hi all,
I'm writing a plugin for WordPress that enables notifications to be sent to
a user upon on any given hook being triggered. The user will be able to
specify which hooks they'd like to be alerted to. An example would be
alerting a user when a post is published; the user would setup a
notification (through an admin panel) for the "publish_post" hook and would
receive a notification (via email, SMS, carrier pigeon, etc.) when that
hook was triggered.
In addition, each hook will be treated slightly differently; a "save_post"
notification, for example, might also include information about that post.
So the plugin will have code that is specific to each hook.
The way I'd like to do it is as follows:
<?php
$listen_for = get_hooks_list(); // get the hooks to listen from database or
option
foreach ($listen_for as $hook) {
add_action($hook, 'my_plugin_handle_hook');
}
function my_plugin_handle_hook() {
// figure out which hook was triggered, execute the appropriate code
if ($hookname == 'save_post') do_something_here();
else if ($hookname == 'publish_post') do_something_else();
}
?>
Unfortunately, as far as I can tell, there's no way to determine the name
of the hook that triggered an event. I'd really like to structure my plugin
in a way that's extensible and allows other plugins to add custom
functionality via hooks, but this issue is preventing me doing so.
So, my question is: Is there any way to figure out the name of the hook
that is triggering the callback? If not, any suggestions on how to
structure my plugin in an extensible manner?
Thanks!
John
More information about the wp-hackers
mailing list