Debug & Caching
…simply doesn’t work. If you’d load a page (on a cached request) and doing all those funky things like checking if you’re logged in, if you’re using an administrator-role account, etc. than all this would be bypassed by the caching plugin. The cache gets applied to the resulting HTML page, not the PHP code generating it.
(…) would a cache plugin like W3 Total Cache help?
NO, simply said. Extended explanation: It would make it much more worse. You’d cache all data (if the cache gets generated based on your request) and everyone would get the debug dump served. So do yourself a favor and
ALWAYS deactivate caching if you’re debugging on a live server.
How to debug on a live site.
In one of my debug plugins, that I use on live servers, I got the following check on top to abort if none of the criteria is met.
// Nothing to see here
if (
! is_admin()
AND isset( $_GET['debug'] )
AND 'true' === $_GET['debug']
AND current_user_can( 'manage_options' )
AND ( defined( 'DOING_AJAX' ) AND DOING_AJAX )
AND ( defined( 'DOING_CRON' ) AND DOING_CRON )
)
return;
So debug output will only be visible if you have the query arg "?debug=true"
or "/debug/true"
(depending on permalink settings) appended.
You can also write into a log file (but that shouldn’t be done on heavy traffic sites). Here are the lines for a wp-config.php
file, that will suppress errors, but write them to your log file.
# DEBUG
define( 'WP_DEBUG', true );
// file: ~/WP_CONTENT_DIR/debug.log
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );