Skip to content

Commit 27a8e1a

Browse files
committed
Fix: wp core is-installed returns 0 when no tables exist
1 parent f157fb3 commit 27a8e1a

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

src/Core_Command.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,45 @@ 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+
396401
if ( is_blog_installed() && ( ! Utils\get_flag_value( $assoc_args, 'network' ) || is_multisite() ) ) {
402+
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+
];
418+
$missing_tables = [];
419+
foreach ( $required_tables as $table ) {
420+
$table_name = $wpdb->prefix . $table;
421+
// Check if table exists
422+
$result = $wpdb->get_var( $wpdb->prepare(
423+
"SHOW TABLES LIKE %s", $table_name
424+
) );
425+
if ( $result !== $table_name ) {
426+
$missing_tables[] = $table_name;
427+
}
428+
}
429+
if ( ! empty( $missing_tables ) ) {
430+
// Output missing tables for debugging
431+
WP_CLI::error( "WordPress is not installed. Missing tables: " . implode( ', ', $missing_tables ), 1 );
432+
}
397433
WP_CLI::halt( 0 );
398434
}
399-
400435
WP_CLI::halt( 1 );
401436
}
402437

0 commit comments

Comments
 (0)