Admin – Enable maintenance mode for non-admins

WordPress Admin Snippet

This is very useful to disable access to non-admins and allow admins to make changes to the admin dashboard so that non-admins can not mess with any thing whilst updates are been made.

Implementation

1. Either code and paste the code into your themes functions.php or child theme
2. If you are not that technical then install the WordPress Snippets plugin

function wpts_maintenance_mode(){
if(!current_user_can(‘edit_themes’) || !is_user_logged_in()){
wp_die(‘Under Maintenance, please come back soon.’, ‘Under Maintenance – please come back soon.’, array(‘response’ => ‘503’));
}
}
add_action(‘get_header’, ‘wpts_maintenance_mode’);

View on snippet on GitHub.

NEED HELP?

If you are struggling to implement the SVG snippet then we can help from £9.99 – use our contact form below and we will get straight back to you!

HELP ME IMPLEMENT THIS SNIPPET

Leave a comment

Shares