Return filesize from Image_Editor_Imagick::_save() - #751
Open
karlisb wants to merge 1 commit into
Open
Conversation
joehoyle
requested changes
Jul 7, 2026
| 'width' => $this->size['width'] ?? 0, | ||
| 'height' => $this->size['height'] ?? 0, | ||
| 'mime-type' => $mime_type, | ||
| 'filesize' => $save['filesize'] ?? wp_filesize( $filename ), |
Member
There was a problem hiding this comment.
Would it not be better to get the filesize before it's uploaded to s3? That would reduce / remove a network call.
Author
There was a problem hiding this comment.
It already does, as $save is a reference the return value of parent::save().
You're right that wp_filesize is a fallback that will make an extra HEAD request but only so this wouldn't break if by any reason Wordpress would revert the introduced filesize in 6.0. In practice this shouldn't be executed ever.
Would you rather me implement a fallback that stats the temp file (a few lines up) before discarding it rather that risking an extra HEAD request if Wordpress goes berserk? 😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #750.
Image_Editor_Imagick::_save()rebuilds its response array after copying the temp file to S3, but omits thefilesizekey thatWP_Image_Editor::_save()has returned since WP 6.0 (core ticket #49412).As a result:
wp_save_image()) trigger an "Undefined array key" PHP warning and persist attachment meta without a usablefilesize;sizes[*]['filesize']is missing from attachment meta for all sub-sizes on every upload;filesize()stats against S3 — the slow HEAD requests Idea: store filesize attachment meta value on upload. #492 / Save filesize with attachment metadata on upload #493 aimed to eliminate (the Save filesize with attachment metadata on upload #493 backfill hookswp_generate_attachment_metadata, which never fires on the image-editor save path).This change returns the
filesizethatparent::_save()already computed for the local temp file — byte-identical to the object copied to S3, so no extra remote request is made. Thewp_filesize()fallback only applies if a future WP version stops returning the key. Docblocks updated to match.