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.

Built from https://develop.svn.wordpress.org/trunk@47448


git-svn-id: http://core.svn.wordpress.org/trunk@47235 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2020-03-10 22:48:07 +00:00
parent 9aa864f1a7
commit a88ac4f003
2 changed files with 15 additions and 1 deletions

View File

@ -5620,6 +5620,20 @@ function wp_delete_attachment( $post_id, $force_delete = false ) {
return wp_trash_post( $post_id ); 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_status' );
delete_post_meta( $post_id, '_wp_trash_meta_time' ); delete_post_meta( $post_id, '_wp_trash_meta_time' );

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.5-alpha-47444'; $wp_version = '5.5-alpha-47448';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.