Custom_Image_Header::show_header_selector( string $type = 'default' )
- Since
- 3.0.0
- Source
wp-admin/includes/class-custom-image-header.php:314
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
- Scaling
- Scales with input
- Instructions
- 13–34
- Plugin surface
- None
- Called by
- 1
Reaches the database via get_posts().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 86.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_posts()one call below Custom_Image_Header::show_header_selector() - optionoption read or write
get_option()one call below Custom_Image_Header::show_header_selector() - hookthird-party callbacks
apply_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.
| When | Instructions | Calls it makes |
|---|---|---|
$type === "default" | 13–14 | none |
$type !== "default" | 15–16 | get_uploaded_header_images() |
$type === "default" | 31–32 | is_random_header_image(), checked(), _e() |
$type !== "default" | 33–34 | get_uploaded_header_images(), is_random_header_image(), checked(), _e() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 86 | 13–34 | 6 | |
| 8.5 | 86 | 13–34 | 6 | |
| 8.4 | 86 | 13–34 | 6 | |
| 8.3 | 86 | 13–34 | 6 | |
| 8.2 | 86 | 13–34 | 6 | |
| 8.1 | 86 | 13–34 | 6 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 87 | 13–34 | 6 |
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
- get_uploaded_header_images()Gets the header images uploaded for the active theme.
- checked()Outputs the HTML checked attribute.
- is_random_header_image()Checks if random header image is in use.
- _e()Displays translated text.
- esc_attr()Escaping for HTML attributes.
- get_theme_mod()Retrieves theme modification value for the active theme.
- esc_url()Checks and cleans a URL.
- set_url_scheme()Sets the scheme for a URL.
Used by · 1
- Custom_Image_Header::step_1()Displays first step of custom header image page.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.