Debug WordPress in simple way |
Debug WordPress in simple way
>> WP_DEBUG
>>SCRIPT_DEBUG
>>SAVEQUERIES
>>The " all " and " shutdown "hooks
>>Core Control
1. WP_DEBUG
>> 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.
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.)
2. SCRIPT_DEBUG
In the admin, WordPress minimizes and concatenates JavaScript and CSS. But WP also comes with the “development” scripts, in the form of dev.js and dev.css. To use these instead:
>> define( 'SCRIPT_DEBUG', true );
3. SAVEQUERIES
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.
source: andrewnacin |
|
| Tag : Debug WordPress,wordpress support |
|
 |
|
|