WordPress.org

Make WordPress Core

Opened 22 months ago

Closed 21 months ago

Last modified 17 months ago

#33214 closed enhancement (fixed)

Allow media file size to be set from metadata when viewing media modal

Reported by: polevaultweb Owned by: wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords: has-patch needs-testing
Focuses: Cc:

Description

When viewing an attachment in the edit post screen, the file size is either calculated from the actual file, or taken from 'filesize' if set, from wp_get_attachment_metadata(). This alternative to using filesize( $file ); is helpful for image plugins that store the file somewhere else, i.e. it doesn't exist locally.

However, when you view the media in the modal, the file size is only calculated using the local file.

Attachments (1)

33214.diff (727 bytes) - added by polevaultweb 22 months ago.

Download all attachments as: .zip

Change History (6)

@polevaultweb
22 months ago

#1 @polevaultweb
22 months ago

  • Keywords has-patch needs-testing added

This patch unifies the implementation between

/wp-admin/includes/media.php line 2823

and

/wp-includes/media.php line 2765

Last edited 21 months ago by polevaultweb (previous) (diff)

#2 @wonderboymusic
21 months ago

  • Milestone changed from Awaiting Review to 4.4

#3 @wonderboymusic
21 months ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 34258:

Media: In wp_prepare_attachment_for_js(), don't call file_exists() and filesize() to retrieve $bytes if the data is already present in $meta. This is how the same code in attachment_submitbox_metadata() already works.

Props polevaultweb.
Fixes #33214.

#4 @drywallbmb
17 months ago

This is great, but is there anywhere in core where the filesize is actually being stored in the metadata? From what I can tell, these queries are always going to turn up nothing and wind up having to actually look at the filesystem to get the file size. In which case, why add this overhead of asking the DB/metadata first?

#5 @drywallbmb
17 months ago

Upon further review, it looks as though WP does populate filesize, but only for media types that get processed by the ID3 library. Is that right? Seems odd to do it for some filetypes and not others.

Note: See TracTickets for help on using tickets.