Skip to content

Commit a1b8628

Browse files
swissspidyCopilot
andauthored
Update src/Core_Command.php
Co-authored-by: Copilot <[email protected]>
1 parent 27758fe commit a1b8628

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/Core_Command.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,18 +1687,42 @@ private function require_upgrade_file( $context = 'WordPress operation' ) {
16871687
// Register a shutdown function to catch fatal errors during require_once.
16881688
$shutdown_handler = function () use ( $upgrade_file, $context ) {
16891689
$error = error_get_last();
1690-
if ( null !== $error && in_array( $error['type'], [ E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR ], true ) ) {
1690+
if (
1691+
null !== $error
1692+
&& in_array(
1693+
$error['type'],
1694+
[ E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_COMPILE_WARNING, E_USER_ERROR ],
1695+
true
1696+
)
1697+
) {
16911698
// Check if error occurred in the upgrade file or files it includes.
1692-
if ( false !== strpos( $error['file'], 'wp-admin/includes/' ) || false !== strpos( $error['file'], 'wp-includes/' ) ) {
1693-
WP_CLI::error(
1694-
sprintf(
1695-
"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.",
1696-
$context,
1697-
$error['message'],
1698-
$error['file'],
1699-
$error['line']
1700-
)
1699+
if (
1700+
false !== strpos( $error['file'], 'wp-admin/includes/' )
1701+
|| false !== strpos( $error['file'], 'wp-includes/' )
1702+
) {
1703+
$message = sprintf(
1704+
"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.",
1705+
$context,
1706+
$error['message'],
1707+
$error['file'],
1708+
$error['line']
17011709
);
1710+
// Attempt to use WP_CLI::error(), but fall back to direct output if in shutdown.
1711+
try {
1712+
if ( class_exists( 'WP_CLI' ) && method_exists( 'WP_CLI', 'error' ) ) {
1713+
WP_CLI::error( $message );
1714+
} else {
1715+
throw new \Exception( 'WP_CLI::error() not available' );
1716+
}
1717+
} catch ( \Throwable $e ) {
1718+
// Fallback: output directly to STDERR and exit.
1719+
if ( defined( 'STDERR' ) ) {
1720+
fwrite( STDERR, $message . "\n" );
1721+
} else {
1722+
error_log( $message );
1723+
}
1724+
exit( 1 );
1725+
}
17021726
}
17031727
}
17041728
};

0 commit comments

Comments
 (0)