_menu_site_is_offline

Versions
4.7 – 6
_menu_site_is_offline()
7
_menu_site_is_offline($check_only = FALSE)

Checks whether the site is off-line 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 off-line 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 off-line.

Related topics

Code

includes/menu.inc, line 2471

<?php
function _menu_site_is_offline() {
  // Check if site is set to off-line mode.
  if (variable_get('site_offline', 0)) {
    // Check if the user has administration privileges.
    if (user_access('administer site configuration')) {
      // Ensure that the off-line 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(l(t('Operating in off-line mode.'), 'admin/settings/site-maintenance'), '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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.