[wp-trac] [WordPress Trac] #47868: wp_delete_attachment returning successfully, deleting all DB data, but NOT deleting files, and NOT returning false

WordPress Trac noreply at wordpress.org
Tue Aug 13 12:03:06 UTC 2019


#47868: wp_delete_attachment returning successfully, deleting all DB data, but NOT
deleting files, and NOT returning false
--------------------------+-----------------------------
 Reporter:  Jossnaz       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 from
 https://wordpress.stackexchange.com/questions/344976/wp-delete-attachment-
 returning-successfully-deleting-all-db-data-but-not-
 delet?noredirect=1#comment505976_344976

 I digged into wp_delete_attachment here
 https://core.trac.wordpress.org/browser/tags/5.2.1/src/wp-
 includes/post.php#L5450 , it calls wp_delete_attachment_files

 wp_delete_attachment_files returns false on failure, but this is ignored!
 in wp_delete_attachment. Now I'm not gonna go on a rant how bad that
 'design' is. My question is, how can I make sure that the files DO get
 deleted?

 I'm calling

  $attachments = get_attached_media('', $post->ID);
  foreach ($attachments as $attachment) {
     wp_delete_attachment($attachment->ID, true);
 wp_delete_attachment never returns falsy.

 How can I figure out and fix wp_delete_attachment ?


 in my case it seems that some post_meta might be damaged, as the file
 location sometimes can be lost for some reason. This should return false
 or better throw and error

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47868>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list