WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 3 weeks ago

#50160 closed defect (bug) (fixed)

Enable captions for image widgets with custom image size

Reported by: kasparsd Owned by: SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version: 5.4.1
Component: Widgets Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Image widgets with image size set to "custom" and custom width and height values do not render captions on the widget output.

This happens because _wp_get_image_size_from_meta() with custom as the first parameter returns false here and sets the $caption_size value to false which in turn causes $width to be 0 which then disables caption output during img_caption_shortcode() here.

Attachments (2)

image-widget-caption.png (1.4 MB) - added by kasparsd 3 months ago.
Demo of the image caption missing for images with custom sizes
image-widget-after-fix-with-custom-width.png (543.5 KB) - added by kasparsd 3 months ago.
Image Widget with a custom image size after applying the patch

Download all attachments as: .zip

Change History (10)

@kasparsd
3 months ago

Demo of the image caption missing for images with custom sizes

This ticket was mentioned in PR #269 on WordPress/wordpress-develop by kasparsd.


3 months ago

Trac ticket: https://core.trac.wordpress.org/ticket/50160

Use the width of a custom image size in an Image Widget instead of doing a lookup for an image size custom which doesn't have a registered width and height.

This ensures that the $width used for setting the caption width is not 0 and the captions are rendered for images with custom sizes.

@kasparsd
3 months ago

Image Widget with a custom image size after applying the patch

#2 @kasparsd
3 months ago

  • Keywords has-patch has-unit-tests added

#3 @prbot
3 months ago

kasparsd commented on PR #269:

[The one failing Travis run](https://travis-ci.com/github/WordPress/wordpress-develop/jobs/333513693) appears to be a Travis issue.

#4 @SergeyBiryukov
3 months ago

  • Milestone changed from Awaiting Review to 5.5

#5 @JavierCasares
3 months ago

Tested on TwentySixteen and TwentyTwnety. The patch worked. I did not tested the Unit Test.

#6 @audrasjb
3 months ago

The pull request looks good to go (the Travis error is not related to this patch).

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


3 weeks ago

#8 @SergeyBiryukov
3 weeks ago

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

In 48557:

Widgets: Make sure image widgets with custom image size render captions.

Props kasparsd, JavierCasares, audrasjb.
Fixes #50160.

Note: See TracTickets for help on using tickets.