Last active
May 8, 2018 15:53
-
-
Save smartdeal/8fee0f69fe0fe6e4eb17a1373e57eca7 to your computer and use it in GitHub Desktop.
[Wordpress debug function] #Wordpress #WP_Debug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function (f_debug) { | |
if (is_admin()) { | |
define('WP_DEBUG', true ) | |
} else { | |
define('WP_DEBUG', false ) | |
} | |
} | |
add_action(init,f_debug); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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