Skip to content

Commit 3f3826e

Browse files
committed
Fix: wp core is-installed returns proper exit code when tables are missing
1 parent 27a8e1a commit 3f3826e

3 files changed

Lines changed: 14 additions & 23 deletions

File tree

features/core.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Feature: Manage WordPress installation
2323

2424
When I try `wp core is-installed`
2525
Then the return code should be 1
26+
And STDERR should contain:
27+
"""
28+
WordPress is not installed. Missing tables:
29+
"""
2630

2731
When I try `wp core is-installed --network`
2832
Then the return code should be 1

src/Core_Command.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -393,45 +393,32 @@ function () use ( $temp ) {
393393
* @param array{network?: bool} $assoc_args Associative arguments.
394394
*/
395395
public function is_installed( $args, $assoc_args ) {
396-
// Check if WordPress is installed by verifying required tables exist.
397-
if ( ! function_exists( 'is_blog_installed' ) ) {
398-
require_once ABSPATH . 'wp-includes/load.php';
399-
}
400-
401396
if ( is_blog_installed() && ( ! Utils\get_flag_value( $assoc_args, 'network' ) || is_multisite() ) ) {
402397
global $wpdb;
403-
// List of required core tables (prefix will be added automatically)
404-
$required_tables = [
405-
'options',
406-
'users',
407-
'usermeta',
408-
'posts',
409-
'comments',
410-
'commentmeta',
411-
'terms',
412-
'termmeta',
413-
'term_taxonomy',
414-
'term_relationships',
415-
'links',
416-
'postmeta',
417-
];
398+
399+
// Get core tables from $wpdb
400+
$tables = $wpdb->tables();
418401
$missing_tables = [];
419-
foreach ( $required_tables as $table ) {
402+
403+
// Check if all core tables exist
404+
foreach ( $tables as $table ) {
420405
$table_name = $wpdb->prefix . $table;
421-
// Check if table exists
422406
$result = $wpdb->get_var( $wpdb->prepare(
423407
"SHOW TABLES LIKE %s", $table_name
424408
) );
409+
425410
if ( $result !== $table_name ) {
426411
$missing_tables[] = $table_name;
427412
}
428413
}
414+
429415
if ( ! empty( $missing_tables ) ) {
430-
// Output missing tables for debugging
431416
WP_CLI::error( "WordPress is not installed. Missing tables: " . implode( ', ', $missing_tables ), 1 );
432417
}
418+
433419
WP_CLI::halt( 0 );
434420
}
421+
435422
WP_CLI::halt( 1 );
436423
}
437424

wp-cli.phar

6.81 MB
Binary file not shown.

0 commit comments

Comments
 (0)