WordPress.org

Ready to get started?Download WordPress

Forums

Editing and trashingPost (4 posts)

  1. dipaksaraf
    Member
    Posted 3 years ago #

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

    In Order to edit a post we use:

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

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

    http://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.

  2. dipaksaraf
    Member
    Posted 3 years ago #

    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:  http://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

  3. dipaksaraf
    Member
    Posted 3 years ago #

    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:
    http://www.domainname.com/wp-admin/post.php?post=74783&action=edit

    Trash code for the post:
    http://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:  http://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.

Topic Closed

This topic has been closed to new replies.

About this Topic