Skip to content

Instantly share code, notes, and snippets.

@smartdeal
Last active May 8, 2018 15:53
Show Gist options
  • Save smartdeal/8fee0f69fe0fe6e4eb17a1373e57eca7 to your computer and use it in GitHub Desktop.
Save smartdeal/8fee0f69fe0fe6e4eb17a1373e57eca7 to your computer and use it in GitHub Desktop.
[Wordpress debug function] #Wordpress #WP_Debug
function (f_debug) {
if (is_admin()) {
define('WP_DEBUG', true )
} else {
define('WP_DEBUG', false )
}
}
add_action(init,f_debug);
/**
* Simple debug trace to wp-content/debug.log
*
* @usage _log( $var );
*/
if ( ! function_exists( '_log' ) ) {
function _log( $log ) {
if ( true == WP_DEBUG ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
} else {
ob_start();
echo '[' . date('d-M-Y h:i:s T') . '] ';
if ( is_array( $log ) || is_object( $log ) ) {
print_r( $log );
} else {
echo( $log );
}
echo "\r\n";
file_put_contents( ABSPATH . 'wp-content/debug.log', ob_get_contents(), FILE_APPEND );
ob_end_clean();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment