junaidbhura / fly-dynamic-image-resizer

Fly Dynamic Image Resizer plugin for WordPress
https://wordpress.org/plugins/fly-dynamic-image-resizer/
MIT License
162 stars 26 forks source link

issue with deleting image #40

Closed zzramesses closed 3 years ago

zzramesses commented 4 years ago

Hello. I have written code that periodically gets a set of posts and updates their post thumbnail from an image url that is saved as post meta. Before it saves the new post thumbnail it deletes the current thumbnail using wp_delete_attachment(). I'm pasting the url to a gist that has both my code and the error log. The plugin is creating a fatal error when I try to delete the image. https://gist.github.com/zzramesses/2e84e26c042c57df04eba86c617ca07c

junaidbhura commented 4 years ago

Hi @zzramesses thanks for this issue. Just confirm: Do you get an error when you try to delete an image from the WP back-end as well? Or just from your custom script?

zzramesses commented 4 years ago

Deleting from the admin area works just fine.

zzramesses commented 3 years ago

Just checking back in on this

junaidbhura commented 3 years ago

Hey @zzramesses it looks like the code triggers before WP_Filesystem() has had the chance to initialize. Does your code execute on some hook? I'd suggest triggering your code after plugins_loaded

junaidbhura commented 3 years ago

Hi closing this out for now, feel free to reply here!

joelgraham commented 3 years ago

Hi @junaidbhura,

I've got a bunch of custom API routes that integrate with another system, one of these routes is a DELETE route for images. The routes are setup using the rest_api_init hook. When I try and delete images through this route I get the same error as the original poster.

As per the original post, I'm using the wp_delete_attachment() method.

Any help would be greatly appreciated.

junaidbhura commented 3 years ago

Hey @joelgraham and @zzramesses I've added a fix for this in 2.0.8. Can you update the plugin and see if this resolves your issue?

One thing to note though: You might have to delete the dynamic Fly images for those deleted images yourself in this case.