• hello I have a following requirement and if anyone would help on how to implement it.

    In Order to edit a post we use:

    https://www.domainname.com/wp-admin/post.php?post=74783&action=edit

    Now if i want to trash the same post we have to use:

    https://www.domainname.com/wp-admin/post.php?post=74783&action=trash&_wpnonce=abcdedfg

    How do i add nonce in this trash link so that if we want the post to be trashed by just clicking this link.My requirement is we get a lot of response for our posts which is forwarded to Email with edit link of the post, now we want to have an additional link which will have trash link also, so that if the response is trash we can just click on this link and trash the comment/post.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter dipaksaraf

    (@dipaksaraf)

    Hi

    I have been using the instruction to code the nonces:

    $nonce= wp_create_nonce  ('my-nonce');
    $nonce=$_REQUEST['_wpnonce'];
    if (! wp_verify_nonce($nonce, 'my-nonce') ) die("Security check");
    
    $elink = "\n\n Trash Link:  https://www.somedomain.com/wp-admin/post.php?post=$post_id&action=trash&_wpnonce=$nonce \n\n\n";

    I have also placed this code in the form

    <?php wp_nonce_field('my-nonce'); ?>

    The link is being generated along with nonces code i guess but when i am clicking on this link i am error which says “Are you sure you want to do this?” and Please try again?

    How do i resolve this error??

    Dipak

    Thread Starter dipaksaraf

    (@dipaksaraf)

    In one of our WP site whenever a user responds to a from or submits a request from a from, a draft post is created automatically. The link for the draft post is mailed to the administrator to edit the post before publishing.

    Now the new requirement is to create a trash link also for the same post to be mailed to admin. The problem with the nonce is that it need to vbe verified before the same can be used.

    I am able to create a trash link, but am unsure how to verify this link else it will throw an security error “Are you sure you want to do this?” and Please try again?

    the codes used are

    Edit code for post:
    https://www.domainname.com/wp-admin/post.php?post=74783&action=edit

    Trash code for the post:
    https://www.domainname.com/wp-admin/post.php?post=74783&action=trash&_wpnonce=abcdedfg

    The code used for creating the Trash link:

    $nonce= wp_create_nonce  ('my-nonce');
    $nonce=$_REQUEST['_wpnonce'];
    if (! wp_verify_nonce($nonce, 'my-nonce') ) die("Security check");
    
    $elink = "\n\n Trash Link:  https://www.somedomain.com/wp-admin/post.php?post=$post_id&action=trash&_wpnonce=$nonce \n\n\n";

    The following code also been place in <form>
    <?php wp_nonce_field('my-nonce'); ?>

    Now the issue is trash link alongwith the nonce code is being generated, but when the link is created from mail it generated security error.

    I think i have to embed some kind of code in link so that the nonce code is verified before it can be used?

    Any thought or suggestion on how to create a trash link which can be mailed and can be used by just clicking the link rather that using from the WP-admin pages.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Editing and trashingPost’ is closed to new replies.