From 2e7277b7339294b5935852bb1506708fa0c353b2 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 17 Sep 2015 05:02:52 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@34258 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 4dfefd4398..c4c8961b9f 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2778,8 +2778,16 @@ function wp_prepare_attachment_for_js( $attachment ) { } $attached_file = get_attached_file( $attachment->ID ); - if ( file_exists( $attached_file ) ) { + + if ( isset( $meta['filesize'] ) ) { + $bytes = $meta['filesize']; + } elseif ( file_exists( $attached_file ) ) { $bytes = filesize( $attached_file ); + } else { + $bytes = ''; + } + + if ( $bytes ) { $response['filesizeInBytes'] = $bytes; $response['filesizeHumanReadable'] = size_format( $bytes ); }