Custom_Image_Header::get_header_dimensions( array $dimensions ): array
- Since
- 3.9.0
- Source
wp-admin/includes/class-custom-image-header.php:1270
Compatibility
- WordPress
- since 3.9.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
$dimensionsarray
Return value
array- dst_height and dst_width of header image.
Performance profile
How much work a call to Custom_Image_Header::get_header_dimensions() 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
- Trivial
- Scaling
- Constant
- Instructions
- 51–75
- Plugin surface
- None
- Called by
- 2
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 90.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below Custom_Image_Header::get_header_dimensions()
What one call costs · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost Custom_Image_Header::get_header_dimensions() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 51–63 | absint(), absint(), get_theme_support(), get_theme_support(), current_theme_supports(), current_theme_supports(), current_theme_supports() |
| always | 57–66 | absint(), absint(), get_theme_support(), get_theme_support(), current_theme_supports(), current_theme_supports(), current_theme_supports(), absint() |
| always | 57–69 | absint(), absint(), get_theme_support(), get_theme_support(), current_theme_supports(), current_theme_supports(), current_theme_supports(), get_theme_support() |
| always | 63–72 | absint(), absint(), get_theme_support(), get_theme_support(), current_theme_supports(), current_theme_supports(), current_theme_supports(), get_theme_support(), absint() |
| always | 64–69 | absint(), absint(), get_theme_support(), get_theme_support(), current_theme_supports(), current_theme_supports(), current_theme_supports(), absint(), absint() |
| always | 70–75 | absint(), absint(), get_theme_support(), get_theme_support(), current_theme_supports(), current_theme_supports(), current_theme_supports(), get_theme_support(), absint(), absint() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 90 | 51–75 | 12 | |
| 8.5 | 90 | 51–75 | 12 | |
| 8.4 | 90 | 51–75 | 12 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 96 | 54–81 | 12 | |
| 8.2 | 96 | 54–81 | 12 | |
| 8.1 | 96 | 54–81 | 12 | |
| 7.4 | 96 | 54–81 | 12 |
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 · 3
- absint()Converts a value to non-negative integer.
- get_theme_support()Gets the theme support arguments passed when registering that support.
- current_theme_supports()Checks a theme's support for a given feature.
Used by · 2
- Custom_Image_Header::ajax_header_crop()Gets attachment uploaded by Media Manager, crops it, then saves it as a new object. Returns JSON-encoded object details.
- Custom_Image_Header::step_3()Displays third step of custom header image page.
Source code
final public function get_header_dimensions( $dimensions ) { $max_width = 0; $width = absint( $dimensions['width'] ); $height = absint( $dimensions['height'] ); $theme_height = get_theme_support( 'custom-header', 'height' ); $theme_width = get_theme_support( 'custom-header', 'width' ); $has_flex_width = current_theme_supports( 'custom-header', 'flex-width' ); $has_flex_height = current_theme_supports( 'custom-header', 'flex-height' ); $has_max_width = current_theme_supports( 'custom-header', 'max-width' ); $dst = array( 'dst_height' => null, 'dst_width' => null, ); // For flex, limit size of image displayed to 1500px unless theme says otherwise. if ( $has_flex_width ) { $max_width = 1500; } if ( $has_max_width ) { $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); } $max_width = max( $max_width, $theme_width ); if ( $has_flex_height && ( ! $has_flex_width || $width > $max_width ) ) { $dst['dst_height'] = absint( $height * ( $max_width / $width ) ); } elseif ( $has_flex_height && $has_flex_width ) { $dst['dst_height'] = $height; } else { $dst['dst_height'] = $theme_height; } if ( $has_flex_width && ( ! $has_flex_height || $width > $max_width ) ) { $dst['dst_width'] = absint( $width * ( $max_width / $width ) ); } elseif ( $has_flex_width && $has_flex_height ) { $dst['dst_width'] = $width; } else { $dst['dst_width'] = $theme_width; } return $dst; }Changelog
Introduced in 3.9.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 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.