is possible to interupt a post deletion when empty the trash

it is possible once called a before_delete_post action not to allow WP to delete post on certain condition? something like e this:

add_action( 'before_delete_post', 'my_custom_delete', 10);

function my_custom_delete($wp_post_id) {
    if (get_post_type($wp_post_id) == 'my_custom_post_type') {
         if(condition_is_true($wp_post_id)){
              error_log(do something to block WP deleting the post);
              notify_the_user();
         }
         else {
              error_log(we can delete the post);
         }

     }
}

Topic trash Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.