Skip to content

Instantly share code, notes, and snippets.

@TobiasBg
Last active January 1, 2016 09:39
Show Gist options
  • Save TobiasBg/8126598 to your computer and use it in GitHub Desktop.
Save TobiasBg/8126598 to your computer and use it in GitHub Desktop.
Some small WordPress debug helpers
<?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