WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#22221 closed defect (bug) (fixed)

get_custom_header() does not handle a default registered header

Reported by: nacin Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: normal Version:
Component: Customize Keywords: has-patch
Focuses: 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 8 years ago.
Debug left in - best tested with Twenty Ten, as it has a default-image.
22221.2.diff (1.2 KB) - added by nacin 8 years ago.

Download all attachments as: .zip

Change History (11)

@nacin
8 years ago

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

#1 @helenyhou
8 years ago

  • Keywords has-patch added

#2 @nacin
8 years ago

  • 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.

#3 @jeffsebring
8 years ago

  • 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?

#4 @jeffsebring
8 years ago

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;
					}
				}
			}

#5 @nacin
8 years ago

  • 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.

#6 follow-up: @nacin
8 years 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.

@nacin
8 years ago

#7 in reply to: ↑ 6 @jeffsebring
8 years 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().

#8 @jeffsebring
8 years ago

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

I'm using PHP 5.4.8.

#9 @nacin
8 years ago

  • 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.