This will do it.
Obviously you don't want to allow just anyone to delete any comment.
The authentication step is to require the user to be logged in with "administer comments" permission.
Alternatively, you could perhaps use a token in the querystring to check access to delete the comment.
/**
* Implements hook_menu
*/
function MY_MODULE_menu() {
$items['action/comment/%/delete'] = array(
'title' => 'Delete comment',
'page callback' => 'MY_MODULE_action_comment_delete',
'page arguments' => array(2),
'access arguments' => array('administer comments'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Menu callback
* Delete comment via GET request
*/
function MY_MODULE_action_comment_delete($cid){
try{
// Delete the comment
comment_delete($cid);
drupal_set_message(t('The comment and all its replies have been deleted.'));
watchdog('MY_MODULE', 'Deleted comment @cid and its replies.', array('@cid' => $cid));
// Clear the cache so an anonymous user sees that his comment was deleted.
cache_clear_all();
}catch(Exception $e){
drupal_set_message(t('There was a problem deleting the comment.'));
watchdog_exception('MY_MODULE', $e);
}
}
The path to delete a comment would then be:
http://www.example.com/action/comment/12/delete
Where "12" is the comment cid.