8
Enable Error Debugging And Logging To Use On Live Sites
This is a guest post I wrote on Comluv.com that allows you to use the WP_DEBUG constants defined as true so you can debug a site that is live and actively used without letting your visitors see any error messages.
Once this code is added to your wp-config.php file, you simply pass the parameter ?debug=1 (or 2, or 3) on any URL of your site. For ex: http://example.com/?debug=1
/**
* Written by Jared Williams - http://new2wp.com
* @wp-config.php replaces WP_DEBUG constant
* Enable WP debugging for usage on a live site
* http://core.trac.wordpress.org/browser/trunk/wp-includes/load.php#L230
* Pass the '?debug=#' parameter at the end of any url on site
*
* http://example.com/?debug=1, /?debug=2, /?debug=3
*/
if ( isset($_GET['debug']) && $_GET['debug'] == '1' ) {
// enable the reporting of notices during development - E_ALL
define('WP_DEBUG', true);
} elseif ( isset($_GET['debug']) && $_GET['debug'] == '2' ) {
// must be true for WP_DEBUG_DISPLAY to work
define('WP_DEBUG', true);
// disable the display of errors
define('WP_DEBUG_DISPLAY', true);
} elseif ( isset($_GET['debug']) && $_GET['debug'] == '3' ) {
// must be true for WP_DEBUG_LOG to work
define('WP_DEBUG', true);
// log errors to debug.log in the wp-content directory
define('WP_DEBUG_LOG', true);
}






User Comments
( ADD YOURS )Andy Bailey October 30
this is really useful for finding what's causing the errors in a plugin, it can be a bit confusing trying to find an error in the myriad of other warnings and notices that are caused by other plugins. (makes me take extra care with my own plugins though!)
thanks for the guest post!
If you want to debug, try PHPed. I spent some time configuring it and I have just managed to get the remote debugging working with php and by golly it's good! being able to stop a process mid flow and inspect all the arrays and globals is something to behold! I could do it before with single scripts but now it works with my plugin files on a full multi site install. so sweet!
Andy Bailey recently posted..API update to ComLuv info panel display
Jared October 30
Yeah this is extremely useful. I used it on WPHonors in combination with the plugin Log Deprecated Notices, and it was a breeze getting things fixed, working, and problem free.
I even used it to hack and fix the plugins I have installed with were throwing tons of errors themselves, and since I can't stand broken code, or having to rely on someone else to make the needed updates for something, I went and hacked the plugins fixing the errors, and essentially updating them to work and support with WP 3.0.1. There's not a single error or message from a Notice at all through out my entire theme thanks to this.
Thanks for letting me guest post, I'm happy to anytime :)
Jared October 30
Oh, and I hear that Phpstore + XDebug are a great combination to use too
http://blogs.jetbrains.com/webide/tag/debug/
Mike Schinkel December 26
You mean PhpStorm + XDEBUG :)
Actually, I'm finding PhpStorm + Zend Debugger to be a much better combination.
Mike Schinkel December 26
Also, I might suggest that you'd want to add a test of current_user_can("edit_themes") to ensure that only people who have logged in and have the rights are about to do this otherwise it could potentially expose information you don't want hackers to see.
@Mike This is obviously not the end all cure for debugging in WordPress. It is a handy little script tho, like for example, what if you're not at your own computer, and you needed to check something. Idk. It's not the best and only thing you need for debugging of course.
And yeah, I have tried to figure out a way to add some kind of capability check so that this is only able to be done by admins of the site but, I wasn't able to find any solution to that.
Because the wp-config.php file calls the functions for loading that stuff, after this code would be run, so it wouldn't be possible to do. If you can find a way to make it work so there is some sort of admin-only setting for it let me know.
Andy Bailey December 27
I think the only way to protect this from showing to just anyone is to hardcode a password to the wp-config.php file and add the password to the url when you want debugging to show.
in wp-config.php :
$pass = 'mysecret';
// wrap the check in
if ( isset($_GET['pass']) && $_GET['pass'] == $pass ) {
// the checks for $_GET['debug']
}
then you can use
http://example.com/?debug=1&pass=mysecret
so hackers can't see your stuff (as long as you don't tell anyone the secret)
:-)
Andy Bailey recently posted..10 Webmaster Tools for Dedicated Bloggers
Jared December 27
@Andy Yeah you could do that, but you could also just change the get parameters of the script itself so that it uses ?mysecret= instead of ?debug= too, or just not tell anyone what your parameters are in the first place.
But that's still not full proof of course. I was thinking that maybe it could be done using sessions or cookies, and incorporate the wordpress logged in check, or something like that.
Trackbacks