Make WordPress Core


Ignore:
Timestamp:
03/10/2022 01:08:19 PM (3 years ago)
Author:
spacedmonkey
Message:

Media: Store attachment’s file size in metadata.

Store the file size of all newly uploaded attachments, as part of the metadata stored in post meta. Storing file size means, developers will not have to resort to doing filesize function calls, that can be time consuming on assets on offloaded to services like Amazon’s S3.

This change also introduces a new helper function called, wp_filesize. This is a wrapper around the filesize php function, that adds some helpful filters and ensures the return value is an integer.

Props Cybr, Spacedmonkey, SergeyBiryukov, johnwatkins0, swissspidy, desrosj, joemcgill, azaozz, antpb, adamsilverstein, uday17035.
Fixes #49412.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/editorGd.php

    r51568 r52837  
    101101                'height'    => 33,
    102102                'mime-type' => 'image/jpeg',
     103                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-50x33.jpg' ),
    103104            ),
    104105        );
     
    301302                'height'    => 7,
    302303                'mime-type' => 'image/jpeg',
     304                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-10x7.jpg' ),
    303305            ),
    304306
     
    309311                'height'    => 50,
    310312                'mime-type' => 'image/jpeg',
     313                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-75x50.jpg' ),
    311314            ),
    312315
     
    317320                'height'    => 20,
    318321                'mime-type' => 'image/jpeg',
     322                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-30x20.jpg' ),
    319323            ),
    320324
     
    325329                'height'    => 400,
    326330                'mime-type' => 'image/jpeg',
     331                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-45x400.jpg' ),
    327332            ),
    328333
     
    333338                'height'    => 33,
    334339                'mime-type' => 'image/jpeg',
     340                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-50x33.jpg' ),
    335341            ),
    336342
     
    341347                'height'    => 37,
    342348                'mime-type' => 'image/jpeg',
     349                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-55x37.jpg' ),
    343350            ),
    344351
     
    349356                'height'    => 55,
    350357                'mime-type' => 'image/jpeg',
     358                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-83x55.jpg' ),
    351359            ),
    352360
     
    357365                'height'    => 60,
    358366                'mime-type' => 'image/jpeg',
     367                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-90x60.jpg' ),
    359368            ),
    360369
     
    365374                'height'    => 70,
    366375                'mime-type' => 'image/jpeg',
     376                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-105x70.jpg' ),
    367377            ),
    368378
     
    373383                'height'    => 133,
    374384                'mime-type' => 'image/jpeg',
     385                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-200x133.jpg' ),
    375386            ),
    376387        );
Note: See TracChangeset for help on using the changeset viewer.