-
Notifications
You must be signed in to change notification settings - Fork 56
Fix: wp core is-installed returns 0 when no tables exist #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
27a8e1a
3f3826e
a4e1e24
1dddaa7
6b4843e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,10 +393,45 @@ | |
* @param array{network?: bool} $assoc_args Associative arguments. | ||
*/ | ||
public function is_installed( $args, $assoc_args ) { | ||
// Check if WordPress is installed by verifying required tables exist. | ||
if ( ! function_exists( 'is_blog_installed' ) ) { | ||
require_once ABSPATH . 'wp-includes/load.php'; | ||
} | ||
|
||
if ( is_blog_installed() && ( ! Utils\get_flag_value( $assoc_args, 'network' ) || is_multisite() ) ) { | ||
global $wpdb; | ||
// List of required core tables (prefix will be added automatically) | ||
$required_tables = [ | ||
'options', | ||
'users', | ||
'usermeta', | ||
'posts', | ||
'comments', | ||
'commentmeta', | ||
'terms', | ||
'termmeta', | ||
'term_taxonomy', | ||
'term_relationships', | ||
'links', | ||
'postmeta', | ||
]; | ||
|
||
$missing_tables = []; | ||
foreach ( $required_tables as $table ) { | ||
$table_name = $wpdb->prefix . $table; | ||
// Check if table exists | ||
$result = $wpdb->get_var( $wpdb->prepare( | ||
"SHOW TABLES LIKE %s", $table_name | ||
Check failure on line 423 in src/Core_Command.php
|
||
) ); | ||
if ( $result !== $table_name ) { | ||
$missing_tables[] = $table_name; | ||
} | ||
} | ||
if ( ! empty( $missing_tables ) ) { | ||
// Output missing tables for debugging | ||
WP_CLI::error( "WordPress is not installed. Missing tables: " . implode( ', ', $missing_tables ), 1 ); | ||
|
||
} | ||
WP_CLI::halt( 0 ); | ||
} | ||
|
||
WP_CLI::halt( 1 ); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? Clearly we have been using this function successfully before.
If this is needed, it requires a test proving it.