Remove "login to post comments" prompt from Story pages

ILIKECAPS - August 24, 2007 - 05:25

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?

A partial solution

JirkaRybka - August 24, 2007 - 07:01

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.

A Better Explination:

ILIKECAPS - August 25, 2007 - 06:10

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!

Ah well...

JirkaRybka - August 25, 2007 - 08:48

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.

Perfect

ILIKECAPS - August 25, 2007 - 13:55

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 :-)

This works for Drupal 5.2...

fransuave - October 2, 2007 - 08:18

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

Cheers,

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

tracking

chlobe - October 26, 2007 - 13:00

bookmarking

theme override

Bacteria Man - January 4, 2009 - 02:01

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

Getting rid of teaser comment link

doublejosh - February 22, 2008 - 00:35

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.)

Thanks Josh, It also works

faqing - February 22, 2008 - 03:56

Thanks Josh,

It does not work with Drupal 6.

There's a bug open on

joachim - February 22, 2008 - 12:29

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.

The recommended way

fletchgqc - May 24, 2008 - 04:40

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:

<?php
/**
* 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:

<?php
/**
* 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]);
    }
  }
}
?>

I created a module with your

Fayna - May 31, 2008 - 04:57

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?

If you go this route your

chris_five - September 10, 2008 - 23:50

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:

<?php
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.

Lot of PHP and suggestions

Wayne_Luke - May 24, 2008 - 14:56

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.

Answer = business-style

fletchgqc - May 31, 2008 - 05:12

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.

Sorry. See

Fayna - May 31, 2008 - 04:58

A call for sanity!!!!

casperl - November 5, 2008 - 22:03

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

Subscribing. A "Login to

ferrangil - November 21, 2008 - 13:59

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...

HI, ILIKECAPS

jason2009 - January 4, 2009 - 02:31

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!

 
 

Drupal is a registered trademark of Dries Buytaert.