Make WordPress Core


Ignore:
Timestamp:
03/10/2022 01:08:19 PM (2 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/editorImagick.php

    r51568 r52837  
    9191                'height'    => 33,
    9292                'mime-type' => 'image/jpeg',
     93                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-50x33.jpg' ),
    9394            ),
    9495        );
     
    290291                'height'    => 7,
    291292                'mime-type' => 'image/jpeg',
     293                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-10x7.jpg' ),
    292294            ),
    293295
     
    298300                'height'    => 50,
    299301                'mime-type' => 'image/jpeg',
     302                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-75x50.jpg' ),
    300303            ),
    301304
     
    306309                'height'    => 20,
    307310                'mime-type' => 'image/jpeg',
     311                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-30x20.jpg' ),
    308312            ),
    309313
     
    314318                'height'    => 400,
    315319                'mime-type' => 'image/jpeg',
     320                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-45x400.jpg' ),
    316321            ),
    317322
     
    322327                'height'    => 33,
    323328                'mime-type' => 'image/jpeg',
     329                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-50x33.jpg' ),
    324330            ),
    325331
     
    330336                'height'    => 37,
    331337                'mime-type' => 'image/jpeg',
     338                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-55x37.jpg' ),
    332339            ),
    333340
     
    338345                'height'    => 55,
    339346                'mime-type' => 'image/jpeg',
     347                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-83x55.jpg' ),
    340348            ),
    341349
     
    346354                'height'    => 60,
    347355                'mime-type' => 'image/jpeg',
     356                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-90x60.jpg' ),
    348357            ),
    349358
     
    354363                'height'    => 70,
    355364                'mime-type' => 'image/jpeg',
     365                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-105x70.jpg' ),
    356366            ),
    357367
     
    362372                'height'    => 133,
    363373                'mime-type' => 'image/jpeg',
     374                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-200x133.jpg' ),
    364375            ),
    365376        );
Note: See TracChangeset for help on using the changeset viewer.