Skip to content

Optimize: webp_uploads_upload_image_mime_transforms filter #361

Closed

Description

@mukeshpanchal27

Bug Description

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.

Additional Context

  • PHP Version: 8.0.15
  • OS: Windows
  • Browser: Chrome
  • Plugin Version: 1.1.0

Activity

  1. felixarntz commented on Jun 16, 2022

    @felixarntz
    Member

    @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.

  2. added
    Needs DevAnything that requires development (e.g. a pull request)
    and removed
    no milestonePRs that do not have a defined milestone for release
    Needs DiscussionAnything that needs a discussion/agreement
    on Jun 16, 2022
  3. added this to the 1.3.0 milestone on Jun 16, 2022
  4. self-assigned this
    on Jun 22, 2022
  5. jjgrainger commented on Jun 22, 2022

    @jjgrainger
    Contributor

    @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.

  6. added
    [Type] BugAn existing feature is broken
    and removed
    [Type] EnhancementA suggestion for improvement of an existing feature
    on Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Needs DevAnything that requires development (e.g. a pull request)[Plugin] Modern Image FormatsFormerly WebP Uploads [slug: webp-uploads][Type] BugAn existing feature is broken

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions