On drupal sites, anonymous comment submitters have '(not verified)' listed next to their name. Some, like me, who have a blog where I am the only user don't want this to display. So, here's how we remove it.
Note: These instructions are for themes using the phptemplate engine. If you're using the default engine in drupal 4.7 or 5 you are using phptemplate.
The commenters name here is themed by the function theme_username. This means we can theme it how we want with the function phptemplate_username in our template.php file. I copied the existing theme_username function and modified it. Here is what it looks like:
<?php
function phptemplate_username($object) {
if ($object->uid && $object->name) {
// Shorten the name when it is too long or it will break many tables.
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) .'...';
}
else {
$name = $object->name;
}
if (user_access('access user profiles')) {
$output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
}
else {
$output = check_plain($name);
}
}
else if ($object->name) {
// Sometimes modules display content composed by people who are
// not registered members of the site (e.g. mailing list or news
// aggregator modules). This clause enables modules to display
// the true author of the content.
if ($object->homepage) {
$output = l($object->name, $object->homepage);
}
else {
$output = check_plain($object->name);
}
//$output .= ' ('. t('not verified') .')';
}
else {
$output = variable_get('anonymous', t('Anonymous'));
}
return $output;
}
?>The only change I made was to comment out the (not verified) line. You can delete this if you want.
You might be thinking, "But you blogged on this last year". I did and it was before I was intimately familiar with the drupal theme system. I gave bad advice so ignore that post. It works but it's not the drupal way and not easily maintainable. I had to redeem myself by explaining the right way.


very nice! Did you add this
very nice! Did you add this to the d.o. handbook?
Too complicated
It's too bad that for such a small change, which is (in my experience) desirable for a lot of non-community websites, you have to make such complicated changes.
that's what makes Drupal extensible
It may seem big (really you just cut and paste this block into your template.php file). But if there was a switch in the UI for every little thing like this (and there are hundreds of little things like this), the UI would be completely unusable.
These hooks are what make Drupal extensible, and keep it manageable.
editing core vs. coding changes in themes
Without even reading your post from last year, I assume you did some edits against Drupal core. Many of us have done this and then learned what a pain it is to update Drupal later while tracking the core hacks. I have also found that doing whatever you can via a theme is the best way... At least start with the theme and see if that will give you the results you need. If that doesn't work, you may need find an existing contrib module that will do what you want.. or at least close enough that you can tweak it to your liking.
Thanks for the code!
Shrop
Copying the function to the
Copying the function to the template.php and modifying it there is certainly best practice, but in my case I simplified this to one line in comment.tpl.php:
<div class="submitted"><?php print str_replace('(not verified)', '(visitor)', $submitted); ?></div>Thank you so much for
Thank you so much for explaining this. I was racking my brains for a few days until I found your solution. =)
Thanks
Thanks . I'm using it on my website. Still I have a question. All functions like theme_whatever can be modified in phptemplate_whatever ?
Yes
Yes, that's one of the great bonuses about the theming system.
Thanks, this helped alot. I
Thanks, this helped alot. I a newbie PHP coder.
-Jake
my site:
dual action cleanse
Thanks, Here's A Simpler Alternative?
Hiya Matt,
Thanks for writing that up, I'd been searching around for a way to handle this since the commenters on my blog started hassling me about it.
Great solution, I thought it could be simplified a fraction, by only including the section of the theme_username function that adds the 'not verified' text to the username.
This can then be included into the template.php file and if changes or updates are made to the main theme.inc they'll still get included. Here's the code I added to template.php:
function phptemplate_username($object) {/* Section of code from theme_username() in theme.inc which styles
comments for users that aren't logged in, but do have names. Note
that the '(not verified)' text isn't added */
if (!$object->uid && $object->name) {
if ($object->homepage) {
$output = l($object->name, $object->homepage);
}
else {
$output = check_plain($object->name);
}
}
/* Otherwise execute the theme function as normal */
else {
$output = theme_username($object);
}
return $output;
}
could we replace "not verified" with ip address?
I'm looking for a way to deal with my blog full of "Guest" comments. I'd like to display the ip address instead of not verified so people can see if "Guest" is all one user or not.
Is That Safe?
I'm wondering if that's a safe move. For example, most of the people on internet connections in the US are on dynamic IP address, meaning they change from time to time. Also, there are a number of people who have laptops and go to different wifi spots so their IP address changes.
So, IP address may not be the ideal solution.
On a different note, IP addresses can be traced to approximate location. So, sharing that will let people narrow down where someone physically lives. Is that a good type of information to give out? This is an ethical question that needs to be answered.
I'm wondering if moderation is a better solution than just giving out personal information (like and IP address). You can add a note to comments letting people know how they tie together.
It could give only the beginning of an IP address
It could give only the beginning of an IP address.
Like 11.22.x.x.
I doubt anyone would be concerned his/her privacy is violated then.
What Does That Tell You?
I don't know if that will tell you what you are looking for. For example, everyone in the same city or town may have an IP address that starts like that. So, if you have more than one person commenting from one local area they will all show up like that.