Make WordPress Core


Ignore:
Timestamp:
03/10/2020 10:46:12 PM (5 years ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r47394 r47448  
    56215621    }
    56225622
     5623    /**
     5624     * Filters whether an attachment deletion should take place.
     5625     *
     5626     * @since 5.5.0
     5627     *
     5628     * @param bool|null $delete       Whether to go forward with deletion.
     5629     * @param WP_Post   $post         Post object.
     5630     * @param bool      $force_delete Whether to bypass the Trash.
     5631     */
     5632    $check = apply_filters( 'pre_delete_attachment', null, $post, $force_delete );
     5633    if ( null !== $check ) {
     5634        return $check;
     5635    }
     5636
    56235637    delete_post_meta( $post_id, '_wp_trash_meta_status' );
    56245638    delete_post_meta( $post_id, '_wp_trash_meta_time' );
Note: See TracChangeset for help on using the changeset viewer.