_menu_site_is_offline
Definition
_menu_site_is_offline()
includes/menu.inc, line 2452
Description
Checks whether the site is offline for maintenance.
This function will log the current user out and redirect to front page if the current user has no 'administer site configuration' permission.
Return value
FALSE if the site is not offline or its the login page or the user has 'administer site configuration' permission. TRUE for anonymous users not on the login page if the site is offline.
Related topics
| Name | Description |
|---|---|
| Menu system | Define the navigation menus, and route page requests to code based on URLs. |
Code
<?php
function _menu_site_is_offline() {
// Check if site is set to offline mode.
if (variable_get('site_offline', 0)) {
// Check if the user has administration privileges.
if (user_access('administer site configuration')) {
// Ensure that the offline message is displayed only once [allowing for
// page redirects], and specifically suppress its display on the site
// maintenance page.
if (drupal_get_normal_path($_GET['q']) != 'admin/settings/site-maintenance') {
drupal_set_message(t('Operating in offline mode.'), 'status', FALSE);
}
}
else {
// Anonymous users get a FALSE at the login prompt, TRUE otherwise.
if (user_is_anonymous()) {
return $_GET['q'] != 'user' && $_GET['q'] != 'user/login';
}
// Logged in users are unprivileged here, so they are logged out.
require_once drupal_get_path('module', 'user') . '/user.pages.inc';
user_logout();
}
}
return FALSE;
}
?> 