Forum Moderators: open
I have this link which deletes a blog post:
[mysite.com...]
Does anyone know what I would add to this so a confirmation alert box pops up allowing the user to cancel or proceed with the action?
Thanks.
function Confirm() {
var answer = confirm("Are you sure you want to delete this post?");
if (answer) {
window.location='http://mysite.com/wordpress/wp-admin/post.php?action=delete&post=86&_wpnonce=a4dbc76dc9';
}
}
</script>
<a href="javascript:Confirm();">Delete Post</a>
Try that.
The link is actually created using php. This is the code which creates the link:
<?php if (current_user_can('edit_post', $post->ID)) echo "<a href='" . wp_nonce_url("/wordpress/wp-admin/post.php?action=delete&post=$id", 'delete-post_' . $post->ID) . "'>Delete post</a>" ?>
Thanks.
function Confirm(goto) {
var answer = confirm("Are you sure you want to delete this post?");
if (answer) {
window.location= goto;
}
}
<?php if (current_user_can('edit_post', $post->ID)) echo "<a href='javascript:Confirm('" . wp_nonce_url("/wordpress/wp-admin/post.php?action=delete&post=$id", 'delete-post_' . $post->ID) . "')'>Delete post</a>" ?>
Try that. I'm not 100% sure if it will work though.
<?php if (current_user_can('edit_post', $post->ID)) echo "<a href='" . wp_nonce_url("/wordpress/wp-admin/post.php?action=delete&post=$id", 'delete-post_' . $post->ID) . "' onclick='return confirm(\"Are you sure you want to delete this post?\")'>Delete post</a>" ?>