WordPress Debugging
26
March
OK, a simple one to start this thing off. If you’re writing PHP and you need to debug something and print some output to your error logs, here’s a nice custom debugging function that’s easier than the default error_log
function. Certainly makes my life a lot easier.
if(!function_exists('_error_log')){ function _error_log( $stuff ) { if( WP_DEBUG === true ){ if( is_array( $stuff ) || is_object( $stuff ) ){ error_log( print_r( $stuff, true ) ); } else { error_log( $stuff ); } } } }
Oh, and don’t forget to add the following to your wp-config.php
file to turn on debugging, and remember to make sure your server has write access to wp-content/debug.log
.
define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false); @ini_set('display_errors',0);
No comments yet.