Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#38633 closed defect (bug) (fixed)

get_header_image_tag() doesn't always return the correct image

Reported by: bradyvercher's profile bradyvercher Owned by: joemcgill's profile joemcgill
Milestone: 4.7 Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch commit
Focuses: Cc:

Description

get_header_image_tag() relies on get_custom_header() to retrieve the URL for the current header image, however get_custom_header() doesn't always return the correct URL.

Most of the header image tags rely on get_header_image(), which uses the header_image theme mod. That theme mod should always contain the direct URL to an image, remove-header, random-default-image, or random-uploaded-image.

get_custom_header() uses the header_image_data theme mod, which will be empty when the header_image theme mod has remove-header, random-default-image, or random-uploaded-image. When that's the case, it will return the URL for the default image instead.

I'm not sure why get_custom_header() relies on a different theme mod or why the behavior is different. The URL it returns doesn't appear to be used anywhere else in core. At the very least, get_header_image_tag() should be updated to use get_header_image() for the image URL.

Attachments (1)

38663.diff (423 bytes) - added by bradyvercher 8 years ago.

Download all attachments as: .zip

Change History (6)

@bradyvercher
8 years ago

#1 @bradyvercher
8 years ago

  • Keywords has-patch added

Whoops, looks like I botched that patch number! 38663.diff uses get_header_image() for the image URL in get_header_image_tag() to make sure remove-header, random-default-image, and random-uploaded-image settings are respected.

This ticket was mentioned in Slack in #core-themes by bradyvercher. View the logs.


8 years ago

#3 @celloexpressions
8 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 4.7
  • Owner set to joemcgill
  • Status changed from new to reviewing

Good catch, looks good to me.

#4 @joemcgill
8 years ago

38663.diff Looks good. I believe we relied on the data from get_custom_header() in [35594] mainly due to performance concerns. The potential for the default image to be displayed was likely an oversight.

#5 @joemcgill
8 years ago

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

In 39121:

Themes: Improve reliability of URL used in get_header_image_tag().

get_header_image_tag() relies on the data returned by get_custom_header()
to build the attributes for the header <img> element. However,
get_custom_header() relies on data from the header_image_data theme
mod rather than the header_image theme mod that get_header_image() uses.
This can create inconsistencies when no header image is set, but a theme
supports a default header image.

This fixes the issue by making get_custom_image_tag() rely on the URL
returned by get_header_image() instead.

Props bradyvercher.
Fixes #38633.

Note: See TracTickets for help on using tickets.