Make WordPress Core

Changeset 53292


Ignore:
Timestamp:
04/27/2022 05:19:52 AM (3 years ago)
Author:
peterwilsoncc
Message:

Media: Ensure wp_crop_image() returns correct file type.

Return the correct file path from wp_crop_image() when a developer modifies the file type with via the image_editor_output_format filter.

Previously the function would return a broken file reference containing the original file extension rather than the one specified via the filter.

Props mat-lipe, adamsilverstein.
Fixes #55403.

Location:
trunk
Files:
2 edited

Legend:

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

    r52837 r53292  
    6262    if ( is_wp_error( $result ) ) {
    6363        return $result;
     64    }
     65
     66    if ( ! empty( $result['path'] ) ) {
     67        return $result['path'];
    6468    }
    6569
  • trunk/tests/phpunit/tests/image/functions.php

    r52837 r53292  
    144144    }
    145145
    146 
    147146    /**
    148147     * @ticket 50833
     
    342341
    343342        return $classes;
     343    }
     344
     345    /**
     346     * @ticket 55403
     347     */
     348    public function test_wp_crop_image_with_filtered_extension() {
     349        add_filter( 'image_editor_output_format', array( $this, 'filter_image_editor_output_format' ) );
     350        $file = wp_crop_image(
     351            DIR_TESTDATA . '/images/canola.jpg',
     352            0,
     353            0,
     354            100,
     355            100,
     356            100,
     357            100
     358        );
     359
     360        $this->assertNotWPError( $file );
     361        $this->assertFileExists( $file );
     362
     363        unlink( $file );
    344364    }
    345365
     
    660680    }
    661681
     682    public function filter_image_editor_output_format() {
     683        return array_fill_keys( array( 'image/jpg', 'image/jpeg', 'image/png' ), 'image/webp' );
     684    }
     685
    662686    public function filter_fallback_intermediate_image_sizes( $fallback_sizes, $metadata ) {
    663687        // Add the 'test-size' to the list of fallback sizes.
Note: See TracChangeset for help on using the changeset viewer.