Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#34124 closed enhancement (fixed)

image_get_intermediate_size not filterable

Reported by: a5hleyrich's profile A5hleyRich Owned by: drewapicture's profile DrewAPicture
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.3.1
Component: Media Keywords: has-patch
Focuses: Cc:


The large majority of functions within wp-includes/media.php are filterable, which allows plugins to modify the return URLs and file paths for attachments.

The problem with image_get_intermediate_size is that if all other methods of determining the correct image size fails, it falls back to the following:

// include the full filesystem path of the intermediate file
if ( empty($data['path']) && !empty($data['file']) ) {
	$file_url = wp_get_attachment_url($post_id);
	$data['path'] = path_join( dirname($imagedata['file']), $data['file'] );
	$data['url'] = path_join( dirname($file_url), $data['file'] );
return $data;

The $data['url'] value is directly used in wp_image_editor to output a preview of the existing image before making any edits:

The reason the image has returned 404 in this cause is because it's being served from S3 and contains illegal characters that need encoding.

Attachments (4)

34124.patch (498 bytes) - added by A5hleyRich 9 years ago.
34124.2.diff (3.8 KB) - added by kirasong 9 years ago.
Add filter to rest of return cases; expand docs.
34124.3.diff (3.8 KB) - added by kirasong 9 years ago.
That wasn't quite right. Fix the height/width types in docs.
34124.diff (3.6 KB) - added by wonderboymusic 9 years ago.

Download all attachments as: .zip

Change History (10)

9 years ago

#1 @A5hleyRich
9 years ago

  • Keywords has-patch added

9 years ago

Add filter to rest of return cases; expand docs.

9 years ago

That wasn't quite right. Fix the height/width types in docs.

#2 @kirasong
9 years ago

  • Milestone changed from Awaiting Review to 4.4
  • Owner set to DH-Shredder
  • Status changed from new to accepted

Hi @A5hleyRich! Thanks for this ticket and patch. I like it.

Attached 34124.3.diff, which expands the filter to handle all return cases, including those where $size was passed a width and height.

Also expanded the docs for image_get_intermediate_size(), since its signature is extremely confusing.

This ticket was mentioned in Slack in #core by mike. View the logs.

9 years ago

9 years ago

#4 @wonderboymusic
9 years ago

  • Owner changed from DH-Shredder to DrewAPicture
  • Status changed from accepted to assigned

34124.diff is a refresh

#5 @DrewAPicture
9 years ago

  • Status changed from assigned to accepted

#6 @DrewAPicture
9 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 35289:

Media: Introduce the image_get_intermediate_size filter to its like-named function, making it possible to manipulate returned intermedia image size data.

Covers both the default and meaningful short-circuit return cases. Also adds a hash notation to the return documentation in the DocBlock.

Props A5hleyRich, DH-Shredder, wonderboymusic.
Fixes #34124.

Note: See TracTickets for help on using tickets.