WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
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

Your Answer


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.