title( __( 'Queries', 'debug-bar' ) );
}
function prerender() {
$this->set_visible( defined( 'SAVEQUERIES' ) && SAVEQUERIES || ! empty( $GLOBALS['EZSQL_ERROR'] ) );
}
function debug_bar_classes( $classes ) {
if ( ! empty( $GLOBALS['EZSQL_ERROR'] ) ) {
$classes[] = 'debug-bar-php-warning-summary';
}
return $classes;
}
function render() {
global $wpdb, $EZSQL_ERROR;
$out = '';
$total_time = 0;
if ( ! empty( $wpdb->queries ) ) {
$show_many = isset( $_GET['debug_queries'] );
if ( $wpdb->num_queries > 500 && ! $show_many ) {
/* translators: %s = a url. */
$out .= "
" . sprintf( __( 'There are too many queries to show easily! Show them anyway', 'debug-bar' ), esc_url( add_query_arg( 'debug_queries', 'true' ) ) ) . "
";
}
$out .= '';
$counter = 0;
foreach ( $wpdb->queries as $q ) {
list( $query, $elapsed, $debug ) = $q;
$total_time += $elapsed;
if ( ++$counter > 500 && ! $show_many ) {
continue;
}
$debug = explode( ', ', $debug );
$debug = array_diff( $debug, array( 'require_once', 'require', 'include_once', 'include' ) );
$debug = implode( ', ', $debug );
$debug = str_replace( array( 'do_action, call_user_func_array' ), array( 'do_action' ), $debug );
$debug = esc_html( $debug );
$query = nl2br( esc_html( $query ) );
/* translators: %s = duration in milliseconds. */
$time = esc_html( sprintf( __( '%s ms', 'debug-bar' ), number_format_i18n( ( $elapsed * 1000 ), 1 ) ) );
$out .= "- $query
$debug #$counter ($time)
\n";
}
$out .= '
';
} else if ( 0 === $wpdb->num_queries ) {
$out .= "" . __( 'There are no queries on this page.', 'debug-bar' ) . "
";
} else {
$out .= "" . __( 'SAVEQUERIES must be defined to show the query log.', 'debug-bar' ) . "
";
}
if ( ! empty( $EZSQL_ERROR ) ) {
$out .= '' . __( 'Database Errors', 'debug-bar' ) . '
';
$out .= '';
foreach ( $EZSQL_ERROR as $error ) {
$query = nl2br( esc_html( $error['query'] ) );
$message = esc_html( $error['error_str'] );
$out .= "- $query
$message
\n";
}
$out .= '
';
}
$heading = '';
if ( $wpdb->num_queries ) {
$heading .= '' . __( 'Total Queries:', 'debug-bar' ) . '' . number_format_i18n( $wpdb->num_queries ) . "
\n";
}
if ( $total_time ) {
$heading .= '' . __( 'Total query time:', 'debug-bar' ) . '';
/* translators: %s = duration in milliseconds. */
$heading .= sprintf( __( '%s ms', 'debug-bar' ), number_format_i18n( ( $total_time * 1000 ), 1 ) ) . "
\n";
}
if ( ! empty( $EZSQL_ERROR ) ) {
$heading .= '' . __( 'Total DB Errors:', 'debug-bar' ) . '' . number_format_i18n( count( $EZSQL_ERROR ) ) . "
\n";
}
echo $heading . $out;
}
}