wppaste
WordPress

Custom_Image_Header::show_header_selector( string $type = 'default' )

Since
3.0.0
Source
wp-admin/includes/class-custom-image-header.php:314
Displays UI for selecting one of several default headers.

Description

Shows the random image option if this theme has multiple header images.
Random image option is on by default if no header has been set.

Compatibility

WordPress
since 3.0.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$typestringoptional
The header type. One of 'default' (for the Uploaded Images control) or 'uploaded' (for the Uploaded Images control).Default: 'default'

Performance profile

How much work a call to Custom_Image_Header::show_header_selector() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_posts().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
13–34

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 86.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_posts()one call below Custom_Image_Header::show_header_selector()
  • optionoption read or writeget_option()one call below Custom_Image_Header::show_header_selector()
  • hookthird-party callbacksapply_filters()one call below Custom_Image_Header::show_header_selector()

Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 4 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost Custom_Image_Header::show_header_selector() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$type === "default"13–14none
$type !== "default"15–16get_uploaded_header_images()
$type === "default"31–32is_random_header_image(), checked(), _e()
$type !== "default"33–34get_uploaded_header_images(), is_random_header_image(), checked(), _e()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev8613–346
8.58613–346
8.48613–346
8.38613–346
8.28613–346
8.18613–3461 fewer instruction than PHP 7.4
7.48713–346

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 8

Used by · 1

Source code

	public function show_header_selector( $type = 'default' ) {		if ( 'default' === $type ) {			$headers = $this->default_headers;		} else {			$headers = get_uploaded_header_images();			$type    = 'uploaded';		} 		if ( 1 < count( $headers ) ) {			echo '<div class="random-header">';			echo '<label><input name="default-header" type="radio" value="random-' . $type . '-image"' . checked( is_random_header_image( $type ), true, false ) . ' />';			_e( '<strong>Random:</strong> Show a different image on each page.' );			echo '</label>';			echo '</div>';		} 		echo '<div class="available-headers">'; 		foreach ( $headers as $header_key => $header ) {			$header_thumbnail = $header['thumbnail_url'];			$header_url       = $header['url'];			$header_alt_text  = empty( $header['alt_text'] ) ? '' : $header['alt_text']; 			echo '<div class="default-header">';			echo '<label><input name="default-header" type="radio" value="' . esc_attr( $header_key ) . '" ' . checked( $header_url, get_theme_mod( 'header_image' ), false ) . ' />';			$width = '';			if ( ! empty( $header['attachment_id'] ) ) {				$width = ' width="230"';			}			echo '<img src="' . esc_url( set_url_scheme( $header_thumbnail ) ) . '" alt="' . esc_attr( $header_alt_text ) . '"' . $width . ' /></label>';			echo '</div>';		} 		echo '<div class="clear"></div></div>';	}

Changelog

Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/class-custom-image-header.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.