Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#49959 closed enhancement (fixed)

Introduce a new helper function to check if WordPress is currently in maintenance mode

Reported by: clorith's profile Clorith Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version: 3.0
Component: Upgrade/Install Keywords: has-patch 2nd-opinion
Focuses: Cc:

Description

Initially thought of as wp_is_updating(), but as I've spent some time considering this, maintenance mode is used by various plugins as well, so it seems reasonable to instead go with something along the lines of wp_is_maintenance_mode(), returning a boolean to indicate if maintenance mode is enabled or not.

Currently core only checks for maintenance mode in a single location, in the `wp_maintenance()` function, used to stop processing if maintenance is ongoing.

With #48964 also looking to check if maintenance mode is enabled, it makes sense to split this out, both for core, but also for potential maintenance plugins.

The most direct route would be to take parts of the existing function, and make that the new helper, specifically lines 189-216.

The big question really is, what would such a function be named, to easily convey intent.

For completeness sake, there is already a wp_installing() boolean check, which looks for the setup constants. With the existing function being there wit ha similar name, it seemed more appropriate to give the new one a slightly more descriptive function name.

Attachments (1)

49959.patch (3.3 KB) - added by Clorith 4 years ago.

Download all attachments as: .zip

Change History (8)

@Clorith
4 years ago

#1 follow-up: @Clorith
4 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 5.5

49959.patch implements the proposed function, using the name wp_in_maintenance_mode(), as it checks the state, so the use of is might have ended up being confusing to some.

This ticket was mentioned in Slack in #core by clorith. View the logs.


4 years ago

#3 @ocean90
4 years ago

If a site is in maintenance mode any other request is blocked which means the function can’t be used by something else. Am I missing something?

#4 @Clorith
4 years ago

While this is true that regular requests will not be able to process, the fatal error handler is still active, and can trigger email notifications during race conditions where files are being processed.

I plan on adding a maintenance check to avoid the error handler from triggering during upgrade routines in #48964, hence this pre-requisite to avoid duplicating the check for .maintenance and related checks that are done.

#5 @SergeyBiryukov
4 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 47623:

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

Props Clorith.
Fixes #49959.

#6 in reply to: ↑ 1 @SergeyBiryukov
4 years ago

  • Keywords 2nd-opinion added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Replying to Clorith:

49959.patch implements the proposed function, using the name wp_in_maintenance_mode(), as it checks the state, so the use of is might have ended up being confusing to some.

It occurred to me that we already have wp_is_recovery_mode() and wp_is_fatal_error_handler_enabled().

Perhaps wp_is_maintenance_mode() or wp_is_maintenance_mode_enabled() would be a better name for consistency with those two functions? I'm not 100% sure the existing name from [47623] should be changed, just wanted to bring it up for discussion.

#7 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 47871:

Upgrade/Install: Rename wp_in_maintenance_mode() to wp_is_maintenance_mode(), for consistency with wp_is_recovery_mode().

While the former name might be a bit more accurate, the latter matches the existing naming pattern.

Follow-up to [47623].

Fixes #49959.

Note: See TracTickets for help on using tickets.