$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 .= '- ';
+ $sqlite_info .= '
' . str_replace( '
', '', self::format_sql( $query['sql'] ) ) . '
';
+ $sqlite_info .= ' ';
+ }
+ $sqlite_info .= '
';
+
+ // Inject toggle button and SQLite info into the query row HTML.
+ $toggle_button = '';
+ $toggle_content = sprintf( '%s
', $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 );
diff --git a/load.php b/load.php
index 29f1dcef..d94bd95b 100644
--- a/load.php
+++ b/load.php
@@ -26,3 +26,8 @@
require_once __DIR__ . '/deactivate.php';
require_once __DIR__ . '/admin-notices.php';
require_once __DIR__ . '/health-check.php';
+
+// Query Monitor integration:
+if ( defined( 'SQLITE_QUERY_MONITOR_LOADED' ) && SQLITE_QUERY_MONITOR_LOADED ) {
+ require_once __DIR__ . '/integrations/query-monitor/plugin.php';
+}
diff --git a/wp-includes/sqlite/class-wp-sqlite-db.php b/wp-includes/sqlite/class-wp-sqlite-db.php
index 7ce46598..d8eca0bb 100644
--- a/wp-includes/sqlite/class-wp-sqlite-db.php
+++ b/wp-includes/sqlite/class-wp-sqlite-db.php
@@ -508,6 +508,13 @@ public function query( $query ) {
} else {
$this->queries[ $i ]['result'] = (int) $return_val;
}
+
+ // Add SQLite query data.
+ if ( $this->dbh instanceof WP_SQLite_Driver ) {
+ $this->queries[ $i ]['sqlite_queries'] = $this->dbh->get_last_sqlite_queries();
+ } else {
+ $this->queries[ $i ]['sqlite_queries'] = $this->dbh->executed_sqlite_queries;
+ }
}
return $return_val;
}
From 5c2265e3343601dc3da01e12180396f540d3a9cc Mon Sep 17 00:00:00 2001
From: Jan Jakes
Date: Wed, 9 Jul 2025 14:12:25 +0200
Subject: [PATCH 5/5] Support the Query Monitor integration in Playground
---
integrations/query-monitor/boot.php | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/integrations/query-monitor/boot.php b/integrations/query-monitor/boot.php
index 35ec433f..928c3413 100644
--- a/integrations/query-monitor/boot.php
+++ b/integrations/query-monitor/boot.php
@@ -12,6 +12,15 @@
* See: https://github.com/johnbillion/query-monitor/blob/develop/wp-content/db.php
*/
+/*
+ * In Playground, the SQLite plugin is preloaded without using the "db.php" file.
+ * To prevent Query Monitor from injecting its own "db.php" file, we need to set
+ * the "QM_DB_SYMLINK" constant to "false".
+ */
+if ( ! defined( 'QM_DB_SYMLINK' ) ) {
+ define( 'QM_DB_SYMLINK', false );
+}
+
// 1. Check if we should load Query Monitor (as per the original "db.php" file).
if ( ! defined( 'ABSPATH' ) ) {
exit;
|