Voting starts in March for the Drupal Association Board election.
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.
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
<?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/themesand 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
- 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.
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) : ?>
<?php endif; ?>
at the end of the original code in your
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
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
Step 2 - Search for the
user.admin.incfile, 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.