Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This merge request will add an action to
rest_api_init
to create a compressor. This will ensure that images uploaded via the media endpoints (https://developer.wordpress.org/rest-api/reference/media/) are properly compressed if possible.Background
Whenever an image is uploaded it will generate various sizes and call the action
wp_generate_attachment_metadata
(link). This action was called on uploading an image through the REST API and thecompress
function on Tiny_Image was called, though because no compressor existed in the settings the images were not compressed:Usually, when admin or ajax is initiated it will call the
admin_init
orajax_init
functions. These have methods hooked up which will create a compressor. When the request goes to the REST API, nothing was done to create the compressor. The solution was to add an action to therest_api_init
hook, which is called when receiving a new REST request, and make sure the compressor is created.