Last active
January 1, 2016 09:39
-
-
Save TobiasBg/8126598 to your computer and use it in GitHub Desktop.
Some small WordPress debug helpers
This file contains 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
<?php | |
/** | |
* Some small WordPress debug helpers | |
*/ | |
/** | |
* Utitily functions for dumping variables | |
*/ | |
function dump( $var, $name = '' ) { | |
echo '<pre>'; | |
if ( '' !== $name ) { | |
echo $name . ': '; | |
} | |
var_export( $var ); | |
echo '</pre>'; | |
} | |
function dump_js( $data ) { | |
$output = '<script>'; | |
$output .= 'console.info( "Debug in Console:" );'; | |
$output .= 'console.log(' . json_encode( $data ) . ');'; | |
$output .= '</script>'; | |
echo $output; | |
} | |
/** | |
* Emulate `WP_DEBUG` and `WP_DEBUG_LOG` (for the PHP error log in `/wp-content/debug.log`) | |
*/ | |
error_reporting( E_ALL ); // equals WP_DEBUG true | |
// ini_set( 'display_errors', 1 ); // equals WP_DISPLAY_ERRORS true | |
ini_set( 'display_errors', 0 ); // equals WP_DISPLAY_ERRORS false | |
ini_set( 'log_errors', 1 ); // equals WP_LOG_ERRORS true | |
ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); // moves error log file to WP_CONTENT_DIR | |
unlink( WP_CONTENT_DIR . '/debug.log' ); // Delete the error log, to have fresh/empty file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment