Make WordPress Core

Ticket #49959: 49959.patch

File 49959.patch, 3.3 KB (added by Clorith, 5 years ago)
  • src/wp-includes/load.php

     
    172172/**
    173173 * Die with a maintenance message when conditions are met.
    174174 *
    175  * Checks for a file in the WordPress root directory named ".maintenance".
    176  * This file will contain the variable $upgrading, set to the time the file
    177  * was created. If the file was created less than 10 minutes ago, WordPress
    178  * enters maintenance mode and displays a message.
    179  *
    180175 * The default message can be replaced by using a drop-in (maintenance.php in
    181176 * the wp-content directory).
    182177 *
     
    186181 * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
    187182 */
    188183function wp_maintenance() {
    189         if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) {
    190                 return;
    191         }
    192 
    193         global $upgrading;
    194 
    195         require ABSPATH . '.maintenance';
    196         // If the $upgrading timestamp is older than 10 minutes, don't die.
    197         if ( ( time() - $upgrading ) >= 600 ) {
    198                 return;
    199         }
    200 
    201         /**
    202          * Filters whether to enable maintenance mode.
    203          *
    204          * This filter runs before it can be used by plugins. It is designed for
    205          * non-web runtimes. If this filter returns true, maintenance mode will be
    206          * active and the request will end. If false, the request will be allowed to
    207          * continue processing even if maintenance mode should be active.
    208          *
    209          * @since 4.6.0
    210          *
    211          * @param bool $enable_checks Whether to enable maintenance mode. Default true.
    212          * @param int  $upgrading     The timestamp set in the .maintenance file.
    213          */
    214         if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
     184        // Return if maintenance mode is disabled.
     185        if ( ! wp_in_maintenance_mode() ) {
    215186                return;
    216187        }
    217188
     
    275246        return $r;
    276247}
    277248
     249/**
     250 * Check if maintenance mode is enabled.
     251 *
     252 * Checks for a file in the WordPress root directory named ".maintenance".
     253 * This file will contain the variable $upgrading, set to the time the file
     254 * was created. If the file was created less than 10 minutes ago, WordPress
     255 * is in maintenance mode.
     256 *
     257 * @since 5.5.0
     258 *
     259 * @return bool
     260 */
     261function wp_in_maintenance_mode() {
     262        if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) {
     263                return false;
     264        }
     265
     266        global $upgrading;
     267
     268        require ABSPATH . '.maintenance';
     269        // If the $upgrading timestamp is older than 10 minutes, consider maintenance over.
     270        if ( ( time() - $upgrading ) >= 600 ) {
     271                return false;
     272        }
     273
     274        /**
     275         * Filters whether to enable maintenance mode.
     276         *
     277         * This filter runs before it can be used by plugins. It is designed for
     278         * non-web runtimes. If this filter returns true, maintenance mode will be
     279         * active and the request will end. If false, the request will be allowed to
     280         * continue processing even if maintenance mode should be active.
     281         *
     282         * @since 4.6.0
     283         *
     284         * @param bool $enable_checks Whether to enable maintenance mode. Default true.
     285         * @param int  $upgrading     The timestamp set in the .maintenance file.
     286         */
     287        if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
     288                return false;
     289        }
     290
     291        return true;
     292}
     293
    278294/**
    279295 * Set PHP error reporting based on WordPress debug settings.
    280296 *