Last updated August 29, 2014. Created on December 18, 2010.
Edited by pc-wurm, devoted.designer, danreb. Log in to edit this page.

Description

Sometimes, for security reason we don't want to show the super admin (user 1) in the user listing at the profile page, this user listing can be view if we visit our website via www.example.com/profile , this page is generated if we enabled the profile module in the core-optional group at the module admin page.

Drupal 6.x

Using a very simple conditional statement in PHP we can hide the user 1 in this list, here's the step :

  • Step 1 - Inside your theme folder create a template file called profile-listing.tpl.php , note, don't create if you already have this file in your theme, skip this step
  • Step 2 - Copy the code below and paste it to your profile-listing.tpl.php :
    <?php if($account->uid!=1) : ?>
    <div class="profile">
      <?php print $picture; ?>

      <div class="name">
          <?php print $name; ?>
      </div>

      <?php foreach ($profile as $field) : ?>
        <div class="field">
          <?php print $field->value; ?>
        </div>
      <?php endforeach; ?>

    </div>
    <?php endif; ?>

      

  • Save the file and visit admin/build/themes and click save configuration, this way, we allow our Drupal site to re-scan our theme directory and registered the new template file that we add.
  • To make sure, clear the cache in admin/settings/performance
  • Visit your website profile page like www.example.com/profile, you can now see that user 1 doesn't appear anymore in user listing page.
  • done

If you already have profile-listing.tpl.php in your theme directory then just wrap it in the if statement as shown in the above code:

  <?php if($account->uid!=1) : ?>

   // here goes all the original content of your profile-listing.tpl.php
  
  <?php endif; ?>

 

so this mean, we just need to insert this code at the beginning

  <?php if($account->uid!=1) : ?>
 

and this

  <?php endif; ?>

at the end of the original code in your profile-listing.tpl.php

Note : If for some reason you want to hide user 1 in "Who's online" block or "Who's new" block, and or don't want anyone to delete/edit user 1 , install userone module: http://drupal.org/project/userone

You may want to look also for userprotect module if you want different approach : http://drupal.org/project/userprotect

Drupal 7.x

To hide User 1 from the users table in the People Administrative Menu linked in the Administrative Toolbar:

ATTENTION: The following code ise VERY VERY VERY BAD PRACTICE! Please ignore it and never hack the core. I don't know why this is added to the documentation pages.

  • Step 1 - Go to your website's root folder, then to modules\user folder.
  • Step 2 - Search for the user.admin.inc file, and open it with any text editor application.

    Notepad++ is definitely my choice

  • Step 3 - Scroll down to line 161.

    There you will find the following code:

    <?php
     $query
    ->condition('u.uid', 0, '<>');
    ?>

    Simply add a new line of code under the above one. The new line is:

    <?php
     $query
    ->condition('u.uid', 1, '<>');
    ?>

    * of course, add the code without the php tags

    Save your changes and Viola!!! User 1 is hidden.

So, to summarize what happened.
Simply the new line of code just adds a new condition to the fetched query to remove User 1 from it.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

devoted.designer’s picture

Hi, this works on Drupal 6.x but it doesn't seem to do the trick on Drupal 7 !
Any suggestions to make it work on Drupal 7 ?
Please HELP!!!
Thanks in advance.

danreb’s picture

You can read the full information in this thread - > http://drupal.org/node/874026

danreb’s picture

That said, I think the best way for D7 is to use views to create a profile listing page and remove user 1 in the list, this will probably achieve the same result.

devoted.designer’s picture

Thank you "danreb".
Although i'm a bit new to drupal, i'll surely try the views after a search about them and how they're used.

elgandoz’s picture

With views you can't achieve the MAIN function of the users page (at least for me): Block or Unblock automatically registered user!! I've this problem since i use Drupal (6).

devoted.designer’s picture

The registered users are not my problem!
I'm just trying to hide the User 1 from the table in the People page.
I think I'm going to edit the core code myself to achieve that, but ... anybody knows where is the related code? Under which file name is it under?

devoted.designer’s picture

Hey there,

I worked with views and knew how to set up one, but how could i replace the new one (containing no user 1) with the original one in the People Block?

Thanks in advance.

1timer’s picture

sub

devoted.designer’s picture

I'm a bit new to Drupal, so I would appreciate a little more explanation.
What is a "sub"? How to use it?
Thanks.

devoted.designer’s picture

Hey guys ...

Finally, I've managed to solve the problem with a simple tweak in the core code.

Refer to the main topic above to check out my new additions to the topic
(Related to Drupal 7.x).

Happy Programming ;)

josepvalls’s picture

With Views you can overwrite system paths.

nicholasstuartwilson’s picture

This core hack works fine but admin can not see them self in the list, to allow that, try...

<?php
 
global $user;
 
$user_start = $user->uid == 1 ? 0 : 1;
 
$query->condition('u.uid', $user_start, '<>');
?>
warmth’s picture

It doesn't work for me on 7.17

Prototyping Sr. Engineer at @smartmatic | @MarkSoMedia COO | @NokiaNewsHQ, @LoveMyNokia & @gourmeturbano writer | Photography, Movie, Music & Sports buff