I\'m saving an image to uploads folder, but I\'m using file_put_contents instead of wp_handle_upload - because I get an image in base64 and not as a file in $_FILES.
Im
The simple solution is probably to just manually add _wp_attached_file
meta value to your attachment.
Set it to the file you want deleted when the attachment is deleted.
The logic behind this is according to https://core.trac.wordpress.org/browser/tags/4.4/src/wp-includes/post.php#L0:
get_attached_file
returns that value to wp_delete_attachment
which sets it as $file
And at the end of wp_delete_attachment
it calls wp_delete_file($file)
So I'm guessing the underlying issue is that, you are never setting a value for the meta key _wp_attached_file
.
The only downside is that I'm not sure what other processes in wp might be using that value. But you might get lucky, perhaps none, and/or it doesn't mess anything up by setting it manually.