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 tomodules\user
folder.Step 2 - Search for theuser.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:
$query->condition('u.uid', 0, '<>');
Simply add a new line of code under the above one. The new line is:
$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.
Comments
What About Drupal 7 ?
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.
Profile module is deprecated in Drupal 7
You can read the full information in this thread - > http://drupal.org/node/874026
You can use views
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.
i'll surely try that
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.
With views you can't achieve
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).
Not What I Really Wanted
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?
Views in Users Block!
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.
sub
sub
?!
I'm a bit new to Drupal, so I would appreciate a little more explanation.
What is a "sub"? How to use it?
Thanks.
Solved at last!!!
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 ;)
With Views you can overwrite
With Views you can overwrite system paths.
to allow admin to still see themselves in this list
This core hack works fine but admin can not see them self in the list, to allow that, try...
It doesn't work for me on
It doesn't work for me on 7.17