Take the 2-minute tour ×

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

3 Answers 3

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


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


