Skip to content

Commit d44ee3c

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

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

wp-includes/sqlite/db.php

+18-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@
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+
// phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText
65+
$db_name = defined( 'DB_NAME' ) ? DB_NAME : 'wordpress';
66+
5367
/*
5468
* Debug: Cross-check with MySQL.
5569
* This is for debugging purpose only and requires files
@@ -59,7 +73,9 @@
5973
$crosscheck_tests_file_path = dirname( __DIR__, 2 ) . '/tests/class-wp-sqlite-crosscheck-db.php';
6074
if ( defined( 'SQLITE_DEBUG_CROSSCHECK' ) && SQLITE_DEBUG_CROSSCHECK && file_exists( $crosscheck_tests_file_path ) ) {
6175
require_once $crosscheck_tests_file_path;
62-
$GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB( DB_NAME );
76+
$GLOBALS['wpdb'] = new WP_SQLite_Crosscheck_DB( $db_name );
6377
} else {
64-
$GLOBALS['wpdb'] = new WP_SQLite_DB( DB_NAME );
78+
$GLOBALS['wpdb'] = new WP_SQLite_DB( $db_name );
6579
}
80+
81+
unset( $db_name );

0 commit comments

Comments
 (0)