Skip to content

Commit 48f1123

Browse files
committed
Add a database name fallback for early adopters of the new driver
The experimental new SQLite driver requires a database name to be set, while the old one doesn't. There are some scenarios in which the DB_NAME constant is missing in wp-config.php. To enable easier early adoption and testing before version 3.0, we're adding a default database name in case the DB_NAME constant is not set. Since the provided database name is now verified against the existing database, this should be a safe change.
1 parent 977a813 commit 48f1123

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

wp-includes/sqlite/db.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@
5555
require_once __DIR__ . '/class-wp-sqlite-db.php';
5656
require_once __DIR__ . '/install-functions.php';
5757

58+
/**
59+
* The DB_NAME constant is required by the SQLite driver.
60+
*
61+
* When DB_NAME is not defined, let's use a default value that corresponds to
62+
* the default value of the constant in "wp-config-sample.php" and in Studio.
63+
*
64+
* TODO: Remove this once the DB_NAME constant is enforced in "wp-config.php".
65+
*/
66+
if ( defined( 'DB_NAME' ) && '' !== DB_NAME ) {
67+
$db_name = DB_NAME;
68+
} else {
69+
$db_name = apply_filters( 'wp_sqlite_default_db_name', 'database_name_here' );
70+
}
71+
5872
/*
5973
* Debug: Cross-check with MySQL.
6074
* This is for debugging purpose only and requires files
@@ -64,9 +78,9 @@
6478
$crosscheck_tests_file_path = dirname( __DIR__, 2 ) . '/tests/class-wp-sqlite-crosscheck-db.php';
6579
if ( defined( 'SQLITE_DEBUG_CROSSCHECK' ) && SQLITE_DEBUG_CROSSCHECK && file_exists( $crosscheck_tests_file_path ) ) {
6680
require_once $crosscheck_tests_file_path;
67-
$GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB( DB_NAME );
81+
$GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB( $db_name );
6882
} else {
69-
$GLOBALS['wpdb'] = new WP_SQLite_DB( defined( 'DB_NAME' ) ? DB_NAME : '' );
83+
$GLOBALS['wpdb'] = new WP_SQLite_DB( $db_name );
7084

7185
// Boot the Query Monitor plugin if it is active.
7286
require_once dirname( __DIR__, 2 ) . '/integrations/query-monitor/boot.php';

0 commit comments

Comments
 (0)