Last active
June 3, 2020 01:29
-
-
Save franz-josef-kaiser/1004606 to your computer and use it in GitHub Desktop.
Wordpress Debug Meta Box
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 | |
/** | |
* 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