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.

I'd like a lightweight way to figure out what is invoking a certain action in an effort to provide logic for certain scenarios where I can't help to avoid a function invocation (for example, a new comment firing edit_post). Is there a way to figure out which action/filter invoked a function?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Sure, just use current_filter().

share|improve this answer
    
That tells me the current action/filter, which is the only information I know of. I'm trying to figure out where that action was invoked. For example, edit_post is called in both wp-includes/comment.php and wp-includes/post.php and I'd like to be able to tell the difference. –  editor Aug 3 '11 at 15:54
    
In that case, you have to dig through the stacktrace returned by debug_backtrace(). Or hook your callback from a second callback that itself is hooked into an earlier action that's specific to wp-includes/comment.php or wp-includes/post.php. –  scribu Aug 3 '11 at 15:55
3  
Or you could use did_action(), passing an action that only fires on wp-includes/comment.php, for example. –  scribu Aug 3 '11 at 16:01
    
Good ideas, thanks scribu –  editor Aug 3 '11 at 17:36
add comment

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.