This is very good module for drupal 7 and I like to add additional feature to it.I want node authors[Not administrator user,Normal registered user who has permission to add content] to delete the unwanted comments under their content.

I have added and edited some code in this module to add that functionality.

In line 236,added the following code

//adding permission to delete comments of own content
'delete comments of own content' => array(
      'title' => t('Delete comments of own content'),
      'description' => t('Allows a user to delete comments of own content'),
    ),

In line 254,replaced the line

access = ($user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && (user_access('delete own comments') || user_access('administer comments')));

and added the following lines

$node = node_load($comment->nid);  
  //commenting this line
  //$access = ($user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && (user_access('delete own comments') || user_access('administer comments')));
//permission to check the current user can access the delete comment page
   $access = ($user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && ( user_access('delete own comments') || user_access('administer comments') ) || ($user->uid && $comment->status == COMMENT_PUBLISHED && ($user->uid==$node->uid) && (user_access('delete comments of own content') || user_access('administer comments') ) ));
  

In line 285,added the following lines

global $user;  
  if($user->uid && ($user->uid==$node->uid)){
	  	$comment->content['links']['comment']['#links']['comment-delete'] = array(
	      'title' => t('delete'),
	      'href' => "comment/$comment->cid/delete-own",
	      'html' => TRUE,
	    );
  }

I hope ,it will help someone who need this functionality.

Comments

ace11’s picture

This is exactly what I need. But could not get this working. Can you be more spesific where to add those codes? Obviously to comment_goodness.module.

This is how my modified comment_goodness.module looks when added the first code.

/**
 * Implements hook_permission().
 */
function comment_goodness_permission() {
  return array(
    'delete own comments' => array(
      'title' => t('Delete own comments'),
      'description' => t('Allows a user to delete own comments that have no replies (e.g. all if in flat mode).'),
    ),
//adding permission to delete comments of own content
'delete comments of own content' => array(
      'title' => t('Delete comments of own content'),
      'description' => t('Allows a user to delete comments of own content'),
    ),
  );
}

This is second code

/**
 * Access callback for deleting own comment.
 */
function comment_goodness_delete_comment_access($comment) {
  global $user;

$node = node_load($comment->nid);  
  //commenting this line
  //$access = ($user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && (user_access('delete own comments') || user_access('administer comments')));
//permission to check the current user can access the delete comment page
   $access = ($user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && ( user_access('delete own comments') || user_access('administer comments') ) || ($user->uid && $comment->status == COMMENT_PUBLISHED && ($user->uid==$node->uid) && (user_access('delete comments of own content') || user_access('administer comments') ) ));
  // Deletion is not allowed if any comment has this comment as a parent.
  return $access && (0 == db_query("SELECT COUNT(cid) FROM {comment} WHERE pid = :cid", array(':cid' => $comment->cid))->fetchField());
}

And where does the last code go? Because on the line 285 is: '#type' => 'link',

Can you post your whole comment_goodness.module code?

Thanks!

formatC'vt’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Status: Active » Needs work
Related issues: +#1608322: Configuration to unpublish comment instead of comment deletion

we have a lot criss-crossed feature requests =)
summary:
- add feature to unpublish instead of delete comment
- add ajax delete
- add support for comment access module
- add delete own comments
- add delete comments for current node owner