Skip to content

Commit e94788f

Browse files
Copilotswissspidy
andcommitted
Simplify error handling - WP_CLI::error() is always available
Co-authored-by: swissspidy <[email protected]>
1 parent 16b95f2 commit e94788f

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

src/Core_Command.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,29 +1708,15 @@ private function require_upgrade_file( $context = 'WordPress operation' ) {
17081708
false !== strpos( $error['file'], 'wp-admin/includes/' )
17091709
|| false !== strpos( $error['file'], 'wp-includes/' )
17101710
) {
1711-
$message = sprintf(
1712-
"Failed to load WordPress files for %s. This often indicates a missing PHP extension or a corrupted WordPress installation.\n\nError: %s in %s on line %d\n\nPlease check that all required PHP extensions are installed and that your WordPress installation is complete.",
1713-
$context,
1714-
$error['message'],
1715-
$error['file'],
1716-
$error['line']
1711+
WP_CLI::error(
1712+
sprintf(
1713+
"Failed to load WordPress files for %s. This often indicates a missing PHP extension or a corrupted WordPress installation.\n\nError: %s in %s on line %d\n\nPlease check that all required PHP extensions are installed and that your WordPress installation is complete.",
1714+
$context,
1715+
$error['message'],
1716+
$error['file'],
1717+
$error['line']
1718+
)
17171719
);
1718-
// Attempt to use WP_CLI::error(), but fall back to direct output if in shutdown.
1719-
try {
1720-
if ( class_exists( 'WP_CLI' ) && method_exists( 'WP_CLI', 'error' ) ) {
1721-
WP_CLI::error( $message );
1722-
} else {
1723-
throw new \Exception( 'WP_CLI::error() not available' );
1724-
}
1725-
} catch ( \Throwable $e ) {
1726-
// Fallback: output directly to STDERR and exit.
1727-
if ( defined( 'STDERR' ) ) {
1728-
fwrite( STDERR, $message . "\n" );
1729-
} else {
1730-
error_log( $message );
1731-
}
1732-
exit( 1 );
1733-
}
17341720
}
17351721
}
17361722
};

0 commit comments

Comments
 (0)