WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/20/2021 10:14:47 PM (5 months ago)
Author:
antpb
Message:

Media: Introduces image_editor_output_format filter for setting default MIME type of sub size image output.

This change introduces the image_editor_output_format filter, which fires as sub size images are generated allowing to define a default image MIME type for those items.

Props adamsilverstein, williampatton, spacedmonkey, mikeschroder, hellofromTonya, justinahinon, Boniu91, antpb, SergeyBiryukov.
Fixes #52867.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor.php

    r49927 r50943  
    317317        }
    318318
     319        /**
     320         * Filters the image editor output format mapping.
     321         *
     322         * Enables filtering the mime type used to save images. By default,
     323         * the mapping array is empty, so the mime type matches the source image.
     324         *
     325         * @see src/wp-includes/class-wp-image-editor.php -> get_output_format()
     326         *
     327         * @since 5.8.0
     328         *
     329         * @param array $wp_image_editor_output_format {
     330         *     An array of mime type mappings. Maps a source mime type to a new
     331         *     destination mime type. Empty by default.
     332         *
     333         *     @type array $mime_type The source mime type {
     334         *         @type string $mime_type The new mime type.
     335         *     }
     336         * @param string $filename Path to the image.
     337         * @param string $mime_type The source image mime type.
     338         * }
     339         */
     340        $wp_image_editor_output_format = apply_filters( 'image_editor_output_format', array(), $filename, $mime_type );
     341
     342        if (
     343            isset( $wp_image_editor_output_format[ $mime_type ] ) &&
     344            $this->supports_mime_type( $wp_image_editor_output_format[ $mime_type ] )
     345        ) {
     346            $mime_type = $wp_image_editor_output_format[ $mime_type ];
     347            $new_ext = $this->get_extension( $mime_type );
     348        }
     349
    319350        // Double-check that the mime-type selected is supported by the editor.
    320351        // If not, choose a default instead.
Note: See TracChangeset for help on using the changeset viewer.