WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 23 months ago

#23945 closed defect (bug) (fixed)

get_the_post_format_image doesn't use specificed image size

Reported by: davidwilliamson Owned by: markjaquith
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.6
Component: Post Formats Keywords:
Focuses: Cc:

Description

Since setup_postdata() runs when the_post() is called and it sets $post->format_content using 'full' as the default image size there is no way to use get_the_post_format_image() or the_post_format_image() to specify a different size. get_the_post_format_image() returns $post->format_content if it's already set rather than retrieving the specified image size.

Attached patch removes the check for $post->format_content which allows the image size to be specified later.

Attachments (4)

23945.patch (455 bytes) - added by davidwilliamson 2 years ago.
23945.2.diff (414 bytes) - added by davidwilliamson 2 years ago.
23945.3.diff (485 bytes) - added by SergeyBiryukov 23 months ago.
23945.diff (490 bytes) - added by wonderboymusic 23 months ago.

Download all attachments as: .zip

Change History (16)

@davidwilliamson2 years ago

comment:1 @SergeyBiryukov2 years ago

  • Milestone changed from Awaiting Review to 3.6

@davidwilliamson2 years ago

comment:2 @davidwilliamson2 years ago

attachment:23945.2.diff replaces the if ( isset( $post->format_content ) ) with a check to see if the image already contained in $post->format_content is the same size as what is being requested. I believe this more closely follows the original intent of the check for whether $post->format_content is set rather than just deleting it all together.

There may be a better way to check whether the image already contained in $post->format_content is the appropriate size but I'm not sure how. There also may very well be a better regex to use when checking, I am not very experienced with regular expressions.

@SergeyBiryukov23 months ago

comment:4 @SergeyBiryukov23 months ago

23945.3.diff uses strpos() instead of preg_match().

comment:5 follow-up: @lancewillett23 months ago

@davidwilliamson Could you provide steps to repeat this? I'm able to get a custom post thumbnail size to work in Twenty Thirteen by using add_image_size( 'twentythirteen-image-post', 724, 1288 );.

Related, though -- I'm running into a problem with WP.com and image sizes. We ignore "intermediate_image_sizes" since we use dynamic image sizing; which means the $sizes loop in calculating which content to remove from content never runs.

I can open a new ticket for it since it's only semi-related to this one.

comment:6 in reply to: ↑ 5 @lancewillett23 months ago

Replying to lancewillett:

I can open a new ticket for it since it's only semi-related to this one.

See #24060

comment:7 follow-up: @davidwilliamson23 months ago

@lancewillett: I just went in, updated trunk to r23974, switched themes to Twenty Thirteen, deleted all my content and re-uploaded the theme test data and regenerated thumbnails. I also created new image posts using the new workflow for 3.6 as well as ones like the test cases with significantly larger original images because the test images are smaller than the new size you are defining with add_image_size( 'twentythirteen-image-post', 724, 1288 );. The problem is still there - although it isn't visible in Twenty Thirteen because of css rules unless you look at the page source. If you look at the source of the page and the image source is the full size version rather than the twentythirteen-image-post version and has the class attachment-full instead of the expected attachment-twentythirteen-image-post.

If you apply the patch attachment:23945.3.diff the class changes to attachment-twentythirteen-image-post and the image source is the corresponding resized version.

comment:8 in reply to: ↑ 7 ; follow-up: @kovshenin23 months ago

Replying to davidwilliamson: Can you also please check if the patch in #24002 does the trick? Thanks!

comment:9 in reply to: ↑ 8 @davidwilliamson23 months ago

Replying to kovshenin:
Looks like the patch in #24002 fixes things.

comment:10 follow-up: @lancewillett23 months ago

@kovshenin We should ping Jaquith to review and commit today.

comment:11 in reply to: ↑ 10 @lancewillett23 months ago

Replying to lancewillett:

@kovshenin We should ping Jaquith to review and commit today.

I mean, #24002 fix.

@wonderboymusic23 months ago

comment:12 @markjaquith23 months ago

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

In 24079:

Allow the_post_format_image() to choose an image size late in the game.

props davidwilliamson, SergeyBiryukov. fixes #23945.

Note: See TracTickets for help on using tickets.