Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jupitercow

    (@jcow)

    Yes. The functionality was too much for something that didn’t seem like it would get used enough. Also I definitely think it should be a separate plugin.

    The function to delete a post is really simple:

    wp_delete_post()

    If you wanted to add a link to delete a post, you could do something like add a link to your single.php:

    <a href="<?php echo add_query_arg( array('delete' => $post_id, 'nonce'=>wp_create_nonce('delete_post')), get_permalink() ); ?>" title="Delete this post">Delete</a>

    And then processes it either in functions.php or your template:

    if (! empty($_GET['delete']) && ! empty($_GET['nonce']) && wp_verify_nonce($_GET['nonce'], 'delete_post') )
    {
    	$post_id = ( is_numeric($_GET['delete']) ) ? $_GET['delete'] : $GLOBALS['post']->ID;
    	if ( current_user_can('delete_posts', $post_id) )
    	{
    		wp_delete_post($post_id);
    	}
    }

    This is a pretty basic example, but could get you started. It is ideal to test capabilities and a nonce will help keep the link from being abused.

    Thanks.
    Jake.

    Thread Starter burlingtonave

    (@burlingtonave)

    Haven’t had a chance to test this, jcow. But I know the quality of your code so I already know it works. I’ll report back for others when I’ve tested, but I just wanted to say thanks again for a great plugin and great support.

    Thread Starter burlingtonave

    (@burlingtonave)

    Just getting around to implementing this function… For the benefit of others, I couldn’t get the ‘delete post’ code above to work but found a great solution at https://ww.wp.xz.cn/support/topic/front-end-delete-post-with-custom-post-type.

    Thanks again for a great ‘edit post’ plugin.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Options for deleting posts’ is closed to new replies.