WordPress: Oh Those Actions and Filters!

Hey there! I'm currently working on a CLI tool to deploy WordPress apps to DigitalOcean. Check it out! It's free and open source.

Reading Joost de Valk’s quick post about Simple WordPress Debugging with a query variable made me think for a while. Really, how often do you come across a white screen with no clue of what’s happening? Very effective indeed, and good note about the security issue, but anyways, what came into my mind is a life-saver for all WordPress themes and plugins developers.

I came accross this following snippet quite some time ago on IRC I believe, but never shared it for no specific reason. Perhaps I thought that everybody is aware of it, but looking at how more and more people struggle with debugging WordPress actions and filters, ugh. Here’s your life-saver:

add_action( 'all', function() {
    var_dump( current_filter() );
} );

This should be used in functions.php or some plugin, and at first sight you’ll notice a huge bunch of text on the output. Fire up the source view of the page you’re looking at (works for admin panels too) and look through the code. You’ll notice that all actions and filters are printed on screen whenever they’re fired.

How could that be used? It clearly shows the order of each action and filter and it clearly shows the names (which tend to be forgotten sometimes). Maybe there are a few more pros I can’t think of right now. Downsides? It doesn’t actually tell you whether it’s an action or a filter, but anyways – short, useful, could be added up to Joost’s snippet.

About the author

Konstantin Kovshenin

WordPress Core Contributor, ex-Automattician, public speaker and consultant, enjoying life in Moscow. I blog about tech, WordPress and DevOps.