Sideloaded image is not compressed
-
Hello,
I need to sideload images to a WordPress installation and created a little plugin for that. Said plugin is actually ping-ponging with another WordPress that has all the necessary information.
At the end, I “upload” an image with this line:
media_handle_sideload($fileArray, 0, 'null', $postData);
And that works. WordPress puts that into the media library, creates all the image sizes, all the good stuff.
The only thing that does not work is compressing the images.
It doesn’t matter if I select compressing in the background or while uploading (“auto”), in either case my sideloaded images are not compressed.
I saw in the plugin that you are hooking into wp_generate_attachment_metadata:
https://github.com/tinify/wordpress-plugin/blob/5b8074b9abf33232df81389859db77c4bbbf6d85/src/class-tiny-plugin.php#L58Which calls process_attachment, which should call blocking_compress_on_upload which actually compresses.
https://github.com/tinify/wordpress-plugin/blob/5b8074b9abf33232df81389859db77c4bbbf6d85/src/class-tiny-plugin.php#L266On the WP side of things, media_handle_sideload calls wp_update_attachment_metadata:
https://core.trac.www.ads-software.com/browser/tags/5.7.1/src/wp-admin/includes/media.php#L501which in turn applies filters for wp_generate_attachment_metadata:
https://core.trac.www.ads-software.com/browser/tags/5.7.1/src/wp-admin/includes/image.php#L631where Tinify should hook into.
But this seems to not happen.
Does anyone have any idea?
Is the issue that my plugin strictly speaking runs from the frontend? If so, how do I make Tinify available to said plugin?
Bulk compression is not really an option because this would have to be done every time the plugin is in action which is multiple times every day.
Thank you
Alduin
- The topic ‘Sideloaded image is not compressed’ is closed to new replies.