Skip to content

Instantly share code, notes, and snippets.

@pryley
Last active Apr 11, 2016
Embed
What would you like to do?
<?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