Support » Fixing WordPress » Delete comments link in template, how to delete comments without confirmation

  • I have created a 2 functions in my template file:


    function delete_comment_link($id) {
      if (current_user_can('edit_post')) {
        echo '| <a href="'.admin_url("comment.php?action=cdc&c=$id").'">del</a> ';
        echo '| <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'">spam</a>';
        echo '|'.wp_delete_comment();


    function mytheme_comment($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment; ?>
       <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
         <div id="comment-<?php comment_ID(); ?>">
          <?php if ($comment->comment_approved == '0') : ?>
             <em><?php _e('Your comment is awaiting moderation.') ?></em>
             <br />
          <?php endif; ?>
          <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'  ','') ?></div>
    <h3>This post was written by <?php the_author(); ?></h3>
          <?php comment_text() ?>
          <?php delete_comment_link(get_comment_ID()); ?>
          <div class="reply">
             <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>

    This works fine as expected and gives me a ‘delete’ or ‘spam’ link on each comment. However, when you click the links it takes you into the WordPress admin area to confirm if you want to delete the comment (or mark as spam).

    I have spent quite a bit of time researching this (Google, Codex, forums etc), but don’t seem to be able to work out how to directly delete a comment WITHOUT the confirmation step and going through to the admin panel.

    I’d just like to delete the comment from the ‘front-end’ of the site, rather than having to go through the admin panel confirmation step. When I look at the URL generated by the confirmation button, it seems to be the same as I am generating.

    Could someone point me in the right direction please – this has really got me puzzled!

  • The topic ‘Delete comments link in template, how to delete comments without confirmation’ is closed to new replies.