Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#50160 closed defect (bug) (fixed)

Enable captions for image widgets with custom image size

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

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 6 years 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 6 years ago.
Image Widget with a custom image size after applying the patch

Download all attachments as: .zip

Change History (10)

@kasparsd
6 years 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.


6 years ago
#1

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
6 years ago

Image Widget with a custom image size after applying the patch

#2 @kasparsd
6 years ago

  • Keywords has-patch has-unit-tests added

​kasparsd commented on ​PR #269:


6 years ago
#3

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

#4 @SergeyBiryukov
6 years ago

  • Milestone Awaiting Review → 5.5

#5 @JavierCasares
6 years ago

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

#6 @audrasjb
6 years 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.


6 years ago

#8 @SergeyBiryukov
6 years ago

  • Owner set to SergeyBiryukov
  • Resolution → fixed
  • Status new → 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.