Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active January 29, 2022 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpscholar/de814426102cb17b3cfc9328303f1575 to your computer and use it in GitHub Desktop.
Save wpscholar/de814426102cb17b3cfc9328303f1575 to your computer and use it in GitHub Desktop.
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