Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.