1

I use this code (not mine, I do not know how to code) to disable Maintenance mode message on front-page while developing a site, it's really annoying when it's flashing all the time in the middle of the page.

function theme_preprocess_page(&$vars) {
    if (variable_get('maintenance_mode', 0)) { //no maintenance mode message on front-end
      $message_count = count($_SESSION['messages']['status']);
      if($message_count > 1) {
        array_shift($_SESSION['messages']['status']);
      }
      else {
        unset($_SESSION['messages']['status']);
      }
}

So it works great while logged in and in maintenance mode, but when going to user/login page as anonymous, it gives this notice in red:

Notice: Undefined variable: _SESSION in theme_preprocess_page()
(line 141 of /sites/all/themes/mytheme/template.php).

So what is this? Is the code missing something?

2

Apparently the $_SESSION variable is not available on the login page (I don't know why, but probably to avoid conflicts with logged in users trying to log in again).

Try checking for it before you try to unset it:

function theme_preprocess_page(&$vars) {
    if (variable_get('maintenance_mode', 0) && isset($_SESSION['messages']['status'])) { //no maintenance mode message on front-end
      $message_count = count($_SESSION['messages']['status']);
      if($message_count > 1) {
        array_shift($_SESSION['messages']['status']);
      }
      else {
        unset($_SESSION['messages']['status']);
      }
    }
}
  • Hi, thanks for helping, but this gives me white screen of death when trying to flush cache. – Optimus Prime Mar 20 '14 at 14:54
  • I was missing the closing bracket for the first if statement, does that solve anythign? – Neograph734 Mar 20 '14 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.