Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing media from library does not remove custom image sizes #2

Closed
drrobotnik opened this issue Nov 26, 2013 · 5 comments
Closed

Comments

@drrobotnik
Copy link
Contributor

I'm adding this issue here, because I don't think it directly relates to core in the way my OP did.
http://core.trac.wordpress.org/ticket/25884#comment:3

Your comment references that WP_images removes the custom crops when a user removes the image from the media library. In my tests, they don't.

This is how I've used it.

$image = new WP_Image( 228 );
$crop = $image->add_image_size( 'slide_thumb', 400, 200, true );

properly creates the size, so we can call wp_get_attachment_image();

$meta = $image->get_metadata(); returns the list of crops including the custom crop.

When removing the image from the library, the custom crop still exists.

@markoheijnen
Copy link
Owner

I was pretty sure that WordPress deletes all the images in the array. I will write some unit tests this week and see why it goes wrong. From there I will start building more functionality like some on-the-fly generation.

@markoheijnen
Copy link
Owner

I finally had the time to look into it and now know the issue. WordPress only deletes existing image sizes. I would assume this is a bigger issue then only my class. Going to check things out and see if WordPress needs to be patched.

@drrobotnik
Copy link
Contributor Author

The first solution I came up with is when you add an image size, store the name in the options table. Then before you delete an image from media, retrieve the image sizes and add them to the sizes global. If you go this route, I recommend prefixing the $name of the image size when you store it to avoid removing another plugins size on accident.

@markoheijnen
Copy link
Owner

Not needed. Long term solution is https://core.trac.wordpress.org/ticket/24518.
I will implement a short time solution with the hooks in wp_delete_attachment() tomorrow.

Also if you didn't check it out yet http://github.com/markoheijnen/improved-image-editor/. Also includes most of the code here. Still need to look if it still can be separated or not.

@markoheijnen
Copy link
Owner

Fixed the problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants