Maintenance mode excluding site administrators
I want to set the site into maintenance mode without using a plugin so that anyone who accesses the site who is not a site admin will see a sorry site under maintenance page.
I created a .maintenance file with the code below:
?php
function is_user_logged_in() {
$loggedin = false;
foreach ( (array) $_COOKIE as $cookie = $value ) {
if ( stristr($cookie, 'wordpress_logged_in_') )
$loggedin = true;
}
return $loggedin;
}
if ( ! stristr($_SERVER['REQUEST_URI'], '/wp-admin')
! stristr($_SERVER['REQUEST_URI'], '/wp-login.php')
! is_user_logged_in() )
$upgrading = time();
?
I also customized a maintenance.php file with page content and installed it in wp-content.
That way it worked well, but the problem is that anyone who is already logged into the site can browse the site. As it's an ecommerce site, it's common for customers to have cookies installed, but I don't want them to be able to use the site while it's under maintenance.
I'm not a developer, so I don't know how to fix the code above to let only admins get around maintenance mode.
Can someone help me?
Edit:
I'm going to use this during the begining of Black Friday to update store prices and my goal is to load as little WordPress as possible when people come to the site so as not to overload the server. In previous years the site didn't handle the high volume of simultaneous users very well while trying to activate promotions and this year, in addition to other actions, I want to prevent people who are constantly refreshing the page from affecting the performance of WordPress.
In my view, the .maintenance file method makes the user to load very little WordPress resources. But please correct me if I'm wrong.
Topic maintenance admin Wordpress
Category Web