comment_delete

Versions
4.6 – 4.7
comment_delete($cid)
5 – 6
comment_delete($cid = NULL)
7
comment_delete($cid)

Menu callback; delete a comment.

Code

modules/comment.module, line 960

<?php
function comment_delete($cid) {
  $comment = db_fetch_object(db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d', $cid));
  $comment->name = $comment->uid ? $comment->registered_name : $comment->name;

  $output = '';

  // We'll only delete if the user has confirmed the
  // deletion using the form in our else clause below.
  if ($comment->cid && $_POST['edit']['confirm']) {
    drupal_set_message(t('The comment and all its replies have been deleted.'));

    // Delete comment and its replies.
    _comment_delete_thread($comment);

    _comment_update_node_statistics($comment->nid);

    // Clear the cache so an anonymous user sees that his comment was deleted.
    cache_clear_all();

    drupal_goto("node/$comment->nid");

  }
  else if ($comment->cid) {
    $output = theme('confirm',
                    t('Are you sure you want to delete the comment %title?', array('%title' => theme('placeholder', $comment->subject))),
                    'node/'. $comment->nid,
                    t('Any replies to this comment will be lost. This action cannot be undone.'),
                    t('Delete'));
    // Show comment that is being deleted
    $comment->comment = check_output($comment->comment, $comment->format);
    $output .= theme('comment', $comment);

  }
  else {
    drupal_set_message(t('The comment no longer exists.'));
  }

  print theme('page', $output);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.