Support » Fixing WordPress » Directly delete comments in template – no admin step please

  • I have deployed the following code in my theme functions file to insert a comment delete link

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

    And further down in another function I use

    <?php delete_comment_link(get_comment_ID()); ?>

    This works fine – however when you click it it takes you to the WordPress admin area and you have to confirm deletion. I’d like to remove the admin area confirmation step and just straight delete the comment from the ‘front end’ (when just viewing the comments).

    I’m guessing there is some wp_nonce action somewhere I have to use maybe, but when I look at the link in the admin panel to confirm deletion it seems to be exactly the same URL as I am using – so I don’t understand why this doesn’t work.

    Anyone got any hot tips on this – I’ve done loads of research and have come up with nothing so far! Any help (or even just a point in the right direction!) would be much appreciated thanks!

  • The topic ‘Directly delete comments in template – no admin step please’ is closed to new replies.