Skip to content

Commit 4be66e8

Browse files
committed
Add a hotfix for missing DB_NAME constant
1 parent 767d246 commit 4be66e8

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

wp-includes/sqlite/db.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@
5050
require_once __DIR__ . '/class-wp-sqlite-db.php';
5151
require_once __DIR__ . '/install-functions.php';
5252

53+
/*
54+
* Fallback to a default database name if "DB_NAME" is not defined.
55+
*
56+
* This can happen when importing a WordPress backup that doesn't include the
57+
* "DB_NAME" constant definition.
58+
*
59+
* TODO: Remove this once addressed in WordPress Playground, which is a more
60+
* appropriate place to fix this. In the SQLite integration plugin, it is
61+
* better to require the "DB_NAME" constant to be defined to avoid issues
62+
* such as storing an incorrect database name in the information schema.
63+
*/
64+
$db_name = defined( 'DB_NAME' ) ? DB_NAME : 'wordpress';
65+
5366
/*
5467
* Debug: Cross-check with MySQL.
5568
* This is for debugging purpose only and requires files
@@ -59,7 +72,9 @@
5972
$crosscheck_tests_file_path = dirname( __DIR__, 2 ) . '/tests/class-wp-sqlite-crosscheck-db.php';
6073
if ( defined( 'SQLITE_DEBUG_CROSSCHECK' ) && SQLITE_DEBUG_CROSSCHECK && file_exists( $crosscheck_tests_file_path ) ) {
6174
require_once $crosscheck_tests_file_path;
62-
$GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB( DB_NAME );
75+
$GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB( $db_name );
6376
} else {
64-
$GLOBALS['wpdb'] = new WP_SQLite_DB( DB_NAME );
77+
$GLOBALS['wpdb'] = new WP_SQLite_DB( $db_name );
6578
}
79+
80+
unset( $db_name );

0 commit comments

Comments
 (0)