For auditing issue, I only want a post can be trashed, but not deleted – for all users.

So I have a plugin like

add_action('before_delete_post', function($id) {
        wp_die(0);
    });

But seems not all delete action are ajax, so it will be show a black screen with return an error page with result “0”

Feature wise the above code is ok, but are there any better way?

3 s
3

Don’t let the action die, just do a redirect (to wherever you’d like):

function wpse_92155_before_delete_post() {
    wp_redirect(admin_url('edit.php'));
    exit();
} // function wpse_92155_before_delete_post
add_action('before_delete_post', 'wpse_92155_before_delete_post', 1);

Leave a Reply

Your email address will not be published. Required fields are marked *