Last active
January 29, 2022 01:34
-
-
Save wpscholar/de814426102cb17b3cfc9328303f1575 to your computer and use it in GitHub Desktop.
Enable maintenance mode via code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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