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

Is there an easy way to apply a function on all action hooks?

I want to apply esc_attr() to every action hook (in a way that would work from functions.php or a plugin).

I figure I would need to filter do_action and do_action_ref_array except that those functions don't use apply_filters. Is there any way to do this?

share|improve this question
Looks like paranoia. What is underlying aim of this wish? – Alexey Sep 25 '11 at 0:01
If you're worried about a plugin that does not escape data, you should stop using the plugin. No need to use a sledge hammer on the whole operation. – Brian Fegter Sep 25 '11 at 2:31
I want to make a plugin, for which I need action hooks to be escaped. – ryanve Sep 25 '11 at 18:38
up vote 2 down vote accepted

Just to answer the title

Apply function on all action hooks?

isn't that hard, when you know where to look:

add_action( 'all', 'callback_function' );
share|improve this answer
Nice find—and it looks like it also works for filter hooks. core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/… (Ctrl+F for 'all') – ryanve Aug 10 '12 at 21:52

I want to make a plugin, for which I need action hooks to be escaped.

No, your Plugin needs to escape its own data on output (and validate/sanitize it on input).

Every add_action() and add_filter() call has an associated callback function. You need to do your escaping inside the callback.

share|improve this answer

While this might be possible technically (with messy output buffering) this makes little sense. It would likely break a lot of output and escaping functions must be used contextually - there is no sense in using esc_attr() for everything.

If this is your own plugin and you have control over code - just go with conventional development techniques like using filters for data that needs to be modified in hooks.

share|improve this answer

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.