Ok, I found this piece of code, and I know I should know how to do this… But how do I create a link that will call this function? It would be nice if it had a popup that warned the user it was a permanent delete option:
// Delete all attatchements with post
function remove_post() {
if(isset($_POST['portfolio']) && is_numeric($_POST['portfolio'])) {
$post = get_post($_POST['portfolio']);
if(get_current_user_id() == $post->post_author) {
$args = array(
'post_parent' => $_POST['portfolio']
);
$post_attachments = get_children($args);
if($post_attachments) {
foreach ($post_attachments as $attachment) {
wp_delete_attachment($attachment->ID, true);
}
}
wp_delete_post($_POST['portfolio'], true);
}
}
exit;
}
You can use JavaScript to prompt you:
Found this here – Example
<script>
function confirmDelete(delUrl) {
if (confirm("Are you sure you want to delete")) {
document.location = delUrl;
}
}
</script>
<a href="javascript:confirmDelete('delete.page?id=1')">Delete</a>
Another way
<a href="delete.page?id=1" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
Warning: This JavaScript will not stop the records from being deleted if they just navigate to the final url – delete.page?id=1 in their browser
does this delete.page?id=1
need to be the actual id of the page? Also, I’m having a hard time getting it to show up in a meta box…
I can’t get it to work, even by just going to the actual link