Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#24060 closed defect (bug) (fixed)

Post formats: `get_the_post_format_image()` splitting content doesn't work when "intermediate_image_sizes" result is empty

Reported by: lancewillett's profile lancewillett Owned by: markjaquith's profile markjaquith
Milestone: 3.6 Priority: normal
Severity: normal Version:
Component: Post Formats Keywords: has-patch
Focuses: Cc:

Description

get_the_post_format_image() splits out an image from post content, to avoid duplicating it when a theme choose to output split content.

Unfortunately, not all WP installs will have "default" or "expected" image sizes, like 'thumbnail', 'medium', 'large' etc.

For example, on WordPress.com this call results in an empty array:
$sizes = get_intermediate_image_sizes();

I think to improve the content parsing two improvements can be made:

  1. Move get_attachment_link( $media->ID ) out of the foreach loop for $sizes -- that URL will be the same for each size, it's just the permalink to the attachment page
  2. Add the "original" image source path to the $urls array, which is the image path with no size information. The original uploaded file path can then be used to parse out images from the main content even if the expected size list is empty.

Attachments (3)

24060.diff (879 bytes) - added by lancewillett 11 years ago.
24060.1.diff (875 bytes) - added by lancewillett 11 years ago.
24060.2.diff (762 bytes) - added by lancewillett 11 years ago.

Download all attachments as: .zip

Change History (11)

#1 @lancewillett
11 years ago

  • Keywords has-patch dev-feedback added; needs-patch removed

@lancewillett
11 years ago

#2 @lancewillett
11 years ago

As an explanatory note for # 1 above (move permalink out of foreach loop) this is an example debug for an Image post format:

Array
(
    [0] => http://wordpress-trunk:8888/wp-content/uploads/2013/04/navigation-circles-150x150.png
    [1] => http://wordpress-trunk:8888/2013/04/image-test-in-content/navigation-circles/
    [2] => http://wordpress-trunk:8888/wp-content/uploads/2013/04/navigation-circles-300x57.png
    [3] => http://wordpress-trunk:8888/2013/04/image-test-in-content/navigation-circles/
    [4] => http://wordpress-trunk:8888/wp-content/uploads/2013/04/navigation-circles-1024x196.png
    [5] => http://wordpress-trunk:8888/2013/04/image-test-in-content/navigation-circles/
    [6] => http://wordpress-trunk:8888/wp-content/uploads/2013/04/navigation-circles-604x270.png
    [7] => http://wordpress-trunk:8888/2013/04/image-test-in-content/navigation-circles/
    [8] => http://wordpress-trunk:8888/wp-content/uploads/2013/04/navigation-circles-724x138.png
    [9] => http://wordpress-trunk:8888/2013/04/image-test-in-content/navigation-circles/
)

You'll see that the permalink is the same for each size, so it's not necessary to have it in the loop.

#3 @lancewillett
11 years ago

Per kovshenin's keen eye — patch updated to use "full" image size to get the original image source path.

#4 @kovshenin
11 years ago

  • Cc kovshenin added

#5 @lancewillett
11 years ago

The extra get_attachment_link() calls still present in a recent change: r23992 -- they are all still the same, and only one is needed. ;)

#6 @lancewillett
11 years ago

Note that @wonderboymusic's attachment:ticket:23965:23965.diff patch fixes moving out the one reference link out of the loop.

#7 @lancewillett
11 years ago

  • Keywords dev-feedback removed

.2 refreshed

  • Moves the duplicated media permalink out of loop
  • Adds 'full' case for better matching when blogs don't have intermediate sizes

#8 @markjaquith
11 years ago

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

In 24003:

Make get_the_post_format_image() work when intermediate_image_sizes is empty.

props lancewillett. fixes #24060.

Note: See TracTickets for help on using tickets.