Skip to content

Instantly share code, notes, and snippets.

@kingkool68
Last active September 5, 2018 03:09
Show Gist options
  • Save kingkool68/f3182a16f57e0242fa36a4d0620172dd to your computer and use it in GitHub Desktop.
Save kingkool68/f3182a16f57e0242fa36a4d0620172dd to your computer and use it in GitHub Desktop.
A better dumping function that preservers whitespace making things easier to read.
<?php
if ( ! function_exists( 'wp_dump' ) ) :
/**
* Dump variables preserving whitespace so they are easier to read.
*/
function wp_dump() {
$is_xdebug = false;
if ( function_exists( 'xdebug_dump_superglobals' ) ) {
$is_xdebug = true;
}
foreach ( func_get_args() as $arg ) {
// If xdebug is installed let it do it's own thing...
if ( $is_xdebug ) {
var_dump( $arg );
continue;
}
echo '<xmp>';
var_dump( $arg );
echo '</xmp>';
}
}
endif;
<?php
if ( ! function_exists( 'wp_log' ) ) :
/**
* A better error_log() function
*/
function wp_log() {
foreach ( func_get_args() as $arg ) {
if ( is_array( $arg ) || is_object( $arg ) ) {
error_log( print_r( $arg, true ) );
} else {
error_log( $arg );
}
}
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment