$row The row data. * @param array $cols The column names. * @return void */ protected function output_query_row( array $row, array $cols ) { // Capture the query row HTML. ob_start(); parent::output_query_row( $row, $cols ); $data = ob_get_length() > 0 ? ob_get_clean() : ''; // Get the corresponding SQLite queries. global $wpdb; static $query_index = 0; $sqlite_queries = $wpdb->queries[ $query_index ]['sqlite_queries'] ?? array(); $sqlite_query_count = count( $sqlite_queries ); $query_index += 1; // Build the SQLite info HTML. $sqlite_info = sprintf( '
Executed %d SQLite %s:
', $sqlite_query_count, 1 === $sqlite_query_count ? 'Query' : 'Queries' ); $sqlite_info .= '
    '; foreach ( $sqlite_queries as $query ) { $sqlite_info .= '
  1. '; $sqlite_info .= '' . str_replace( '
    ', '', self::format_sql( $query['sql'] ) ) . '
    '; $sqlite_info .= '
  2. '; } $sqlite_info .= '
'; // Inject toggle button and SQLite info into the query row HTML. $toggle_button = ''; $toggle_content = sprintf( '', $sqlite_info ); $data = str_replace( 'qm-row-sql', 'qm-row-sql qm-has-toggle', $data ); $data = preg_replace( '/()(.*?)(<\/td>)/s', implode( array( '$1', str_replace( '$', '\\$', $toggle_button ), '$2', str_replace( '$', '\\$', $toggle_content ), '$3', ) ), $data ); echo $data; } } // Remove the default Query Monitor class and replace it with the custom one. remove_filter( 'qm/outputter/html', 'register_qm_output_html_db_queries', 20 ); /** * Register the custom HTML output class. * * @param array $output * @param QM_Collectors $collectors * @return array */ function register_sqlite_qm_output_html_db_queries( array $output, $collectors ) { $collector = QM_Collectors::get( 'db_queries' ); if ( $collector ) { $output['db_queries'] = new SQLite_QM_Output_Html_DB_Queries( $collector ); } return $output; } add_filter( 'qm/outputter/html', 'register_sqlite_qm_output_html_db_queries', 20, 2 );