Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Last active June 3, 2020 01:29
Show Gist options
  • Save franz-josef-kaiser/1004606 to your computer and use it in GitHub Desktop.
Save franz-josef-kaiser/1004606 to your computer and use it in GitHub Desktop.
Wordpress Debug Meta Box
<?php
/**
* Debugging
*
* @example: add_filter( 'debug', create_function( '$a', 'return $handle;' ) );
*
* @param unknown_type $input
* @param unknown_type $print_r_dump
* @param unknown_type $print
* @return (mixed) $output
*/
function oxo_debug_cb( $input, $print_r_dump = 'print', $print = true )
{
$input = apply_filters( 'debug', $input );
if ( $print_r_dump = 'print' )
{
$dump = htmlspecialchars( var_export( $input, true ) );
}
else
{
ob_start();
var_dump( $input );
$dump = ob_get_clean();
}
$output = '<pre class="debug">'.$dump.'</pre></div></div></div>';
if ( $print === false )
return $output;
return print $output;
}
/**
* Adds the debug meta box to a post screen
* @return void
*/
function add_debug_box()
{
add_meta_box( 'debug', __('Debug'), 'oxo_debug_cb', 'post', 'normal', 'low' );
}
add_action( 'admin_init', 'add_debug_box', 0 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment