Make WordPress Core

Changeset 55437


Ignore:
Timestamp:
03/01/2023 12:34:18 AM (4 years ago)
Author:
azaozz
Message:

Media: Revert the addition of a $size parameter to get_attached_file().

Reverts [55199], [55202], and [55217] but keeps the updated docs.

Props: flixos90, joedolson, azaozz.
Fixes: #51780.

Location:
trunk
Files:
2 edited

Legend:

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

    r55401 r55437  
    706706 * Retrieves attached file path based on attachment ID.
    707707 *
    708  * Will return intermediate size path if the `$size` parameter is provided.
    709  *
    710708 * By default the path will go through the {@see 'get_attached_file'} filter, but
    711709 * passing `true` to the `$unfiltered` argument will return the file path unfiltered.
     
    716714 *
    717715 * @since 2.0.0
    718  * @since 6.2.0 The `$size` parameter was added.
    719  *
    720  * @param int          $attachment_id Attachment ID.
    721  * @param bool         $unfiltered    Optional. Whether to skip the {@see 'get_attached_file'} filter.
    722  *                                    Default false.
    723  * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array
    724  *                                    of width and height values in pixels (in that order). Default empty string.
     716 *
     717 * @param int  $attachment_id Attachment ID.
     718 * @param bool $unfiltered    Optional. Whether to skip the {@see 'get_attached_file'} filter.
     719 *                            Default false.
    725720 * @return string|false The file path to where the attached file should be, false otherwise.
    726721 */
    727 function get_attached_file( $attachment_id, $unfiltered = false, $size = '' ) {
    728 
    729         // Check for intermediate sizes first, otherwise fall back to the original attachment size.
    730         if ( ! empty( $size ) ) {
    731                 $intermediate_image = image_get_intermediate_size( $attachment_id, $size );
    732                 if ( ! $intermediate_image || ! isset( $intermediate_image['path'] ) ) {
    733                         return false;
    734                 }
    735 
    736                 $file = $intermediate_image['path'];
    737         } else {
    738                 $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
    739         }
     722function get_attached_file( $attachment_id, $unfiltered = false ) {
     723        $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
    740724
    741725        // If the file is relative, prepend upload dir.
     
    755739         *
    756740         * @since 2.1.0
    757          * @since 6.2.0 The `$size` parameter was added.
    758741         *
    759742         * @param string|false $file          The file path to where the attached file should be, false otherwise.
    760743         * @param int          $attachment_id Attachment ID.
    761          * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array
    762          *                                    of width and height values in pixels (in that order). Default empty string.
    763744         */
    764         return apply_filters( 'get_attached_file', $file, $attachment_id, $size );
     745        return apply_filters( 'get_attached_file', $file, $attachment_id );
    765746}
    766747
  • trunk/tests/phpunit/tests/media/wpGenerateAttachmentMetadata.php

    r55199 r55437  
    1919         *
    2020         * @ticket 49412
    21          * @ticket 51780
    2221         *
    2322         * @covers ::wp_create_image_subsizes
     
    3029                $this->assertSame( wp_filesize( get_attached_file( $attachment ) ), $metadata['filesize'] );
    3130
    32                 foreach ( $metadata['sizes'] as $size => $intermediate_size ) {
     31                foreach ( $metadata['sizes'] as $intermediate_size ) {
    3332                        $this->assertArrayHasKey( 'filesize', $intermediate_size );
    3433                        $this->assertNotEmpty( $intermediate_size['filesize'] );
    3534                        $this->assertIsNumeric( $intermediate_size['filesize'] );
    36                         $this->assertStringContainsString( $intermediate_size['file'], get_attached_file( $attachment, false, $size ) );
    3735                }
    3836        }
Note: See TracChangeset for help on using the changeset viewer.