On the Story pages, users that are not logged in are prompted with a link to "Login to post comments." (Garland theme)

I do not want my users to even know that they CAN post comments, so I want to remove this line from beneath both the original Story post and the subsequent Comments.

I have rudimentary PHP skills, decent CSS and HTML skills. Any ideas?

Comments

JirkaRybka’s picture

As for me, I only think the links on teasers (front page) are a bad thing - just tried to sort this for Drupal 6: http://drupal.org/node/169938 - let's see if this one will be accepted into core. Perhaps the patch will also work for Drupal 5, the code doesn't seem to be changed.

Removing links also on full node-pages means in fact disallowing comments at all (no way to reach the comment-submit form left), so I don't see how this is useful. If you want to disallow comments at all, just do it in Access control, or even disable comment module completely. If you want it only for certain content types, set the workflow on these content types to have comments disabled by default (which is also possible on single nodes if you're logged in as admin). Just look at the admin pages, there's a lot of useful settings.

mihai.moldovan’s picture

I know this is a verry old subject, but I`ll say what i`ve did anyway.
using a editor program: nano or vim
vim /rootdrupalfolder/modules/comment/comment.module
line: 2396,9 87%
replace it with the following:
return t(' ', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));

ILIKECAPS’s picture

my problem:

On my website, i have people "rating" items, but only a few people who I, as the admin, register on the site. In the permissions, i have only these folks set to be allowed to comment on the Story posts.

People who want to read the ratings come to my site, and never log in, they only navigate to the page they are interested in, and they read the comments that the "raters" make.

The problem is that people who are not "raters" see a link under each Comment and under the original Story post that says "Login to post comments" (because they do not need to log in, they are simply visitors, not "raters." People then think that they, too, can post comments, and they try, but are unable to log in resulting in an inbox full of emails asking why they can not comment on an item. I have to write back that i do not want them to write a comment, i only want them to read the comments posted by those i allowed.

So, to remedy this, i simply want to remove the prompt to "Login to post comments" from the pages all together for folks that are not logged in, as the only ones that CAN log in are the folks I allow to comment.

Unfortunately, the admin panel has no setting to remove the link to login altogether from those spots.

I hope that explains my problem. I have not been able to find any documentation of anyone trying to do this before. I truely appreciate all comments or suggestions on this. The drupal community is among the best on the web!

JirkaRybka’s picture

Then, you need to change code: Find your modules/comment/comment.module file, open it in a text-editor (like wordpad or the like), and search for the text you don't want to see on pages. You need to comment out (or delete) a bit of code, something like:

//    if (variable_get('user_register', 1)) {
//      return t('<a href="@login">Login</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', $destination), '@register' => url('user/register', $destination)));
//    }
//    else {
//      return t('<a href="@login">Login</a> to post comments', array('@login' => url('user/login', $destination)));
//    }
    return '';

The added 'return' is just for case, to ensure nothing to show - I didn't test this.

You can either edit the original file (which is quick but unclean, and requires you to redo the change after every unpgrade), or override that function in your theme properly by placing its copy into your template.php file (whole function!), renaming it to "phptemplate_[name]", and changing as needed. I think (not tested!) that it should look like this (added to 'template.php' in your theme's folder / create the file if not existing yet, with <?php line at the begin):

function phptemplate_comment_post_forbidden($nid) {
  global $user;
  if ($user->uid) {
    return t("you can't post comments");
  }
  else {
    // we cannot use drupal_get_destination() because these links sometimes appear on /node and taxo listing pages
    if (variable_get('comment_form_location', COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
      $destination = "destination=". drupal_urlencode("comment/reply/$nid#comment_form");
    }
    else {
      $destination = "destination=". drupal_urlencode("node/$nid#comment_form");
    }

//    if (variable_get('user_register', 1)) {
//      return t('<a href="@login">Login</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', $destination), '@register' => url('user/register', $destination)));
//    }
//    else {
//      return t('<a href="@login">Login</a> to post comments', array('@login' => url('user/login', $destination)));
//    }
    return '';

  }
}

But still, you'll probably need to check on every upgrade, whether this copied code is in sync with core's possible new changes.

ILIKECAPS’s picture

Wow, Jirka, I really appreciate this. After talking to some of my partners, the consensus is to simply change the wording to say "Reviewers login here to comment". Thus, no need for the "comment out tactic." With this knowledge of the inner workings, however, there is alot of other changes that can be made. A huge help! THANKS for finding the spot in the code for me to makes that change!

Hopefully others with the same problem can use this thread :-)

fransuave’s picture

If anyone is wondering, I can confirm that this works for 5.2.

Cheers,

.............................
Francis Care
www.fralius.com.au

chlobe’s picture

bookmarking

johnhanley’s picture

The issue of removing "Login or register to post comments" just came up for me today (for a Drupal 5 website) and overriding the default theme as JirkaRybka pointed out in his comment is indeed the way to go about it. From Drupal 5 forward there's a variety of ways to override the default output so there's very little reason one would ever need to hack the core.

-------------------------------------------------------

"If you don't read the newspaper you are uninformed;
if you do read the newspaper you are misinformed."
-- Mark Twain

vaneramirone’s picture

And a part of a category i'm taking involves this specific subject and that i am researching for data to use in associate degree approaching report. Your post is de facto helpful; does one have any others on this topic? You can find out more about blog curation.

doublejosh’s picture

I wanted to remove the "Add Comment" on node teasers...

NOTE: Simple Review module users, the $links[comment_add] key is altered to be "Review this Article," but you can nip the issue in the bud at the comment.module level :)

Go to about line 320 in comment.module and find this...

if ($node->comment == COMMENT_NODE_READ_WRITE) {
  if(!teaser) {      // -------- Here is my teaser test
    if (user_access('post comments')) {
      $links['comment_add'] = array(
        'title' => t('Add new comment'),
        'href' => "comment/reply/$node->nid",
        'attributes' => array('title' => t('Add a new comment to this page.')),
        'fragment' => 'comment-form'
      );
    }    // -------- This ends the teaser test 
    else {
      $links['comment_forbidden']['title'] = theme('comment_post_forbidden', $node->nid);
    }
  }
}

Add in the $teaser test as an if statement. (I've marked it in code comments.)

faqing’s picture

Thanks Josh,

It does not work with Drupal 6.

mybinaryromance’s picture

actually line 2 is supposed to be
if(!$teaser) { // -------- Here is my teaser test
won't work without the $...

peace, bonzo

joachim’s picture

There's a bug open on this... people who can't log in anyway, or couldn't post comments if they did log in, shouldn't be shown that message.

fletchgqc’s picture

Hi,
I just found this post as I had the same problem and have figured out how you are "supposed" to do it (in Drupal 6).

First option: override the comment_post_forbidden in your theme, as someone mentioned above. Actually all you need to include in your function is the following:

/**
 * Theme a "you can't post comments" notice.
 *
 * @param $node
 *   The comment node.
 * @ingroup themeable
 */
function THEME_NAME_comment_post_forbidden($node) {
	return '';
}

However I discovered this leaves some HTML <ul> tags behind which mucked up the alignment of my other links. So I wrote my own module (if you've never done it, this takes about 30 minutes of studying the module developers handbook to understand). Then I put this function in the module which really removes the item from the links and voila, problem solved:

/**
* Implementation of hook_link_alter()
* removes "login to post comment" links
*/
function MODULE_NAME_link_alter(&$links, $node) {
  foreach ($links AS $module => $link) {
    if (strcmp('comment_forbidden', $module) == 0) {
      // it's a "login to post comment" link, remove it
      unset($links[$module]);
    }
  }
}
Fayna’s picture

I created a module with your function and it worked! :-) For story nodes with no comments on them, how would I display a simple "0 comments" link where the "login or register to post comments" used to be?

ngstigator’s picture

If you go this route your non-registered visitors will not know what they need to do to post a comment (i.e. register and log in). Luckily, theme_comment_wrapper() to the rescue!

Something like this in your template.php will work:

function phptemplate_comment_wrapper($content) {
  $output = '<div id="comments">';

  if (!user_access('post comments')) {
    $output .= '<div class="comment-join">Please ' . l('log in', '/user/login') . ' or ' . l('register', 'user/register') . ' to post comments.</div>';
  }

  $output .= $content;
  $output .= '</div>';

  return $output;
}

…although you may have to alter your logic and verbage to suit your site's comment policy.

Matt B’s picture

<?php
function MODULE_NAME_node_view_alter(&$build) {
  unset($build['links']['comment']['#links']['comment_forbidden']);
}
?>
eaajithe’s picture

CSS trick worked for me :)
Just find the wrapper DIV and
div.links_foot{
display:none;
}

Wayne_Luke’s picture

Lot of PHP and suggestions here... Why not just edit the content type so that comments are disabled. If they are disabled then they won't get prompted to login and leave comments.

fletchgqc’s picture

Answer = business-style site.

I want people that know how to log in to be able to post comments.

I don't want people that don't know how to log in to realise that they can log in.

brainites’s picture

Sadly or woefully the comment settings for webform for D7 hasn't got any click-to-disable comment. I think this is one of the ridiculous things in Drupal. I use CMSes a lot but such things freak me out when I land to do anything in here. Could have done it in 2 secs elsewhere. Anyway it is part of the fun.
Later found the simplest solution. http://drupal.org/node/170065#comment-4793040

Fayna’s picture

casperl’s picture

One would think that not displaying a silly message that appears to anonymous visitors to a a site that invites them to log in to post comments, will be a setting that can be toggled on or off.

But no, EVERY solution above barring disabling comments totally for the content type is a convoluted hack!

And yes, googling around, this issue has been around since Drupal 4.x and the solution, time and again, is to go and hack Drupal core by commenting out the appropriate lines in the comments module. Alternately to go and write a module. Or editing a php template file in ways that even I don't understand what is going on.

AM I THE ONLY PERSON THAT THINKS THIS IS ABSOLUTELY RIDICULOUS?

While a lot is being done to "supposedly" make Drupal easier, there are a lot of simply crazy stuff that just remains and which makes Drupal difficult to use. And this is a very good example!

Only a small subset of people have the technical skills to implement the changes above. And in reality - EVERY solution above is a hack.

I despair, because those with the technical skills are chasing a target called Drupal 7, hopefully releasing it before Christmas this year. In reality I will probably never be able to upgrade some Drupal 5 websites since some critical modules that do exactly the job I want it to do, will in all likelyhood never be upgraded to Drupal 6 and beyond.

Really, I despair - this is supposed to be something so easy, yet it is so confoundedly difficult!!!

Casper Labuschagne

ferrangil’s picture

Subscribing.
A "Login to post comments" is appearing below the text of a news that comes from a view (in the front page).
I went to the news content type to disable comments (because there's not need to have them now) but its still there!
I don't want to hack that.
Will see...

brainites’s picture

In my opinion the developers here are thinking too complex. The solution is just a click away. http://drupal.org/node/170065#comment-4793040

jason2009’s picture

there are Methods to do.

1. you can edit the content type, without user can post comment or Choose (comment write or read)none when you post story pages.

2. comment-type.tpl.php type is stroy, set $content = null in it.

Freee, sharing images--acoshare acobox!

webmaster.netbuild’s picture

Ya really it is....

--------------------
Carolina Barbeque - Smithfield's Chicken 'N Bar-B-Q – the finest Eastern North Carolina-style BBQ.

tomychad’s picture

Its a shame that such a beautiful system like Drupal
has these minor inconveniences. Hacking through the
source code to do such a small job is pretty dumb as
once I update the site to the latest version changes
are gone and I have to do them again.

Tomy, Jobs Search

johnhanley’s picture

All content management systems have "minor inconveniences". Drupal provides a variety of ways to override the default output without hacking the source files. Doing so is the lazy man's route and you should take time to learn how to do it right.

picxelplay’s picture

They are not "minor inconveniences." Drupal has a basic "core," and (with knowledge) you can override what you wish. There is no reason the hack the core when you can do simple overrides. If they are not so simple for you, well then, you just need to study and learn Drupal more.

----
Sudo Kill Cylons

Frederic wbase’s picture

You just need to change the permisions in admin/user/permissions of the comment module. search for "post comments" and "post comments without aproval"

cheers

http://www.wbase.be twitter: @wbase_be

abp’s picture

I might have misunderstood the question, but what I do (in Drupal 6) for content type I've created, is go to:

Administer » Content management
Content
Go to the particular Page, Story, etc and click on edit. Then scroll down to "Comment Settings". Choose "disabled".

brainites’s picture

You gave the perfect solution. I think most developers thing too complex and end up complicating their lives. Wondering why all the hacks with custom modules were given when the solution is just a click away. Thinking simple is always the best thing to do as a developer. Very informative article. Thanks a bunch!

kingandy’s picture

This issue originated in 2007, when Drupal did not include that feature ;)

++Andy
Developing Drupal websites for Livelink New Media since 2008

johnhanley’s picture

@brainites, that simple "click away" solution was brought to you by some developer taking a previously complex modification and making it easy to configure through the interface.

ervan.salin’s picture

In your theme template file "template.php" ( in a custom template ) add this theme function and set the value off the element called "comment forbiden" to empty it or unset it.

function YORTHEMENAME_preprocess_comment(&$variables, $hook) {
  if((user_is_anonymous() === TRUE) 
  && (isset($variables['content']['links']['comment']['#links']['comment_forbidden']) 
  && (!empty($variables['content']['links']['comment']['#links']['comment_forbidden'])))) {
    // Set to empty
    $variables['content']['links']['comment']['#links']['comment_forbidden']['title'] = '';

     // OR unset it
    unset($variables['content']['links']['comment']['#links']['comment_forbidden']['title']);
  }
}

This remove "Login to post comments." under all comments, but not above the form.

stuman’s picture

Maybe I have a slightly different issue, but I wish to view and maintain comments on my site as administrator, but not even have the fact that comments module is installed visible to visitors. I have NO login users, and have to overtly access the login page with ?q=user on the URL.

What I believe the OP was looking for was a way to drop the prompt but still allow comments for authenticated users. By disallowing comments for authenticated users as well as visitors, I got the prompt to go away. It needs to be a configurable option of the comments module whether or not to prompt for login.

andrejsagaidak’s picture

Is there a simple way I can change the wording of the "Read more" link in the teasers? I'd like to change it to "Read more …" -- but I need to know where to find it first. Thanks!