I am allowing Authors to delete their posts on the front end as they cant access the admin. I have this working, but what bothers me is the standard javascript onclick alert message - is there are way to style a js alert? From my understanding, no. Or to use jQuery for the message and use a modal window that I can style?
Also, after deletion the user is returned to the same page which is good, but there is no confirmation message - I'd like to have a message saying "Post successfully deleted". I just think these touches would provide a better user experience. Here's the code I am using:
function wp_delete_post_link($link = 'Delete This', $before = '', $after = '') {
global $post;
if ( $post->post_type == 'post' ) {
if ( !current_user_can( 'edit_page', $post->ID ) )
return;
} else {
if ( !current_user_can( 'edit_post', $post->ID ) )
return;
}
$message = "Are you sure you want to delete ".get_the_title($post->ID)." ?";
$delLink = wp_nonce_url( get_bloginfo('url') . "/wp-admin/post.php?action=delete&post=" . $post->ID, 'delete-post_' . $post->ID);
$htmllink = "<a href='" . $delLink . "' onclick = \"if ( confirm('".$message."' ) ) { execute(); return true; } return false;\"/>".$link."</a>";
echo $before . $htmllink . $after;
$redirect = add_query_arg( 'success', 'true', $redirect );
}
<?php wp_delete_post_link('Delete your Entry', '<p><em>Delete your Entry: </em>', '</p>'); ?>
And was added to the author.php where the post delete button is
<?php if ( ! empty( $_GET['success'] ) ) {
echo 'Wahey!';
}
?>