Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need both Admin and Editor role users to be able to delete a custom post type from the front-end. I found the code to create a post delete link, but whenever either role tries to delete there is an error:

Forbidden You don't have permission to access /wp-admin/post.php on this server.

Any ideas? Is it because this is a custom post type? The post delete code is included below.

In function.php:

function wp_delete_post_link($link = 'Delete This', $before = '', $after = '')
{
global $post;
if ( $post->post_type == 'page' ) {
if ( !current_user_can( 'edit_page', $post->ID ) )
return;
} else {
if ( !current_user_can( 'edit_post', $post->ID ) )
return;
}
$link = "<a onclick=\"return confirm('Are you SURE you want to delete this post/page?')\" href='" . wp_nonce_url( get_bloginfo('url') . "/wp-admin/post.php?action=delete&amp;post=" . $post->ID, 'delete-post_' . $post->ID) . "'>".$link."</a>";
echo $before . $link . $after;
}

Inserted into page:

<?php wp_delete_post_link('Delete', ' <strong class="delete">', '</strong> ') ?>
share|improve this question
    
That looks like a server error outside of WordPress - are you sure the URL is valid & points to the correct location of wp-admin/post.php? –  TheDeadMedic Jan 11 '12 at 19:21

1 Answer 1

Here you go, this creates a Delete Post link that only appears to the user if they are both logged in and the author of the post. When the link is clicked, they get a js confirmation asking them if they're sure, which once clicked will delete the post. And it does work with Custom Post Types, tested it myself.

<?php if ($post->post_author == $current_user->ID) { ?><p><a onclick="return confirm('Are you SURE you want to delete this post?')" href="<?php echo get_delete_post_link( $post->ID ) ?>">Delete post</a></p><?php } ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.