Skip to content

Instantly share code, notes, and snippets.

@rileyelliott
Created June 11, 2019 15:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rileyelliott/e314bb00b8dcf2e9181dd069bf335278 to your computer and use it in GitHub Desktop.
Save rileyelliott/e314bb00b8dcf2e9181dd069bf335278 to your computer and use it in GitHub Desktop.
Wordpress DECHO
DEBUG_URL=whatever.test
div.DECHO {
background: #F6F2CD;
border: {
bottom: 2px solid red;
top: 2px solid red;
}
font: {
family: Courier;
size: 12px;
}
h3 {
font: {
size: 14px;
}
max-width: 1300px;
margin: 0 auto;
text-transform: none;
}
pre {
margin: 0 auto;
overflow: auto;
max-width: 1300px;
width: 100%;
}
}
<?php
function DECHO($var) {
$current_user = wp_get_current_user();
if (user_can($current_user, 'administrator') || $_SERVER['SERVER_NAME'] == getenv('DEBUG_URL')) {
$bt = debug_backtrace();
$caller = array_shift($bt);
add_action('wp_footer', function () use ($var, $caller) {
echo '<div class="DECHO"><h3>Line: ' . $caller['line'] . '<br />File: ' . $caller['file'] . '</h3><pre>' . print_r($var,
true) . '</pre></div>';
});
}
}
function ADECHO($var) {
$current_user = wp_get_current_user();
if (user_can($current_user, 'administrator')) {
$bt = debug_backtrace();
$caller = array_shift($bt);
add_action('admin_footer', function () use ($var, $caller) {
echo '<div style="margin-left: 170px;" class="DECHO"><h3>Line: ' . $caller['line'] . '<br />File: ' . $caller['file'] . '</h3><pre>' . print_r($var,
true) . '</pre></div>';
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment