Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/wp-admin/includes/class-wp-automatic-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 7 additions & 1 deletion src/wp-includes/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
34 changes: 34 additions & 0 deletions tests/phpunit/tests/load/wpIsMaintenanceMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Unit tests for `wp_is_maintenance_mode()`.
*
* @package WordPress
* @subpackage UnitTests
*
* @group load
*
* @covers ::wp_is_maintenance_mode
*/
class Test_WP_Is_Maintenance_Mode extends WP_UnitTestCase {

public function tear_down() {
if ( is_dir( ABSPATH . '.maintenance' ) ) {
rmdir( ABSPATH . '.maintenance' );
}

parent::tear_down();
}

/**
* @ticket 65911
*/
public function test_should_return_false_when_the_maintenance_file_cannot_be_loaded() {
if ( file_exists( ABSPATH . '.maintenance' ) ) {
$this->markTestSkipped( 'A .maintenance file already exists in ABSPATH.' );
}

mkdir( ABSPATH . '.maintenance' );

$this->assertFalse( wp_is_maintenance_mode() );
}
}
Loading