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.
[…] This post was mentioned on Twitter by Planet WordPress, Amor. Amor said: WordPress: Oh Those Actions and Filters! http://bit.ly/bcXMe6 – via @kovshenin […]
Looks pretty smart. Didn't there actually existed an "all" action.
Hooks are trickier than they look. There are plenty of edge cases with static methods or whole object stuffed in them.
By the way actions and filters are identical internally. Difference in outer layer is semantic for ease of use by humans (distinguishing if return is expected), inside it is handled by same code.
And, if you don't mind, shameless plug of my debug functions for WP hooks :)
http://www.rarst.net/script/debug-wordpress-hooks…
Comments and suggestions for that code are welcome, small details that need fixes or polish pop out all the time. :(