Skip to content

Instantly share code, notes, and snippets.

@lucatume
Last active January 22, 2019 15:39
Show Gist options
  • Save lucatume/49985e27c5e0637fd75c0c99d29168b6 to your computer and use it in GitHub Desktop.
Save lucatume/49985e27c5e0637fd75c0c99d29168b6 to your computer and use it in GitHub Desktop.
WordPress main query vars and props debug bar panel. Download the files and put them in a folder in the WordPress installation plugins folder.
<?php
class QueryDebugBarPanel
extends Debug_Bar_Panel {
function title( $title = null ) {
return 'Query';
}
function render() {
global $wp_query;
$vars = [];
foreach ( $wp_query->query_vars as $key => $value ) {
if ( empty( $value ) ) {
continue;
}
$vars[] = sprintf( '<tr><td>%s</td><td>%s</td></tr>', $key, print_r( $value, true ) );
}
$props = [];
foreach ( get_object_vars( $wp_query ) as $key => $value ) {
if ( empty( $value ) ) {
continue;
}
$props[] = sprintf( '<tr><td>%s</td><td>%s</td></tr>', $key, print_r( $value, true ) );
}
$vars = implode( PHP_EOL, $vars );
$props = implode( PHP_EOL, $props );
include __DIR__ . '/template.php';
}
}
<?php
/*
Plugin Name: Query Debug Bar panel
Description: Because doing by hand is horrible.
*/
add_filter('debug_bar_panels', function(array $panels=[]){
include_once __DIR__ .'/Panel.php';
$panels[] = new QueryDebugBarPanel();
return $panels;
});
<style>
#query-debug table {
width: 100%;
}
#query-debug section:not(:last-of-type) {
margin-bottom: 4em;
}
#query-debug table caption{
font-size: 200%;
font-weight: bold;
margin-bottom: 1em;
}
#query-debug table th, #query-debug table td{
padding: .75em .75em .75em .75em;
border: #0a55a0 solid 1px;
}
</style>
<div id="query-debug">
<section >
<main>
<table>
<caption>Query vars</caption>
<thead>
<tr>
<th>Var</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<?php echo $vars; ?>
</tbody>
</table>
</main>
</section>
<section >
<main>
<table>
<caption>Query properties</caption>
<thead>
<tr>
<th>Property</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<?php echo $props; ?>
</tbody>
</table>
</main>
</section>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment