- Notifications
You must be signed in to change notification settings - Fork 113
Introduce filter webp_uploads_pre_generate_additional_image_source
to short-circuit generating additional image sources on upload #318
New issue
Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.
By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on ? Sign in to your account
Conversation
… use custom mechanism to create additional mime types for the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments, would be great to add some tests around the filter as well.
Co-authored-by: Eugene Manuilov <[email protected]>
Co-authored-by: Eugene Manuilov <[email protected]>
Co-authored-by: Eugene Manuilov <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
However it looks like we might want to introduce a new filter in the return
value as currently, we are assuming the image would be in the same directory as the WordPress installation and calling filesize
for files stored in a bucket like S3 this is not the case, I think in those cases we can rely on a new filter being used so plugins can define the logic in how the filesize
is calculated.
For example;
return apply_filters( 'filter_name', array...
Specifically here:
performance/modules/images/webp-uploads/helper.php
Lines 89 to 92 in 2efa53a
return array( 'file' => $image['file'], 'filesize' => filesize( $image['path'] ), );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mehulkaklotar The implementation is missing support for the possible WP_Error
return type of the filter, which is critical and needs to be fixed. Other than that, just a documentation enhancement suggestion.
Co-authored-by: Felix Arntz <[email protected]>
webp_uploads_pre_generate_additional_image_source
to short-circuit generating additional image sources on upload @mehulkaklotar I've updated the base branch to |
…s_pre_generate_additional_image_source
# Conflicts: # modules/images/webp-uploads/helper.php
@felixarntz I am still not sure about the so are we going to make bydefault |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mehulkaklotar Thank you for making the changes, I have two follow-up comments.
* | ||
* @return array|null|WP_Error An array with the file and filesize if the image was created correctly otherwise a WP_Error | ||
*/ | ||
$image = apply_filters( 'webp_uploads_pre_generate_additional_image_source', null, $attachment_id, 'full', $size_data, $mime ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so are we going to make bydefault
full
for all image size in filter? because it doesn't really make sense as I tested it and it turns out all image size data is being worked on in that.
Ahh, sorry I had totally missed this. Yes, this absolutely shouldn't show full
for any image size. We will need to provide the name of the image size where the $size_data
comes from. We don't have access to that currently from this function, so let's add a new function parameter $size_name
right before $size_data
.
We then need to pass this new parameter accordingly everywhere that webp_uploads_generate_additional_image_source()
is called. Can you please make that update here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added changes for this in the latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mehulkaklotar. Please review my new feedback in #318 (review) - part of your new implementation isn't needed, as the one function by definition is only used for the full
image size, so we don't need to try to find the matching size, it's always full
in that scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mehulkaklotar One more follow-up around the newly added change, which can be simplified.
@felixarntz We should look into this comment from @mitogh about introducing another filter for returning value for function. Should we introduce that in this change or make new PR for it? |
Co-authored-by: Eugene Manuilov <[email protected]>
@mehulkaklotar Is there a reason we couldn't expect the I would want @felixarntz and @mitogh to input here just incase I've overlooked something. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, I've added a comment based on adding an additional filter to confirm #318 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mehulkaklotar!
Regarding @mitogh's comment, that's an important point. I think a good solution would be to allow for an optional path
key within the return array, which we would use instead of file
in case it is set. Let's open a follow-up issue for that and work on it for the 1.2.0 plugin release.
Summary
Fixes #307
Relevant technical choices
Checklist
[Focus]
orInfrastructure
label.[Type]
label.no milestone
label.