When WordPress is updating the core, themes or plugins it generates a file in the root folder called .maintenance.
WordPress will be put into “maintenance mode” and your visitors will then see the message “Briefly unavailable for scheduled maintenance. Check back in a minute”.
You can easily replace this message with a custom page of your own. Here’s how.
What is Maintenance Mode?
Whenever you run the update process on the WordPress core, a theme or a plugin, WordPress is placed in what is called “maintenance mode”.
The reason for this is to minimize any errors to file updates and to prevent your visitors from seeing any errors.
The update process downloads the most recent zip file from the WordPress.org repository, deletes the existing copy and then unzips the new version replacing the old one.
If you or your visitors were to try and access the site when this update process is taking place they would get errors due to missing files during the deletion and
This is the reason for WordPress’ maintenance mode.
How does WordPress know it’s in Maintenance Mode?
The update process creates a small hidden (in Unix) file called .maintenance in the root folder of your site. The same location as your .htaccess file.
Prior to WordPress
Sometimes things don’t work according to plan and
This would leave the .maintenance file still in the root and the WordPress site would be left in maintenance mode limbo.
Site owners would have to manually delete the .maintenance file to get their site running again.
Since WordPress 3.0 a PHP variable [codelet]$updating[/codelet] is added to the file containing a UNIX timestamp of when the file was created.
[codelet]<!–?php $upgrading = 1367901024; ?–>[/codelet]
WordPress now checks this time against the current time and if it’s under 10 minutes the maintenance mode message is displayed.
This means that even if the update process fails and doesn’t automatically delete the .maintenance file, you can still access your site after 10 minutes. Yay.
Replacing the Default Maintenance Mode Message
The default message is pretty
As a developer that just won’t do
The code is in the file wp-includes/load.php around line 131 in the function [codelet]wp_maintenance()[/codelet].
Looking through the code you can see where it checks for
The next part of the function then checks to see if there is a file called maintenance.php in the wp-content folder.
[gist id=8142756 file=code-snippet-1.php]
Bingo! I can work with that.
Ten minutes later and a lot of code badgering we now have a nicely branded maintenance.php file sitting in the wp-content folder which overrides the sucky default maintenance mode message.
Everything else in your site is branded so why not this too!
Just remember that this page is out of scope for the WordPress libraries so things like $post and WordPress functions won’t work unless you include the appropriate files in your maintenance.php page.
Go forth and pimp your WordPress maintenance mode message and send us a link to it.