Maintenance Mode for Non-Admins
Displays a 503 maintenance page to all non-administrator visitors while leaving the wp-admin dashboard accessible.
PHPby SnipCraft
php
<?php
add_action( 'template_redirect', 'scseed_maintenance_mode', 1 );
function scseed_maintenance_mode() {
// Allow administrators, CLI processes, and WP-Cron through.
if ( current_user_can( 'manage_options' ) ) {
return;
}
if ( defined( 'WP_CLI' ) && WP_CLI ) {
return;
}
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
return;
}
// 503 tells search engines the site is temporarily unavailable;
// Retry-After suggests when to check back.
status_header( 503 );
header( 'Retry-After: 3600' );
nocache_headers();
$site_name = get_bloginfo( 'name' );
wp_die(
'<div style="font-family:sans-serif;text-align:center;padding:60px 20px;">'
. '<h1>' . esc_html__( 'Briefly unavailable for scheduled maintenance.', 'scseed' ) . '</h1>'
. '<p>' . esc_html__( 'Check back in a moment.', 'scseed' ) . '</p>'
. '<p style="color:#888;font-size:0.9em;">' . esc_html( $site_name ) . '</p>'
. '</div>',
esc_html__( 'Maintenance Mode', 'scseed' ),
array( 'response' => 503 )
);
}#503#development#maintenance#redirect