Media: Introduce preflight filter to `wp_delete_attachment()`.

Introduces the filter `pre_delete_attachment` to allow developers to prevent or modify the deletion of attachments. This improves consistency with `wp_delete_post()` and `wp_trash_post()`.

Props joemcgill, peterwilsoncc.
Fixes #49597.


git-svn-id: https://develop.svn.wordpress.org/trunk@47448 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson 2020-03-10 22:46:12 +00:00
parent 01ad44e871
commit eba126609f
1 changed files with 14 additions and 0 deletions

View File

@ -5620,6 +5620,20 @@ function wp_delete_attachment( $post_id, $force_delete = false ) {
return wp_trash_post( $post_id );
}
/**
* Filters whether an attachment deletion should take place.
*
* @since 5.5.0
*
* @param bool|null $delete Whether to go forward with deletion.
* @param WP_Post $post Post object.
* @param bool $force_delete Whether to bypass the Trash.
*/
$check = apply_filters( 'pre_delete_attachment', null, $post, $force_delete );
if ( null !== $check ) {
return $check;
}
delete_post_meta( $post_id, '_wp_trash_meta_status' );
delete_post_meta( $post_id, '_wp_trash_meta_time' );