Opened 7 months ago

Closed 6 months ago

#22221 closed defect (bug) (fixed)

get_custom_header() does not handle a default registered header

Reported by: nacin Owned by: nacin
Priority: normal Milestone: 3.5
Component: Appearance Version:
Severity: normal Keywords: has-patch
Cc:

Description

get_custom_header() handles two sources of data: the data of a random header image, and the saved header_image_data theme mod.

Before a theme is saved, header_image_data is not populated. If the theme has a default-image rather than a random-default, get_custom_header() will end up having no values for 'url' or 'thumbnail_url'.

Attached patch fixes that. Ideally, some logic in custom-header.php, this new logic, and the logic in _get_random_header_data() should come together in a much nicer way.

Attachments (2)

22221.diff (1.8 KB) - added by nacin 7 months ago.
Debug left in - best tested with Twenty Ten, as it has a default-image.
22221.2.diff (1.2 KB) - added by nacin 6 months ago.

Download all attachments as: .zip

Change History (11)

nacin7 months ago

Debug left in - best tested with Twenty Ten, as it has a default-image.

  • Keywords has-patch added
  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 22436:

Allow get_custom_header() to handle a default registered header that has yet to be saved to the database. fixes #22221.

  • Resolution fixed deleted
  • Status changed from closed to reopened

I'm using a default header, yet $_wp_default_headers is null, and throwing an error on theme.php line 1037. Maybe check it before the loop?

This should take care of it:

			if ( $_wp_default_headers ) {
				foreach ( $_wp_default_headers as $header => $details ) {
					$url = vsprintf( $details['url'], $directory_args );
					if ( $default_image == $url ) {
						$data = $details;
						$data['url'] = $url;
						$data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args );
						break;
					}
				}
			}
  • Resolution set to fixed
  • Status changed from reopened to closed

In 22544:

Ensure $_wp_default_headers is set before iterating over it in get_custom_header(). props jeffsebring. fixes #22221.

comment:6 follow-up: ↓ 7   nacin6 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Are you using a default header as in 'default-image' => $something, but not actually registering any headers with register_default_headers()? It looks like we support this (see Custom_Header::reset_header_image()), so we can make an adjustment. Patch incoming.

nacin6 months ago

comment:7 in reply to: ↑ 6   jeffsebring6 months ago

Replying to nacin:

Are you using a default header as in 'default-image' => $something, but not actually registering any headers with register_default_headers()? It looks like we support this (see Custom_Header::reset_header_image()), so we can make an adjustment. Patch incoming.

That is exactly how I am doing it. I set the default-image in the add_theme_support() array argument, without using register_default_headers().

I should add that the default image still displays, beneath the notice.

I'm using PHP 5.4.8.

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

In 22669:

In get_custom_header(), support a default header that is registered using default-image but not register_default_headers(). fixes #22221.

Note: See TracTickets for help on using tickets.