I created a Drupal 6 / Ubercart 2 site for one of my clients and wanted to give them access to add products while the site was in maintenance mode.
So I created a "store manager" role and created a user with that role. I placed the site in maintenance mode and sent my client the "store manager" user name and password, but they just see the maintenance page (as expected).
I read some posts that suggest implementing HTTP Access or giving that role "administer site configuration" permission, but I need the custom maintenance page working (since it has important information) and allowing site configuration would be risky.
I figured out a hack and thought I would share. I posted the HowTo on this page:
http://www.ubercart.org/forum/support/1734/can_multiple_administrators_a...
Basically (in Drupal 6) I edited the /includes/menu.inc file. The function to look for in that file is
_menu_site_is_offline()
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.
global $user;
if (user_access('administer site configuration') || in_array('store manager', $user->roles)) {
// 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;
}
I added / changed these lines:
global $user;
if (user_access('administer site configuration') || in_array('store manager', $user->roles)) {
I added this post to drupal.org forum (in addition to Ubercart's forum) because it affects the whole drupal system!
Comments
doesn't work for me
I've tried to edit my menu.inc file and edited 'store manager' to 'staff' (having set up a user role called 'staff' and set permission to 'administer site configuration', but I get an error message on screen and the login will not work for the 'staff' user.
Here's my edited code:
Any hints?
============
Drupal Core Maintainer for "Out of the Box" Initiative.
silly me,
silly me, I was trying to login as the wrong person. Great little hack this. Thanks.
============
Drupal Core Maintainer for "Out of the Box" Initiative.
nice ! thanks
nice ! thanks
Further advice, please
This hack is great for us who can't yet use D7, thanks a lot!.
I'd like to know if you experienced the same as me: I used the hack and everything goes ok, but in the login page, i got the primary links displayed(not the access to the pages, just the links being displayed), which i am not supossed to have access (because in that moment i am an anonymous user). Is this supossed to happen?.
I'll try to override the login page with a custom template, so i can get rid of the primary links (using zen subtheme, by the way).
If someone finds out a simpler way to get rid of the links, i'd really like to hear about it!.
Update: I used the "page-user.tlp.php" template (copied from page.tlp.php) to override the login page and get rid of the links. Works as intended, but still have the feeling that there should be something simpler to get the same result.
Don't hack core!
Here is a small module that offers a permission for 'Use the site in maintenance mode'.
offline_access.info
offline_access.module
I installed and enabled the
I installed and enabled the module but saw no new additional option on the User Permissions page. Should I be looking elsewhere?
comment deleted by author
comment deleted by author
Thanks for making this small,
Thanks for making this small, but very handy module!
greetings,
Martijn
Don't see new permission...
I don't see any permission too. What can be wrong here?
Look for the "Use the site in
Look for the "Use the site in maintenance mode" permission
Super nice :)
This small module is wonderful.
Very useful module, bravo ! I
Very useful module, bravo !
I have just a "remarque", the message box "Operating in off-line mode." does not appear any more...
Stève
Showing "off-line" message
Here is a little change on Grendzy's module to address your issue regarding the "Operating in off-line mode" message, which is relevant:
offline_access.info
offline_access.module
Remember that you should not use the PHP closing tag in Drupal.
Beware to add final ?> to the
Beware to add final ?> to the module file, this throws an error and lot of problems on site's behaviour. Here's the error:
warning: Cannot modify header information - headers already sent by (output started at /home/xxx/domains/xxx.com/public_html/modules/offline_access/offline_access.module:19) in /home/xxx/domains/xxx.com/public_html/includes/common.inc on line 148.Needs confirmation.
it should not be a
it should not be a problem..
be careful maybe you entered a space after the ?>
Don't put a closing tag
PHP does not require a closing tag and it is, actually, advisable not to put the PHP closing tags when in Drupal.
Perfect
Just the thing I was looking for, thank you.
--
... I mind
"version is incompatible with the 6.22 version of Drupal core"
Curses, foiled again! This is the error message I get when I went to enable your great little offline_access.module.
Is there an easy fix? I'd really like to use this module.
Excellent Module
Thanks, Grendzy! Excellent module!
beautifully coded, thumbs up
beautifully coded, thumbs up
That's a tiny module but it
That's a tiny module but it works like a charm. Thanks a lot for this!
great
Super-handy module, thanks.
Strony www Bydgoszcz
another solution, use a
another solution, use a simple theme for your site, with a message in your page.tpl.php like: Site in maintenance...
Then allow user themes, edit each user and make availabe for them the theme in which you are working.
For some cases can be a solution.
Thanks