1.20.x menu.inc _menu_site_status($path = NULL, $display_messages = FALSE)

Checks whether the site is in maintenance mode.

This function will log the current user out and redirect to home page if the current user has no 'access site in maintenance mode' permission.

Parameters

string $path: The path at which to check site status. Some pages (such as user/login) may be considered online while the rest of the site is offline. If empty, the current path will be used.

bool $display_messages: If set to TRUE, messages will be displayed indicating the site is in offline mode.

Return value

FALSE if the site is not in maintenance mode, the user login page is: displayed, or the user has the 'access site in maintenance mode' permission. TRUE for anonymous users not being on the login page when the site is in maintenance mode.

Related topics

File

includes/menu.inc, line 4057
API for the Backdrop menu system.

Code

function _menu_site_status($path = NULL, $display_messages = FALSE) {
  $site_status = &backdrop_static(__FUNCTION__);
  if (isset($site_status) && !$display_messages) {
    return $site_status === MENU_SITE_OFFLINE;
  }

  $site_status = MENU_SITE_ONLINE;

  // Check if site is in maintenance mode.
  if (state_get('maintenance_mode', FALSE)) {
    if (user_access('access site in maintenance mode')) {
      // Ensure that the maintenance mode message is displayed only once
      // (allowing for page redirects) and specifically suppress its display on
      // the batch and maintenance mode settings pages. 'admin_bar/flush-cache'
      // has been added to the list of excluded paths in order to suppress the
      // warning on the maintenance mode settings page when clearing caches (see
      // https://github.com/backdrop/backdrop-issues/issues/3313).
      $excluded_paths = array('batch', 'admin/config/development/maintenance', 'admin_bar/flush-cache');
      if ($display_messages && !in_array(current_path(), $excluded_paths)) {
        $message = t('The site is currently in maintenance mode.');
        if (user_access('administer site configuration')) {
          $message .= ' ' . l(t('Go online.'), 'admin/config/development/maintenance', array('query' => backdrop_get_destination()));
        }
        backdrop_set_message($message, 'warning', FALSE);
      }
    }
    else {
      $site_status = MENU_SITE_OFFLINE;
    }
  }

  // Allow other modules to change the site status but not the path because that
  // would not change the global variable. hook_url_inbound_alter() can be used
  // to change the path. Code later will not use the $read_only_path variable.
  $read_only_path = !empty($path) ? $path : current_path();
  backdrop_alter('menu_site_status', $site_status, $read_only_path);

  return $site_status;
}