Network-Wide Maintenance Mode Switch
Adds a checkbox to Network Admin > Settings that puts every site on the network into maintenance mode at once; super admins can still browse and work normally.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
add_action( 'wpmu_options', function () {
?>
<h2><?php esc_html_e( 'Maintenance' ); ?></h2>
<table class="form-table" role="presentation">
<tr>
<th scope="row"><?php esc_html_e( 'Maintenance mode' ); ?></th>
<td><label><input type="checkbox" name="wpide_network_maintenance" value="1" <?php checked( get_site_option( 'wpide_network_maintenance' ) ); ?>> <?php esc_html_e( 'Show a maintenance page on every site to everyone except super admins' ); ?></label></td>
</tr>
</table>
<?php
} );
add_action( 'update_wpmu_options', function () {
if ( current_user_can( 'manage_network_options' ) ) {
update_site_option( 'wpide_network_maintenance', empty( $_POST['wpide_network_maintenance'] ) ? 0 : 1 );
}
} );
add_action( 'template_redirect', function () {
if ( ! get_site_option( 'wpide_network_maintenance' ) || is_super_admin() ) {
return;
}
header( 'Retry-After: 3600' );
wp_die(
'<h1>' . esc_html__( 'Down for maintenance' ) . '</h1><p>' . esc_html__( 'We are making some improvements and will be back shortly.' ) . '</p>',
esc_html__( 'Maintenance' ),
array( 'response' => 503 )
);
} );
add_action( 'admin_bar_menu', function ( $bar ) {
if ( get_site_option( 'wpide_network_maintenance' ) && is_super_admin() ) {
$bar->add_node( array(
'id' => 'wpide-network-maintenance',
'title' => '<span style="color:#f0b849">' . esc_html__( 'Network maintenance ON' ) . '</span>',
'href' => network_admin_url( 'settings.php' ),
) );
}
}, 100 );
Notes
Visitors get a 503 response with a Retry-After header, which tells search engines the downtime is temporary.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.