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?

1 Answer 1


Sure, just use current_filter().

  • 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, 2011 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, 2011 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, 2011 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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