wppaste
WordPress

image_size_input_fields( WP_Post $post, bool|string $check = '' ): array

Since
2.7.0
Source
wp-admin/includes/media.php:1191
Retrieves HTML for the size radio buttons with the specified one checked.

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

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

Touches nothing outside its own arguments.

Scaling
Scales with input

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

Instructions
36–42

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

Plugin surface
1 hook

Third-party callbacks on 'image_size_names_choose' run inside this call, and their cost is not bounded by anything here.

Called by
1

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

What it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
!empty($check)36–37__(), __(), __(), __(), thumbnail(), __()
empty($check)41–42__(), __(), __(), __(), thumbnail(), get_user_setting(), __()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev11836–4210
8.511836–4210
8.411836–42101 fewer instruction than PHP 8.3
8.311939–4510
8.211939–4510
8.111939–4510
7.411939–4510

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:

  1. apply_filters( image_size_names_choose )filterline 1200 (+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

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&nbsp;&times;&nbsp;%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.

  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.

7.0.4
Return type changed from array to array<string,.verified against source
2.7.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 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.