diff --git a/src/wp-admin/includes/class-wp-automatic-updater.php b/src/wp-admin/includes/class-wp-automatic-updater.php index cd9426c6ef88b..fd094f0341231 100644 --- a/src/wp-admin/includes/class-wp-automatic-updater.php +++ b/src/wp-admin/includes/class-wp-automatic-updater.php @@ -1766,8 +1766,11 @@ protected function has_fatal_error() { return false; } - require $maintenance_file; - if ( ! is_int( $upgrading ) ) { + // The file may be removed between the check above and the load below. + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Warning emitted in expected failure case. + $maintenance_file_loaded = @include $maintenance_file; + + if ( false === $maintenance_file_loaded || ! is_int( $upgrading ) ) { return false; } diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index 27c58b57dd671..bcab88242f3a3 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -441,7 +441,13 @@ function wp_is_maintenance_mode() { return false; } - require ABSPATH . '.maintenance'; + // The file may be removed between the check above and the load below. + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Warning emitted in expected failure case. + $maintenance_file_loaded = @include ABSPATH . '.maintenance'; + + if ( false === $maintenance_file_loaded ) { + return false; + } // If the $upgrading timestamp is older than 10 minutes, consider maintenance over. if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) { diff --git a/tests/phpunit/tests/load/wpIsMaintenanceMode.php b/tests/phpunit/tests/load/wpIsMaintenanceMode.php new file mode 100644 index 0000000000000..a8b66e5aa8e01 --- /dev/null +++ b/tests/phpunit/tests/load/wpIsMaintenanceMode.php @@ -0,0 +1,34 @@ +markTestSkipped( 'A .maintenance file already exists in ABSPATH.' ); + } + + mkdir( ABSPATH . '.maintenance' ); + + $this->assertFalse( wp_is_maintenance_mode() ); + } +}