Upgrade/Install: Introduce wp_in_maintenance_mode(), a helper function to check if WordPress is currently in maintenance mode.

Props Clorith.
Fixes #49959.
Built from https://develop.svn.wordpress.org/trunk@47623


git-svn-id: http://core.svn.wordpress.org/trunk@47398 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-04-25 20:19:07 +00:00
parent 43cfa7ee60
commit 77eb929b52
2 changed files with 50 additions and 34 deletions

View File

@ -146,46 +146,15 @@ function wp_favicon_request() {
/**
* Die with a maintenance message when conditions are met.
*
* Checks for a file in the WordPress root directory named ".maintenance".
* This file will contain the variable $upgrading, set to the time the file
* was created. If the file was created less than 10 minutes ago, WordPress
* enters maintenance mode and displays a message.
*
* The default message can be replaced by using a drop-in (maintenance.php in
* the wp-content directory).
*
* @since 3.0.0
* @access private
*
* @global int $upgrading the unix timestamp marking when upgrading WordPress began.
*/
function wp_maintenance() {
if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) {
return;
}
global $upgrading;
require ABSPATH . '.maintenance';
// If the $upgrading timestamp is older than 10 minutes, don't die.
if ( ( time() - $upgrading ) >= 600 ) {
return;
}
/**
* Filters whether to enable maintenance mode.
*
* This filter runs before it can be used by plugins. It is designed for
* non-web runtimes. If this filter returns true, maintenance mode will be
* active and the request will end. If false, the request will be allowed to
* continue processing even if maintenance mode should be active.
*
* @since 4.6.0
*
* @param bool $enable_checks Whether to enable maintenance mode. Default true.
* @param int $upgrading The timestamp set in the .maintenance file.
*/
if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
// Return if maintenance mode is disabled.
if ( ! wp_in_maintenance_mode() ) {
return;
}
@ -206,6 +175,53 @@ function wp_maintenance() {
);
}
/**
* Check if maintenance mode is enabled.
*
* Checks for a file in the WordPress root directory named ".maintenance".
* This file will contain the variable $upgrading, set to the time the file
* was created. If the file was created less than 10 minutes ago, WordPress
* is in maintenance mode.
*
* @since 5.5.0
*
* @global int $upgrading The Unix timestamp marking when upgrading WordPress began.
*
* @return bool True if maintenance mode is enabled, false otherwise.
*/
function wp_in_maintenance_mode() {
global $upgrading;
if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) {
return false;
}
require ABSPATH . '.maintenance';
// If the $upgrading timestamp is older than 10 minutes, consider maintenance over.
if ( ( time() - $upgrading ) >= 600 ) {
return false;
}
/**
* Filters whether to enable maintenance mode.
*
* This filter runs before it can be used by plugins. It is designed for
* non-web runtimes. If this filter returns true, maintenance mode will be
* active and the request will end. If false, the request will be allowed to
* continue processing even if maintenance mode should be active.
*
* @since 4.6.0
*
* @param bool $enable_checks Whether to enable maintenance mode. Default true.
* @param int $upgrading The timestamp set in the .maintenance file.
*/
if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
return false;
}
return true;
}
/**
* Start the WordPress micro-timer.
*

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-alpha-47622';
$wp_version = '5.5-alpha-47623';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.