Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Lots of hooks:

add_action('thesis_hook_after_comment', 'pj_time');
add_action('thesis_hook_after_comments', 'pj_time');
add_action('thesis_hook_after_comment_box', 'pj_time');
add_action('thesis_hook_after_comment_meta', 'pj_time');
add_action('thesis_hook_after_content', 'pj_time');
add_action('thesis_hook_after_content_area', 'pj_time');
add_action('thesis_hook_after_content_box', 'pj_time');
add_action('thesis_hook_after_footer', 'pj_time');
add_action('thesis_hook_after_header', 'pj_time');
add_action('thesis_hook_after_headline', 'pj_time');
// etc.

How can function pj_time() know which hook called it? Is there a global variable or something that tells me which hook we're on? So pj_time() could output something like: "The hook (name of hook here) rocks."

I don't know the order the hooks are called either, they're just in alphabetical order here. Otherwise I could use a counter to figure how many hooks we've done so far and determine the name of the hook that way.

So I want to know if it's possible to get the name of the hook. Thanks.

share|improve this question
    
Here's the source of what I was attempting to do pjbrunet.com/… –  PJ Brunet Oct 28 '13 at 17:47

1 Answer 1

function pj_time () {
    echo current_filter();
}

Easier than I thought ;-)

http://codex.wordpress.org/Function_Reference/current_filter

share|improve this answer
    
+1 Another cool thing is that you can use that to remove functions and methods as well: remove_function( current_filter(), __FUNCTION__ ); and remove_function( current_filter(), array( $this, __FUNCTION__ ) );. Only problem is that you'd still have to extract the priority if it's not 10. –  kaiser Oct 27 '13 at 3:58
    
Sure. We use it in our WCM Language switcher plugin. –  kaiser Oct 28 '13 at 17:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.