Skip to content

Commit 33c9b39

Browse files
committed
Enable overriding Query Monitor's "wp-content/db.php" file
1 parent 0cb3bc7 commit 33c9b39

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

activate.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,28 @@ function sqlite_plugin_copy_db_file() {
8282

8383
$destination = WP_CONTENT_DIR . '/db.php';
8484

85+
/*
86+
* When an existing "db.php" drop-in is detected, let's check if it's a known
87+
* plugin that we can continue supporting even when we override the drop-in.
88+
*/
89+
$override_db_dropin = false;
90+
if ( file_exists( $destination ) ) {
91+
// Check for the Query Monitor plugin.
92+
// When "QM_DB" exists, it must have been loaded via the "db.php" file.
93+
if ( class_exists( 'QM_DB', false ) ) {
94+
$override_db_dropin = true;
95+
}
96+
97+
if ( $override_db_dropin ) {
98+
require_once ABSPATH . '/wp-admin/includes/file.php';
99+
global $wp_filesystem;
100+
if ( ! $wp_filesystem ) {
101+
WP_Filesystem();
102+
}
103+
$wp_filesystem->delete( $destination );
104+
}
105+
}
106+
85107
// Place database drop-in if not present yet, except in case there is
86108
// another database drop-in present already.
87109
if ( ! defined( 'SQLITE_DB_DROPIN_VERSION' ) && ! file_exists( $destination ) ) {

admin-page.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ function sqlite_add_admin_menu() {
2626
* The admin page contents.
2727
*/
2828
function sqlite_integration_admin_screen() {
29+
$db_dropin_path = WP_CONTENT_DIR . '/db.php';
30+
31+
/*
32+
* When an existing "db.php" drop-in is detected, let's check if it's a known
33+
* plugin that we can continue supporting even when we override the drop-in.
34+
*/
35+
$override_db_dropin = false;
36+
if ( file_exists( $db_dropin_path ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) {
37+
// Check for the Query Monitor plugin.
38+
// When "QM_DB" exists, it must have been loaded via the "db.php" file.
39+
if ( class_exists( 'QM_DB', false ) ) {
40+
$override_db_dropin = true;
41+
}
42+
}
43+
2944
?>
3045
<div class="wrap">
3146
<h1><?php esc_html_e( 'SQLite integration.', 'sqlite-database-integration' ); ?></h1>
@@ -50,7 +65,7 @@ function sqlite_integration_admin_screen() {
5065
<div class="notice notice-error">
5166
<p><?php esc_html_e( 'We detected that the PDO SQLite driver is missing from your server (the pdo_sqlite extension is not loaded). Please make sure that SQLite is enabled in your PHP installation before proceeding.', 'sqlite-database-integration' ); ?></p>
5267
</div>
53-
<?php elseif ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) : ?>
68+
<?php elseif ( file_exists( $db_dropin_path ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) && ! $override_db_dropin ) : ?>
5469
<?php if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) : ?>
5570
<div class="notice notice-warning">
5671
<p>
@@ -103,6 +118,22 @@ function sqlite_integration_admin_screen() {
103118
</div>
104119
<h2><?php esc_html_e( 'Important note', 'sqlite-database-integration' ); ?></h2>
105120
<p><?php esc_html_e( 'This plugin will switch to a separate database and install WordPress in it. You will need to reconfigure your site, and start with a fresh site. Disabling the plugin you will get back to your previous MySQL database, with all your previous data intact.', 'sqlite-database-integration' ); ?></p>
121+
122+
<?php if ( $override_db_dropin ) : ?>
123+
<p>
124+
<strong>NOTE:</strong>
125+
<?php
126+
printf(
127+
/* translators: %s: db.php drop-in path */
128+
esc_html__( 'We’ve detected an existing database drop-in file at %s, created by the Query Monitor plugin.', 'sqlite-database-integration' ),
129+
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
130+
);
131+
?>
132+
<?php esc_html_e( 'To enable SQLite support, this file will need to be replaced.', 'sqlite-database-integration' ); ?>
133+
<?php esc_html_e( 'The Query Monitor plugin will continue to function correctly after the change. You can safely proceed with the installation.', 'sqlite-database-integration' ); ?>
134+
</p>
135+
<?php endif; ?>
136+
106137
<p><?php esc_html_e( 'By clicking the button below, you will be redirected to the WordPress installation screen to setup your new database', 'sqlite-database-integration' ); ?></p>
107138

108139
<a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=sqlite-integration&confirm-install' ), 'sqlite-install' ) ); ?>"><?php esc_html_e( 'Install SQLite database', 'sqlite-database-integration' ); ?></a>

0 commit comments

Comments
 (0)