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.
Image and certain post data are saved/updated as they should be using this functions:
- wp_insert_attachment
- wp_update_attachment_metadata
The problem is when I want to remove an old image (when saving a new one).
wp_delete_attachment does not remove the image (it does seem to remove stuff in db though..). I am thinking the problem lies in not using wp_handle_upload. (when I upload an image via upload btn and receive it using $_FILES and then upload it with wp_handle_upload - removing works)
Does anyone have an idea of what might be the right way to remove an image in my case? Perhaps I can save it properly using wp_handle_upload even if I have an image in base64?
Thanks for any info.
EDIT: I also tried saving image with wp_upload_bits and wp_delete_attachment still did not work.
Another thing I checked: the code of wp_handle_upload function located in wp-admin/includes/file.php
: I don't see an easy way to modify or copy the existing function and add a custom one which would accept base64 image instead of a file as in $_FILES. Someone has a "base64 to $_FILES" workaround perhaps?