Created
January 19, 2021 18:56
-
-
Save michaelbragg/3aaf6baff3bbef1ad0832f3fed863ffe to your computer and use it in GitHub Desktop.
Simple Maintenance Mode redirect
This file contains 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 | |
/** | |
* Plugin Name: [TI] Maintenance Mode | |
* Plugin URI: https://www.thoughtsandideas.uk | |
* Description: | |
* Author: Michael Bragg <michael.bragg@thoughtsandideas.uk> | |
* Author URI: https://www.thoughtsandideas.uk | |
* Version: 1.0.0 | |
* License: GPLv2 | |
*/ | |
function ti_maintenance_mode() { | |
// Set `define( 'TI_MAINTENANCE_MODE', true)` in your `wp-config.php` file. | |
if ( ! defined( 'TI_MAINTENANCE_MODE' ) || false == TI_MAINTENANCE_MODE ) { | |
return; | |
} | |
// Use `list_users` as check to allow Shop Managers access. | |
if( ! is_user_logged_in() && ! current_user_can( 'list_users' ) ) { | |
wp_redirect( | |
// Path to holding page file. | |
get_option( 'home' ) . '/maintenance.html', | |
307 | |
); exit; | |
} | |
} | |
add_action( | |
'get_header', | |
'ti_maintenance_mode' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment