aside from the admin, there are other roles created by the admin who could also administer and manage users. and because of this, there's a need to hide the admin from being viewed among the list of users and operators. there's a good reason for resorting to this.

in this connection, how do we go about this? what is the best solution for implementing this? please help..

Comments

jet_lee’s picture

i'm sure someone here has got the answer. could you pls share to us the solution? pls help...

the entire drupal community would be very grateful.

detectedstealth’s picture

Hi there is a few ways to hide the administrator from the users list.

The way I did it was:
[Note: There is also a tutorial that may provide you with a better way of doing this. It is located in the theme developers guide under customizing the user listing page I think.]

// This will stop the root user from showing up in the listing page. This code goes in your profile_listing.tpl.php file.
if($user->uid != '1') {
  // Inside here write your custom theme code.
}

(If your referring to removing the admin from showing up every where on the site, that is a bigger problem and I am still trying to figure that one out)

vrc3’s picture

I know modifying drupal core is supposed to be a no-no, but this is a really easy one. Find the line in profile.module that looks like:
$result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);
It's in the function "profile_browse" and on line 503 in drupal 5.2.

Change it to:
$result = pager_query('SELECT uid, access FROM {users} WHERE uid > 1 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL);

Then user 1 doesn't show up on www.example.com/profile

You'll also need to leave all admin user's profile fields blank so they don't show up in the other profile pages, and don't post anything as admin.

This works for me, but of course it won't work if you have more than one admin account. And there's nothing to prevent someone from going to www.example.com/user/1

Valerie
www.beerreviewjournal.com

Pierco’s picture

I wrote a custom module (for 6.x) to achieve this:

hide_admin.info:

name = Hide Admin
description = Hide administrator account (uid 1) from the users list.
package = CSETID
version = VERSION
core = 6.x

And hide_admin.module:

<?php

function hide_admin_form_alter(&$form, $form_state, $form_id) {
  global $user;
  if($form_id == "user_admin_account" && $user->uid != 1) {
    $keys = array('name', 'status', 'roles', 'member_for', 'last_access', 'operations');
    foreach($keys as $key) {
      unset($form[$key][1]);
    }
    unset($form['accounts']['#options'][1]);
  }
}

?>

Hope this helps.

pimpedlightedsaber’s picture

Did you have to anything beyond making the module and enabling it?

I tried using this instead of changing the code in profile.pages.inc, and I copy/pasted the .info and .module code, and enabled the module, but I still get the admin on my user list.

Pierco’s picture

Try to do a print_r and check user #1.

function hide_admin_form_alter(&$form, $form_state, $form_id) {
  global $user;
  if($form_id == "user_admin_account" && $user->uid != 1) {
    $keys = array('name', 'status', 'roles', 'member_for', 'last_access', 'operations');
    foreach($keys as $key) {
      unset($form[$key][1]);
    }
    unset($form['accounts']['#options'][1]);
    print_r($form);
  }
}
Anonymous’s picture

Works for me, perfect solution.

Thanks sirozz

karizmatikalem’s picture

This Fix will not workin for me.

I have drupal 6.19

danreb’s picture

danreb’s picture

If you want to see it working, login as another user or modify the code like this


<?php

function hide_admin_form_alter(&$form, $form_state, $form_id) {
  global $user;
  if($form_id == "user_admin_account") {
    $keys = array('name', 'status', 'roles', 'member_for', 'last_access', 'operations');
    foreach($keys as $key) {
      unset($form[$key][1]);
    }
    unset($form['accounts']['#options'][1]);
  }
}

?>

note I removed && $user->uid != 1 inside the PHP if statement, this way even user 1 can't see himself from the list of user in admin/user/user

ranieri machado’s picture

With additional features

function hide_admin_form_alter(&$form, $form_state, $form_id) {
  global $user;
  // IF code to hide administrator from listing
  // Posted by Pierco on February 15, 2010 at 2:22pm
  // drupal.org/node/154404
  if($form_id == "user_admin_account" && $user->uid != 1) {
    $keys = array('name', 'status', 'roles', 'member_for', 'last_access', 'operations');
    foreach($keys as $key) {
      unset($form[$key][1]);
    }
    unset($form['accounts']['#options'][1]);
  }
  // IF code to manage filters panel
  else 
  if($form_id == "user_filter_form" && $user->uid != 1) {
    // Hide administrator from role filter 
//    unset($form['filters']['status']['filters']['role']['#options']['3']);
    // Hide whole filters panel 
    $form['#attributes'] = array('style'=>'display: none;');
  }
  else
  // IF code to deny access to /user/1/edit. 
  // Posted by davidgenetic on January 19, 2012 at 6:33pm    
  // drupal.org/node/154404    
  if($form_id == "user_profile_form" && $user->uid != 1 && $form['#user']->uid == 1) {
    drupal_access_denied();
    drupal_exit();  			
  }  
}
TimMachine’s picture

What good does hiding user 1 from the list if someone can still just go to http://somesite.com/user/1/edit?

If a role has "Administer User" permissions he can edit the admin account and then give himself admin privileges.

There has to be a better solution.

jiri.motejlek’s picture

exactly. Im looking for a solution of this too. I found module Administer Users by Role, it should do exactly what we want. But it appears to have some bug, in order to add some role permission to edit some other users (belonging to a certain role) you have to give this role "Administer Users" privilege first, but since then, users in this role can edit whoever they want, including admin.

davidgenetic’s picture

In addition to Pierco's function you can add the following to it to deny access to /user/1/edit.

if($form_id == "user_profile_form" && $user->uid != 1 && $form['#user']->uid == 1) {
  drupal_access_denied();
  drupal_exit();  			
}

Cheers.

christopher james francis rodgers’s picture

I notice that you posted your issue some time back.

Please be aware that you posted your topic
in the 'Deprecated' (no longer used) section of the forums.

That is likely why you never got any replies.

Please note that this "topic" had been "Deprecated"
and will not be seen by typical forum users.

The "Deprecated section of the Forums"
is not actively used and is intended as a library archive
collection of old posts.

The only notice it will get is via notifications
to this topic's 'followers'.

Please "Post new Forum topic" in one of the active forums.

In your case I recommend that you post in the forum
-- Post installation http://drupal.org/forum/22


All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *

arvindranabhat’s picture

I am also looking for a solution. I came across this thread through a friend. WIsh Drupal had tons of plugins like Wordpress.

alex’s picture

Hilariously enough, I also named the module Hide Admin (sorry Pierco! I found this thread too late)
It works for my situation. Anyone who finds it useful is welcome to use it at their own risk.