A very simple maintenance mode plugin for very short maintenance times.
This is a super maintenance mode plugin that I wrote a few years ago. I updated it this morning to be a bit more efficient.
Choosing the action
The original version of the plugin ran during the ‘get_header‘ action. I often use this action because I know that all the template tags (e.g. is_single()) have been initialised and theme and plugin actions have been added (and available for me to remove_action() them).
This morning I opened the WordPress Action Reference and looked for earlier actions to use to reduce the amount of WordPress code that is run before the plugin rudely stops everything. As the plugin checks user capabilities it had to be an action that runs after the user is initialised.
The ‘init‘ action is run after the user is authenticated. While promising, I quickly found that this prevents users from logging into the site – the maintenance mode message shows when you go to the wp-login.php page.
I tried the ‘wp_loaded‘ action and encountered the same issue.
The ‘wp‘ action was my next attempt and it worked.
That’s it. Don’t use it for very long because it doesn’t set the correct return code to indicate maintenance mode (that should be 503).