@@ -120,11 +120,11 @@ private static function get_initial_locale() {
120120 *
121121 * ## OPTIONS
122122 *
123- * --dbname=<dbname>
124- * : Set the database name.
123+ * [ --dbname=<dbname>]
124+ * : Set the database name. Required unless the SQLite integration drop-in is detected.
125125 *
126- * --dbuser=<dbuser>
127- * : Set the database user.
126+ * [ --dbuser=<dbuser>]
127+ * : Set the database user. Required unless the SQLite integration drop-in is detected.
128128 *
129129 * [--dbpass=<dbpass>]
130130 * : Set the database user password.
@@ -219,6 +219,22 @@ public function create( $_, $assoc_args ) {
219219 'ssl ' => false ,
220220 ];
221221 $ assoc_args = array_merge ( $ defaults , $ assoc_args );
222+
223+ $ is_sqlite = self ::is_sqlite_integration_active ();
224+
225+ if ( ! $ is_sqlite ) {
226+ $ errors = [];
227+ if ( empty ( $ assoc_args ['dbname ' ] ) ) {
228+ $ errors [] = 'missing --dbname parameter (Set the database name.) ' ;
229+ }
230+ if ( empty ( $ assoc_args ['dbuser ' ] ) ) {
231+ $ errors [] = 'missing --dbuser parameter (Set the database user.) ' ;
232+ }
233+ if ( ! empty ( $ errors ) ) {
234+ WP_CLI ::error ( 'Parameter errors: ' . PHP_EOL . implode ( PHP_EOL , $ errors ) );
235+ }
236+ }
237+
222238 if ( empty ( $ assoc_args ['dbprefix ' ] ) ) {
223239 WP_CLI ::error ( '--dbprefix cannot be empty ' );
224240 }
@@ -228,7 +244,7 @@ public function create( $_, $assoc_args ) {
228244
229245 // Check DB connection. To make command more portable, we are not using MySQL CLI and using
230246 // mysqli directly instead, as $wpdb is not accessible in this context.
231- if ( ! Utils \get_flag_value ( $ assoc_args , 'skip-check ' ) ) {
247+ if ( ! $ is_sqlite && ! Utils \get_flag_value ( $ assoc_args , 'skip-check ' ) ) {
232248 // phpcs:disable WordPress.DB.RestrictedFunctions
233249 $ mysql = mysqli_init ();
234250
@@ -1480,6 +1496,30 @@ private function print_dotenv( array $value ) {
14801496 WP_CLI ::line ( "{$ name }= {$ variable_value }" );
14811497 }
14821498
1499+ /**
1500+ * Check if the SQLite integration drop-in is active.
1501+ *
1502+ * @return bool True if SQLite integration is detected, false otherwise.
1503+ */
1504+ private static function is_sqlite_integration_active () {
1505+ $ wp_content_dir = defined ( 'WP_CONTENT_DIR ' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content ' ;
1506+ $ db_dropin_path = $ wp_content_dir . '/db.php ' ;
1507+
1508+ if ( ! is_file ( $ db_dropin_path ) || ! is_readable ( $ db_dropin_path ) ) {
1509+ return false ;
1510+ }
1511+
1512+ $ db_dropin_contents = file_get_contents ( $ db_dropin_path , false , null , 0 , 8192 );
1513+ if ( false === $ db_dropin_contents ) {
1514+ return false ;
1515+ }
1516+
1517+ return 1 === preg_match (
1518+ '/\b(?:define\s*\(\s*[ \'"]SQLITE_DB_DROPIN_VERSION[ \'"]|const\s+SQLITE_DB_DROPIN_VERSION\b)/ ' ,
1519+ $ db_dropin_contents
1520+ );
1521+ }
1522+
14831523 /**
14841524 * Escape a config value so it can be safely used within single quotes.
14851525 *
0 commit comments