WordPress.org

Make WordPress Core

Opened 5 weeks ago

Last modified 2 weeks ago

#49959 reopened enhancement

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

Reported by: Clorith Owned by: 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 5 weeks ago.

Download all attachments as: .zip

Change History (7)

@Clorith
5 weeks ago

#1 follow-up: @Clorith
5 weeks 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 weeks ago

#3 @ocean90
4 weeks 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 weeks 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 weeks 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
2 weeks 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.

Note: See TracTickets for help on using tickets.