Skip to content

Instantly share code, notes, and snippets.

@mikevanwinkle
Created June 7, 2013 18:16
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 mikevanwinkle/5731256 to your computer and use it in GitHub Desktop.
Save mikevanwinkle/5731256 to your computer and use it in GitHub Desktop.
WPE Debug DB
<?php
/**
Plugin Name: WPE Debug Queries
Description: WPE Plugin for debuging query issues.
**/
if( isset( $_REQUEST['wpe_check_queries'] ) )
{
define("SAVEQUERIES",true);
add_action('wpe_filtered_output','wpe_shutdown_db');
function wpe_shutdown_db($html) {
global $wpdb;
$queries = "";
if( !is_array($wpdb->queries) ) return false;
$html = 'Total Queries Run: '.count($wpdb->queries);
if( isset( $_REQUEST['show_queries']) )
{
if( $wpdb->queries < 1) $html .= "no queries";
$html .= "\n\r\n\r-----ALL QUERIES-----\n\r\n\r";
ini_set('display_errors',1);
function cmp($a,$b) { if($a[1] == $b[1]) {return 0;} return ($a[1] < $b[1]) ? 1 : -1; }
uasort( $wpdb->queries, 'cmp');
foreach($wpdb->queries as $query)
{
$query[0] = str_replace('/*',"\n\r/*",$query[0]);
$html .= "[Time {$query[1]}] {$query[0]}\n\r\n\r";
}
}
return $html;
}
}?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment