before_delete_post is fired before post metadata is deleted.
Let's suppose you have a plugin and when a certain post_type is deleted you want to perform some action.
<?php
add_action( 'before_delete_post', 'my_func' );
function my_func( $postid ){
// We check if the global post type isn't ours and just return
global $post_type;
if ( $post_type != 'my_custom_post_type' ) return;
// My custom stuff for deleting my custom post type here
}
?>
It's important to note the hook runs only when the WordPress user empties the Trash. If you're using this hook note that it will not fire if the user is deleting an Attachment, since attachments are force deleted, i.e., not sent to the Trash. Instead use the delete_post() hook.
before_delete_post() is located in wp-includes/post.php
.