File: //scripts/wpcloud-maintenance-mode.php
<?php
/**
* Plugin Name: WP Cloud Maintenance Mode
* Description: Custom implementation for use with the WP CLI maintenance-mode command.
*
* See: https://core.trac.wordpress.org/ticket/62489
*/
if ( ( 'fpm-fcgi' === php_sapi_name() ) && ( ! function_exists( 'wpcloud_maintenance_mode' ) ) ) {
function wpcloud_maintenance_mode() {
if ( ! defined( 'WP_CONTENT_DIR' ) ) {
return;
}
// Return if maintenance mode is disabled.
if ( ! file_exists( WP_CONTENT_DIR . '/.wpcloud-maintenance' ) ) {
return;
}
// We do not declare the $upgrading variable in the global scope to avoid conflating our
// plugin behavior with core's functionality.
require WP_CONTENT_DIR . '/.wpcloud-maintenance';
// If the $upgrading timestamp is older than 10 minutes, consider maintenance over.
if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) {
return;
}
if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
return;
}
if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
require_once WP_CONTENT_DIR . '/maintenance.php';
die();
}
require_once ABSPATH . WPINC . '/functions.php';
wp_load_translations_early();
header( 'Retry-After: 600' );
wp_die(
__( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ),
__( 'Maintenance' ),
503
);
}
add_action( 'muplugins_loaded', 'wpcloud_maintenance_mode' );
}