Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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`
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
41 changes: 38 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.
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

The synopsis now marks --dbname/--dbuser as optional, but they’re still required for non-SQLite installs (enforced later in create()). To avoid misleading wp help config create output, consider updating the option descriptions to explicitly state “Required unless SQLite integration drop-in is detected.”

Copilot uses AI. Check for mistakes.
*
* [--dbpass=<dbpass>]
Expand Down Expand Up @@ -219,6 +219,22 @@ public function create( $_, $assoc_args ) {
'ssl' => false,
];
$assoc_args = array_merge( $defaults, $assoc_args );

$is_sqlite = self::is_sqlite_integration_active();

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

if ( empty( $assoc_args['dbprefix'] ) ) {
WP_CLI::error( '--dbprefix cannot be empty' );
}
Expand All @@ -228,7 +244,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 +1496,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 );
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