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?