[wp-trac] [WordPress Trac] #49597: Introduce preflight filter to wp_delete_attachment().

WordPress Trac noreply at wordpress.org
Mon Mar 9 21:47:44 UTC 2020


#49597: Introduce preflight filter to wp_delete_attachment().
---------------------------+------------------------------
 Reporter:  peterwilsoncc  |       Owner:  (none)
     Type:  enhancement    |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Media          |     Version:
 Severity:  normal         |  Resolution:
 Keywords:  has-patch      |     Focuses:
---------------------------+------------------------------
Changes (by peterwilsoncc):

 * keywords:  needs-patch => has-patch


Comment:

 @joemcgill

 The intent is to make preflighting available for deleting attachments, at
 the moment it is unavailable due to the order of operation in
 `wp_delete_post()`.

 `wp_delete_post()` checks the post type and calls `wp_delete_attachment()`
 prior to calling the preflight hook:

 {{{#!php
 <?php
 // From wp_delete_post():

 if ( 'attachment' === $post->post_type ) {
         return wp_delete_attachment( $postid, $force_delete );
 }

 /**
  * Filters whether a post deletion should take place.
  *
  * @since 4.4.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_post', null, $post, $force_delete );
 if ( null !== $check ) {
         return $check;
 }
 }}}

 In [attachment:"49597.diff"]:

 * introduce preflight hook
 * For consistency with `pre_delete_post` and `pre_trash_post`, I've added
 the function below any relevant post type and status checking.

 I've left the milestone as awaiting review to allow the media component
 team to consider.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49597#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list