Many plugin and theme authors don’t take full advantage of some really helpful debugging tools in WordPress. Here’s a quick run-down of five cool tools for debugging:
define( 'WP_DEBUG', true );
It’s no secret I love this constant and everything it stands for. Define it in wp-config.php and you’ll start seeing PHP notices and also WordPress-generated debug messages, particularly deprecated function usage.
(Added June 27, 2010: You may wish to check out my Log Deprecated Notices plugin.)
There’s also WP_DEBUG_DISPLAY and WP_DEBUG_LOG, which enable you to log these to a wp-content/debug.log file. I’ve added some inline documentation that describes these both well. Some use WP_DEBUG on a live site and just make sure it gets logged.
WP_DEBUG will often reveal potential problems in your code, such as unchecked indexes (empty() and isset() are your friend) and undefined variables. (You may even find problems in WordPress itself, in which case you should file a bug report.)
define( 'SCRIPT_DEBUG', true );
The WordPress database class can be told to store query history:
define( 'SAVEQUERIES', true );
When this is defined,
$wpdb->queries stores an array of queries that were executed, along with the time it takes to execute them.
The database class has additional error and debugging tools, which are documented on the Codex (though when in doubt, check the source).
4. The ‘all’ and ‘shutdown’ hooks
There’s an ‘all’ hook that fires for all actions and filters. Example usage:
add_action( 'all', create_function( '', 'var_dump( current_filter() );' ) );
You’ll be surprised how many hooks get executed on every page load. Good for troubleshooting and identifying the right hook.
There’s also a ‘shutdown’ hook you can use in combination with, say, SAVEQUERIES, and write the query information to the database. It’s the last hook to run.
5. Core Control
There are plenty of great developer-oriented plugins out there, but I’m not sure any list would be complete without Dion Hulse’s Core Control plugin. It is comprised of five modules covering Filesystem methods, HTTP methods, HTTP logging, Cron tasks, and upgrades. A must-have.
This list is by no means exhaustive, just some quick hits to get you started. What tools do you use?