For this I suggest you to use given solution which ensure each post is processed individually without interrupting the batch processing, and also allowing soft deletion
to work for both emptying the trash
and bulk
actions.
You need to update the softDelete function with the given code.
function softDelete( $postId ) {
if ( get_post_type( $postId ) != 'MY_POST_TYPE' ) {
return;
}
// Here we are changing post status to "deleted".
wp_update_post( [
'ID' => $postId,
'post_status' => 'deleted'
] );
// Here we are stopping further actions.
remove_action( 'before_delete_post', 'softDelete' );
}
Also we need to add given piece of code which will handles bulk actions
and empty the trash by updating the post status to deleted
for each post
and preventing further deletion.
add_action( 'wp_trash_post', 'soft_delete_for_bulk_and_empty_trash' );
function soft_delete_for_bulk_and_empty_trash( $postId ) {
if ( get_post_type( $postId ) != 'MY_POST_TYPE' ) {
return;
}
// Here we are changing post status to "deleted".
wp_update_post( [
'ID' => $postId,
'post_status' => 'deleted'
] );
// Here we are preventing permanent deletion.
add_filter( 'pre_trash_post', '__return_true' );
}
This should works for you.