Skip to content

Commit 16b95f2

Browse files
Copilotswissspidy
andcommitted
Prevent shutdown handler from executing after successful require_once
Co-authored-by: swissspidy <[email protected]>
1 parent 3e9d6c1 commit 16b95f2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Core_Command.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,8 +1684,16 @@ private function require_upgrade_file( $context = 'WordPress operation' ) {
16841684
WP_CLI::error( "Cannot read WordPress installation file '{$upgrade_file}'. Check file permissions." );
16851685
}
16861686

1687+
// Use a flag to track successful completion and prevent handler from executing after success.
1688+
$require_completed = false;
1689+
16871690
// Register a shutdown function to catch fatal errors during require_once.
1688-
$shutdown_handler = function () use ( $context ) {
1691+
$shutdown_handler = function () use ( $context, &$require_completed ) {
1692+
// Only handle errors if require_once did not complete successfully.
1693+
if ( $require_completed ) {
1694+
return;
1695+
}
1696+
16891697
$error = error_get_last();
16901698
if (
16911699
null !== $error
@@ -1731,5 +1739,8 @@ private function require_upgrade_file( $context = 'WordPress operation' ) {
17311739

17321740
// phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- Path comes from WordPress itself.
17331741
require_once $upgrade_file;
1742+
1743+
// Mark as completed to prevent the shutdown handler from executing on unrelated errors.
1744+
$require_completed = true;
17341745
}
17351746
}

0 commit comments

Comments
 (0)