Created
June 7, 2013 18:16
-
-
Save mikevanwinkle/5731256 to your computer and use it in GitHub Desktop.
WPE Debug DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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