By sgware on
I am working on a module to add multiple superusers (as if multiple users had uid 1) to a Drupal site. But before I can start overriding functions, I need to know which ones to override and how to change them. For experimentation purposes, I am modifying core code to see if I can achieve what I'm trying to do.
This is a slightly modified version of user_access() from modules/user/user.module. In theory, it should allow uid 2 to have all the same permissions that uid 1 has, but it does not work.
Is this even the right function to be changing? Are there more than this that I need to change?
function user_access($string, $account = NULL) {
global $user;
static $perm = array();
if (is_null($account)) {
$account = $user;
}
// User #1 has all privileges:
if ($account->uid == 1) {
return TRUE;
}
// User #2 has all privileges: <<<< HERE IS MY CODE
if ($account->uid == 2) {
return TRUE;
}
// To reduce the number of SQL queries, we cache the user's permissions
// in a static variable.
if (!isset($perm[$account->uid])) {
$result = db_query("SELECT DISTINCT(p.perm) FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN (%s)", implode(',', array_keys($account->roles)));
$perm[$account->uid] = '';
while ($row = db_fetch_object($result)) {
$perm[$account->uid] .= "$row->perm, ";
}
}
if (isset($perm[$account->uid])) {
return strpos($perm[$account->uid], "$string, ") !== FALSE;
}
return FALSE;
}
Comments
Umm, why?
First, I would never recommend hacks to core. It's a sure-fire way to end up in Drupal Hell.
Secondly, why not just set up an "administrator" role and grant access to everything to that role? This is what I do and it works fine. This is a whole lot simpler than doing hacks and custom code.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru
As stated above, this is not
As stated above, this is not a permanent solution. I will write this into a module or something later, but right now I can't even figure out what functions need to be overwritten or changed or how to change them.
This is step 1 in a long series of steps to have an admin role span all sites on a multi-site setup where the user_roles table is not shared. Please don't criticize my methods yet... I know they are bad form, and I plan to change them. Right now I just need to know why this code is not working.
It does work!
Oops, apparently this code does work, but you'll need to clear the cache first. I thought the cache would be cleared after submitting the modules page, but apparently it is only cleared if you actually change the settings on one of your modules and then submit it.