Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enable maintenance mode via code
<?php
/**
* Maintenance Mode
*
* @package MaintenanceMode
* @author Micah Wood
* @copyright Copyright 2022 by Micah Wood - All rights reserved.
* @license GPL2.0-or-later
*
* @wordpress-plugin
* Plugin Name: Maintenance Mode
* Plugin URI: https://gist.github.com/wpscholar/de814426102cb17b3cfc9328303f1575
* Description: Shows an "Under Maintenance" message to logged out users when plugin is active.
* Version: 1.0
* Requires PHP: 5.6
* Requires at least: 5.0
* Author: Micah Wood
* Author URI: https://wpscholar.com
* Text Domain: maintenance-mode
* Domain Path: /languages
* License: GPL V2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
add_action(
'get_header',
function () {
if ( ! current_user_can( 'manage_options' ) || ! is_user_logged_in() ) {
wp_die( '<h1>Under Maintenance</h1><br />Website under planned maintenance. Please check back later.' );
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment