Skip to main content
knackforge blog knowledge base

Drupal 7: Invoking custom callback in maintenance mode

In a Drupal site, if we have any module upgrade or configuration related work to be done in our live site, it is recommended to put the site in maintenance mode, so we can prevent end users from experiencing glitches.
 
When the site is operating in maintenance mode, any page request would return only maintenance message. Some pages are allowed to access though. The login functionality for instance will work in the maintenance mode. Recently, I faced such a requirements in which a custom module's callback to be invoked as to let Single Sign On (SSO) work for admin in maintenance mode. I would like to explain the way I fixed the same in this blog.
 
There is a hook in Drupal 7 for that, hook_menu_site_status_alter(). With this hook we can control the site status before menu dispatching, So we can change the site status for the particular path.
 
function MY_MODULE_menu_site_status_alter(&$menu_site_status, $path) {
  if ($path == 'my_module/authentication') {
    $menu_site_status = MENU_SITE_ONLINE;
  }
}

 

Now the my_module/authentication path will be working in the site maintenance mode.