@@ -120,10 +120,10 @@ private static function get_initial_locale() {
120120 *
121121 * ## OPTIONS
122122 *
123- * --dbname=<dbname>
123+ * [ --dbname=<dbname>]
124124 * : Set the database name.
125125 *
126- * --dbuser=<dbuser>
126+ * [ --dbuser=<dbuser>]
127127 * : Set the database user.
128128 *
129129 * [--dbpass=<dbpass>]
@@ -219,6 +219,24 @@ 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 ( ! isset ( $ assoc_args ['dbname ' ] ) ) {
228+ $ errors [] = 'missing --dbname parameter (Set the database name.) ' ;
229+ }
230+ if ( ! isset ( $ assoc_args ['dbuser ' ] ) ) {
231+ $ errors [] = 'missing --dbuser parameter (Set the database user.) ' ;
232+ }
233+ if ( ! empty ( $ errors ) ) {
234+ WP_CLI ::error (
235+ 'Parameter errors: ' . "\n " . implode ( "\n " , $ errors )
236+ );
237+ }
238+ }
239+
222240 if ( empty ( $ assoc_args ['dbprefix ' ] ) ) {
223241 WP_CLI ::error ( '--dbprefix cannot be empty ' );
224242 }
@@ -228,7 +246,7 @@ public function create( $_, $assoc_args ) {
228246
229247 // Check DB connection. To make command more portable, we are not using MySQL CLI and using
230248 // mysqli directly instead, as $wpdb is not accessible in this context.
231- if ( ! Utils \get_flag_value ( $ assoc_args , 'skip-check ' ) ) {
249+ if ( ! $ is_sqlite && ! Utils \get_flag_value ( $ assoc_args , 'skip-check ' ) ) {
232250 // phpcs:disable WordPress.DB.RestrictedFunctions
233251 $ mysql = mysqli_init ();
234252
@@ -1506,4 +1524,22 @@ private function escape_config_value( $key, $value ) {
15061524
15071525 return $ value ;
15081526 }
1527+
1528+ /**
1529+ * Check if the SQLite integration drop-in is active.
1530+ *
1531+ * @return bool
1532+ */
1533+ private static function is_sqlite_integration_active () {
1534+ $ wp_content_dir = defined ( 'WP_CONTENT_DIR ' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content ' ;
1535+ $ db_dropin_path = $ wp_content_dir . '/db.php ' ;
1536+
1537+ if ( ! is_readable ( $ db_dropin_path ) ) {
1538+ return false ;
1539+ }
1540+
1541+ $ contents = file_get_contents ( $ db_dropin_path );
1542+
1543+ return false !== $ contents && false !== strpos ( $ contents , 'SQLITE_DB_DROPIN_VERSION ' );
1544+ }
15091545}
0 commit comments