You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As we have provided filter webp_uploads_upload_image_mime_transforms for the mime type transforms in any case user does not want to transform the mime type then they just return empty, true/false or array() then this file helper.php code is not require because $transforms = (array) apply_filters( 'webp_uploads_upload_image_mime_transforms', $default_transforms ); filter always retunt array value.
Return type empty
add_filter('webp_uploads_upload_image_mime_transforms', function () {
return;
});
Return type true/false
add_filter('webp_uploads_upload_image_mime_transforms', function () {
return false;
});
Return type empty array:
add_filter('webp_uploads_upload_image_mime_transforms', function () {
return array();
});
Also, we have to check if an array is null and then return an empty array so it can't execute next foreach code.
@mukeshpanchal27 Good catch! We should probably change this so that the filter does not cast to an array so that the check afterwards makes sense.
Of course the filter should always be used with an array, returning anything else would be doing it wrong. But the fact that it currently casts to an array is indeed a bug that we should address.
Activity
felixarntz commentedon Jun 16, 2022
@mukeshpanchal27 Good catch! We should probably change this so that the filter does not cast to an array so that the check afterwards makes sense.
Of course the filter should always be used with an array, returning anything else would be doing it wrong. But the fact that it currently casts to an array is indeed a bug that we should address.
jjgrainger commentedon Jun 22, 2022
@mukeshpanchal27 @felixarntz Fix for this here in #393
I've effectively removed the cast to array and added tests to check behaviour for the different values that may be passed back from the filter.