Created
January 21, 2012 19:26
-
-
Save GaryJones/1653664 to your computer and use it in GitHub Desktop.
WP Simple Maintenance Mode
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 | |
/** | |
* WP Simple Maintenance Mode plugin | |
* | |
* Shows site in maintenance mode unless on the login page or one of a | |
* selected group of users. | |
* | |
* Revamp of http://pastebin.com/tK6YnfyS | |
* | |
* @package WP_Simple_Maintenance_Mode | |
* @author Brian Richards | |
* @author Gary Jones | |
* @license GPL3 | |
* @link https://gist.github.com/1653664 | |
* | |
* @wordpress-plugin | |
* Plugin Name: WP Simple Maintenance Mode | |
* Plugin URI: https://gist.github.com/1653664 | |
* Description: Shows site in maintenance mode unless on the login page or one of a selected group of users. | |
* Version: 1.0.0 | |
* Author: <a href="http://rzen.net/">Brian Richards</a> and <a href="http://garyjones.co.uk/">Gary Jones</a> | |
* License: GPL3 | |
*/ | |
// Try and load translation file for this plugin. | |
if( ! load_plugin_textdomain( 'wp_simple_maintenance_mode', false, '/wp-content/languages/' ) ) | |
load_plugin_textdomain( 'wp_simple_maintenance_mode', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); | |
// Default to WP version if the function exists. | |
if ( ! function_exists( 'is_login_page' ) ) { | |
/** | |
* Check if we're on the login or registration page. | |
* | |
* @since 1.0.0 | |
* | |
* @return boolean True if currently on the login or register page, false otherwise. | |
*/ | |
function is_login_page() { | |
return in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ); | |
} | |
} | |
add_action( 'init', 'wpsmm_show_maintenance_message', 1 ); | |
/** | |
* Conditionally enter a simple maintenance mode. | |
* | |
* If we're on the login page, or one of the selected user IDs, do nothing. | |
* | |
* @since 1.0.0 | |
* | |
* @return null Returns early if on login page or current user is excluded. | |
*/ | |
function wpsmm_show_maintenance_message() { | |
if ( is_login_page() ) | |
return; | |
$excluded_users = array( | |
1, // Admin | |
5, // Bob | |
); | |
if ( in_array( get_current_user_id(), $excluded_users ) ) | |
return; | |
// Could send a HTTP header here to tell search engines we're only down temporarily. | |
wp_die( __( '<h1>Oops</h1><p>This site is currently undergoing maintenance. Sorry for the inconvenience. Please check back soon.</p>', 'wp_simple_maintenance_mode' ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment