• Resolved fillidill

    (@fillidill)


    Hi,
    My goal is to make a delete link front-end under each posted comment to make it possible for a author to delete their own comments. I have searched and tried multiple methods but I can’t seem to make it work with the nonce even though reading through the documentation. I am hoping for some guidance.

    I have figured out that the link should look like something like this:
    https://www.host.com/wp-admin/comment.php?c=###&action=trashcomment&_wpnonce=##########

    I can get the ID of the comment, no problem but I can’t seem to generate the correct nonce and I’m stuck.

    Could someone please help me and show we how it is done?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello, the default delete comment link in the dashboard is generated like this:

    $del_nonce     = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
    $trash_url     = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );

    You can see above how the nonce is created and what I noticed is that in your link the post id &p=$comment->comment_post_ID is missing. I hope this helps!

    Thread Starter fillidill

    (@fillidill)

    Thank you so much! Works flawlessly ??

    Thread Starter fillidill

    (@fillidill)

    Forgot to mark it as solved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating a nonce for deleting comment front-end’ is closed to new replies.