image_size_input_fields( WP_Post $post, bool|string $check = '' ): array<string,
- Since
- 2.7.0
- Source
wp-admin/includes/media.php:1209
Compatibility
- WordPress
- since 2.7.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
$postWP_Post$checkbool|stringoptional- Default:
''
Return value
array<string,- string> An array of data for the image size input fields.
Performance profile
How much work a call to image_size_input_fields() 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
- Light
- Scaling
- Scales with input
- Instructions
- 36–42
- Plugin surface
- 1 hook
- Called by
- 1
Touches nothing outside its own arguments.
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 118.
Third-party callbacks on 'image_size_names_choose' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach query, option, 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 · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost image_size_input_fields() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($check) | 36–37 | __(), __(), __(), __(), thumbnail(), __() |
empty($check) | 41–42 | __(), __(), __(), __(), thumbnail(), get_user_setting(), __() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 118 | 36–42 | 10 | |
| 8.5 | 118 | 36–42 | 10 | |
| 8.4 | 118 | 36–42 | 10 | 1 fewer instruction than PHP 8.3 |
| 8.3 | 119 | 39–45 | 10 | |
| 8.2 | 119 | 39–45 | 10 | |
| 8.1 | 119 | 39–45 | 10 | |
| 7.4 | 119 | 39–45 | 10 |
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.
Hooks and filters fired · 1
One hook fires while image_size_input_fields() runs, in this order:
- apply_filters( image_size_names_choose )filterline 1218 (+9 into the body)
Filters the names and labels of the default image sizes.
Uses · 5
- apply_filters()Calls the callback functions that have been added to a filter hook.
- __()Retrieves the translation of $text.
- get_user_setting()Retrieves user interface setting value based on setting name.
- image_downsize()Scales an image to fit a particular size (such as 'thumb' or 'medium').
- disabled()Outputs the HTML disabled attribute.
Used by · 1
- get_attachment_fields_to_edit()Retrieves the attachment fields to edit form fields.
Source code
function image_size_input_fields( $post, $check = '' ) { /** * Filters the names and labels of the default image sizes. * * @since 3.3.0 * * @param string[] $size_names Array of image size labels keyed by their name. Default values * include 'Thumbnail', 'Medium', 'Large', and 'Full Size'. */ $size_names = apply_filters( 'image_size_names_choose', array( 'thumbnail' => __( 'Thumbnail' ), 'medium' => __( 'Medium' ), 'large' => __( 'Large' ), 'full' => __( 'Full Size' ), ) ); if ( empty( $check ) ) { $check = get_user_setting( 'imgsize', 'medium' ); } $output = array(); foreach ( $size_names as $size => $label ) { $downsize = image_downsize( $post->ID, $size ); $checked = ''; // Is this size selectable? $enabled = ( $downsize[3] || 'full' === $size ); $css_id = "image-size-{$size}-{$post->ID}"; // If this size is the default but that's not available, don't select it. if ( $size === $check ) { if ( $enabled ) { $checked = " checked='checked'"; } else { $check = ''; } } elseif ( ! $check && $enabled && 'thumbnail' !== $size ) { /* * If $check is not enabled, default to the first available size * that's bigger than a thumbnail. */ $check = $size; $checked = " checked='checked'"; } $html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />"; $html .= "<label for='{$css_id}'>$label</label>"; // Only show the dimensions if that choice is available. if ( $enabled ) { $html .= " <label for='{$css_id}' class='help'>" . sprintf( '(%d × %d)', $downsize[1], $downsize[2] ) . '</label>'; } $html .= '</div>'; $output[] = $html; } return array( 'label' => __( 'Size' ), 'input' => 'html', 'html' => implode( "\n", $output ), );}Changelog
Introduced in 2.7.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
array to array<string,.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/media.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.