Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions features/config-create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,23 @@ Feature: Create a wp-config file
Then the return code should be 0
And the subdir/wp-config.php file should exist

@require-sqlite
Scenario: Configure without --dbname and --dbuser when SQLite integration is active
Given an empty directory
And WP files
And a wp-content/db.php file:
"""
<?php
define( 'SQLITE_DB_DROPIN_VERSION', '1.0.0' );
"""

When I run `wp config create --skip-salts --skip-check`
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario includes --skip-check, so it doesn’t actually exercise the new behavior of bypassing the MySQLi connection check when SQLite is detected. To cover the new branch, run wp config create without --skip-check (while still omitting --dbname/--dbuser) and assert it succeeds.

Suggested change
When I run `wp config create --skip-salts --skip-check`
When I run `wp config create --skip-salts`

Copilot uses AI. Check for mistakes.
Then the return code should be 0
And STDOUT should contain:
"""
Generated 'wp-config.php' file.
"""

@require-mysql @require-mysql-5.7
Scenario: Configure with required SSL connection
Given an empty directory
Expand Down
37 changes: 34 additions & 3 deletions src/Config_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ private static function get_initial_locale() {
*
* ## OPTIONS
*
* --dbname=<dbname>
* [--dbname=<dbname>]
* : Set the database name.
*
* --dbuser=<dbuser>
* [--dbuser=<dbuser>]
* : Set the database user.
*
* [--dbpass=<dbpass>]
Expand Down Expand Up @@ -219,6 +219,18 @@ public function create( $_, $assoc_args ) {
'ssl' => false,
];
$assoc_args = array_merge( $defaults, $assoc_args );

$is_sqlite = self::is_sqlite_integration_active();

if ( ! $is_sqlite ) {
if ( empty( $assoc_args['dbname'] ) ) {
WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbname parameter (Set the database name.)' );
}
if ( empty( $assoc_args['dbuser'] ) ) {
WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbuser parameter (Set the database user.)' );
}
Comment on lines +226 to +231
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current validation for missing --dbname/--dbuser changes behavior compared to WP-CLI’s synopsis validation: (1) using empty() will incorrectly reject values like --dbuser=0, and (2) calling WP_CLI::error() per-field exits on the first missing parameter so you never report both missing options together. Consider collecting missing parameters into an array and emitting a single Parameter errors: message, and check for presence/empty-string rather than empty().

Suggested change
if ( empty( $assoc_args['dbname'] ) ) {
WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbname parameter (Set the database name.)' );
}
if ( empty( $assoc_args['dbuser'] ) ) {
WP_CLI::error( 'Parameter errors:' . PHP_EOL . 'missing --dbuser parameter (Set the database user.)' );
}
$param_errors = [];
if ( ! array_key_exists( 'dbname', $assoc_args ) || $assoc_args['dbname'] === '' ) {
$param_errors[] = 'missing --dbname parameter (Set the database name.)';
}
if ( ! array_key_exists( 'dbuser', $assoc_args ) || $assoc_args['dbuser'] === '' ) {
$param_errors[] = 'missing --dbuser parameter (Set the database user.)';
}
if ( ! empty( $param_errors ) ) {
WP_CLI::error( 'Parameter errors:' . PHP_EOL . implode( PHP_EOL, $param_errors ) );
}

Copilot uses AI. Check for mistakes.
}

if ( empty( $assoc_args['dbprefix'] ) ) {
WP_CLI::error( '--dbprefix cannot be empty' );
}
Expand All @@ -228,7 +240,7 @@ public function create( $_, $assoc_args ) {

// Check DB connection. To make command more portable, we are not using MySQL CLI and using
// mysqli directly instead, as $wpdb is not accessible in this context.
if ( ! Utils\get_flag_value( $assoc_args, 'skip-check' ) ) {
if ( ! $is_sqlite && ! Utils\get_flag_value( $assoc_args, 'skip-check' ) ) {
// phpcs:disable WordPress.DB.RestrictedFunctions
$mysql = mysqli_init();

Expand Down Expand Up @@ -1480,6 +1492,25 @@ private function print_dotenv( array $value ) {
WP_CLI::line( "{$name}={$variable_value}" );
}

/**
* Check if the SQLite integration drop-in is active.
*
* @return bool True if SQLite integration is detected, false otherwise.
*/
private static function is_sqlite_integration_active() {
$wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content';
$db_dropin_path = $wp_content_dir . '/db.php';

if ( file_exists( $db_dropin_path ) ) {
$db_dropin_contents = file_get_contents( $db_dropin_path, false, null, 0, 8192 );
Comment on lines +1504 to +1505
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file_get_contents() can emit PHP warnings (e.g., if wp-content/db.php exists but is not readable), which would leak noise into CLI output. Consider adding an is_readable() guard and/or suppressing warnings and handling failures explicitly to keep output clean.

Suggested change
if ( file_exists( $db_dropin_path ) ) {
$db_dropin_contents = file_get_contents( $db_dropin_path, false, null, 0, 8192 );
if ( is_readable( $db_dropin_path ) ) {
// Suppress potential warnings and handle failure explicitly to keep CLI output clean.
$db_dropin_contents = @file_get_contents( $db_dropin_path, false, null, 0, 8192 );

Copilot uses AI. Check for mistakes.
if ( false !== $db_dropin_contents && false !== strpos( $db_dropin_contents, 'SQLITE_DB_DROPIN_VERSION' ) ) {
return true;
}
}

return false;
}

/**
* Escape a config value so it can be safely used within single quotes.
*
Expand Down
Loading