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 ) $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 ); $query = nl2br(esc_html($query)); $out .= "
  1. $query
    $debug #{$counter} (" . number_format(sprintf('%0.1f', $elapsed * 1000), 1, '.', ',') . "ms)
  2. \n"; } $out .= '
'; } else { if ( $wpdb->num_queries == 0 ) $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 $e ) { $query = nl2br(esc_html($e['query'])); $out .= "
  1. $query
    {$e['error_str']}
  2. \n"; } $out .= '
'; } $heading = ''; if ( $wpdb->num_queries ) $heading .= '

Total Queries:' . number_format( $wpdb->num_queries ) . "

\n"; if ( $total_time ) $heading .= '

Total query time:' . number_format(sprintf('%0.1f', $total_time * 1000), 1) . " ms

\n"; if ( ! empty($EZSQL_ERROR) ) $heading .= '

Total DB Errors:' . number_format( count($EZSQL_ERROR) ) . "

\n"; $out = $heading . $out; echo $out; } }