Skip to content

Instantly share code, notes, and snippets.

@pryley
Last active April 11, 2016 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pryley/fab3d0463a57670884e56f433d762efc to your computer and use it in GitHub Desktop.
Save pryley/fab3d0463a57670884e56f433d762efc to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: print__r()
* Description: print_r() alternative
* Version: 1.0.0
* Author: Paul Ryley
* Author URI: http://geminilabs.io
*/
/**
* CSS for print__r()
*
* @return void
*/
function print__r_print_css()
{
$wp_styles = wp_styles()->queue;
if( empty( $wp_styles ) ) {
return;
}
$inline_styles = '
.print__r {
position: relative;
max-height: 600px;
overflow-y: scroll;
background: #1d1f21;
border-radius: 3px;
padding: 10px;
margin: 12px 0;
}
.print__r pre {
display: block;
font: 12px/1.5 "Operator Mono", Consolas, monospace;
color: #b5bd68; //#c5c8c6;
text-align: left;
text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
padding: 5px;
margin: 0;
}
.print__r_group {
position: relative;
background: #1d1f21;
border-radius: 3px;
padding: 1px;
margin: 12px 0;
}
.print__r_group .print__r {
background: #282a2e;
border-radius: 2px;
padding: 0;
margin: 9px;
}
.print__r_group .print__r:not(:last-child) {
margin-bottom: 10px;
}';
wp_add_inline_style( $wp_styles[0], apply_filters( 'print__r_print_css', $inline_styles ) );
}
add_action( 'wp_enqueue_scripts', 'print__r_print_css', 99 );
/**
* print_r() alternative
*
* @param mixed $value ...
*
* @return void
*/
if( !function_exists( 'print__r' ) ) {
function print__r( $value )
{
if( !apply_filters( 'print__r', true ) ) {
return;
}
if( empty( $value ) ) {
$value = "''";
}
if( func_num_args() == 1 ) {
printf( '<div class="print__r"><pre>%s</pre></div>',
htmlspecialchars( print_r( $value, true ), ENT_QUOTES, 'UTF-8' )
);
}
else {
echo '<div class="print__r_group">';
foreach( func_get_args() as $param ) {
print__r( $param );
}
echo '</div>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment