wp_delete_attachment should delete everything that is about attachment.

However if I do

wp_delete_attachment( (int)$delete_attachment_id, true );

The files remain on the server (even true should indicate force delete).

Function acts as successful:

Return: (WP_Post|false|null) Post data on success, false or null on failure.

...it does return WP_Post object and really the WP_Post object of this attachment is deleted.
But the files are not deleted... not even the thumbnails...

Additional info: this happens for files previously added with media_handle_upload

  • 1
    The function does have unreliable return, I've reported that, but I just noticed that wp_delete_attachment_files() also returned true altough file remained... it comes down to wp_delete_file_from_directory() which again doesn't check if the deletion really happened and to final wp_delete_file() which is the final one and still it just silently calls PHP's unlink and does not check if the file was really deleted or not... – jave.web Oct 11 '18 at 19:29
  • As to this my case, it was caused by filter wp_delete_file which made the filepath empty, therefore the file wp_delete_file() could not be successful, but still this part of WP is currently unreliable. – jave.web Oct 11 '18 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.