wppaste
WordPress

wp_image_editor( int $post_id, false|object $msg = false )

Since
2.9.0
Source
wp-admin/includes/image-edit.php:18
Loads the WP image-editing interface.

Compatibility

WordPress
since 2.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

$post_idint
Attachment post ID.
$msgfalse|objectoptional
Message to display for image editor updates or errors.
Default false.Default: false

Performance profile

How much work a call to wp_image_editor() 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_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
433–531

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

Plugin surface
1 hook

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

Called by
2

2 places 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
  • querycontent queryget_post()one call below wp_image_editor()

Further down the call graph this can also reach 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 · 6 distinct outcomes

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

WhenInstructionsCalls it makes
!isset($meta) && !$big && empty($backup_sizes) && !mime_type()433–441wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_e(), esc_html_e(), get_post_mime_type(), mime_type(), __(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), admin_url(), esc_url(), rand(), _e(), esc_html_e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), _e()
!isset($meta) && !$big && empty($backup_sizes) && !mime_type() && defined('IMAGE_EDIT_OVERWRITE')458–465wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_e(), esc_html_e(), get_post_mime_type(), mime_type(), __(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), admin_url(), esc_url(), rand(), _e(), esc_html_e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), _e(), _e(), esc_attr_e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), _e()
!isset($meta) && !$big && empty($backup_sizes) && !mime_type()461–470wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_e(), esc_html_e(), get_post_mime_type(), mime_type(), __(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), admin_url(), esc_url(), rand(), _e(), esc_html_e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), _e(), _e(), __(), esc_attr_e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), _e()
!isset($meta) && !$big && empty($backup_sizes) && !mime_type()496–502wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_e(), esc_html_e(), get_post_mime_type(), mime_type(), __(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), admin_url(), esc_url(), rand(), _e(), esc_html_e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), wp_constrain_dimensions(), _e(), esc_html_e(), _e(), _e(), _e(), _e(), _e(), _e(), _e()
!isset($meta) && !$big && empty($backup_sizes) && !mime_type() && defined('IMAGE_EDIT_OVERWRITE')521–526wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_e(), esc_html_e(), get_post_mime_type(), mime_type(), __(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), admin_url(), esc_url(), rand(), _e(), esc_html_e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), _e(), _e(), esc_attr_e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), wp_constrain_dimensions(), _e(), esc_html_e(), _e(), _e(), _e(), _e(), _e(), _e(), _e()
!isset($meta) && !$big && empty($backup_sizes) && !mime_type()524–531wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_e(), esc_html_e(), get_post_mime_type(), mime_type(), __(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), admin_url(), esc_url(), rand(), _e(), esc_html_e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), _e(), _e(), __(), esc_attr_e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), _e(), esc_html_e(), esc_html_e(), wp_constrain_dimensions(), _e(), esc_html_e(), _e(), _e(), _e(), _e(), _e(), _e(), _e()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev625433–53125
8.5625433–53125
8.4625433–531252 fewer instructions than PHP 8.3
8.362726–53525
8.262726–53525
8.162726–535257 fewer instructions than PHP 7.4
7.463426–53825

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 wp_image_editor() runs, in this order:

  1. apply_filters( image_edit_thumbnails_separately )filterline 55 (+37 into the body)

    Shows the settings in the Image Editor that allow selecting to edit only the thumbnail of an image.

Uses · 15

Show all 15

Used by · 2

Source code

function wp_image_editor( $post_id, $msg = false ) {	$nonce     = wp_create_nonce( "image_editor-$post_id" );	$meta      = wp_get_attachment_metadata( $post_id );	$thumb     = image_get_intermediate_size( $post_id, 'thumbnail' );	$sub_sizes = isset( $meta['sizes'] ) && is_array( $meta['sizes'] );	$note      = ''; 	if ( isset( $meta['width'], $meta['height'] ) ) {		$big = max( $meta['width'], $meta['height'] );	} else {		die( __( 'Image data does not exist. Please re-upload the image.' ) );	} 	$sizer = $big > 600 ? 600 / $big : 1; 	$backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );	$can_restore  = false; 	if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) ) {		$can_restore = wp_basename( $meta['file'] ) !== $backup_sizes['full-orig']['file'];	} 	if ( $msg ) {		if ( isset( $msg->error ) ) {			$note = "<div class='notice notice-error' role='alert'><p>$msg->error</p></div>";		} elseif ( isset( $msg->msg ) ) {			$note = "<div class='notice notice-success' role='alert'><p>$msg->msg</p></div>";		}	} 	/**	 * Shows the settings in the Image Editor that allow selecting to edit only the thumbnail of an image.	 *	 * @since 6.3.0	 *	 * @param bool $show Whether to show the settings in the Image Editor. Default false.	 */	$edit_thumbnails_separately = (bool) apply_filters( 'image_edit_thumbnails_separately', false ); 	?>	<div class="imgedit-wrap wp-clearfix">	<div id="imgedit-panel-<?php echo $post_id; ?>">	<?php echo $note; ?>	<div class="imgedit-panel-content imgedit-panel-tools wp-clearfix">		<div class="imgedit-menu wp-clearfix">			<button type="button" onclick="imageEdit.toggleCropTool( <?php echo "$post_id, '$nonce'"; ?>, this );" aria-expanded="false" aria-controls="imgedit-crop" class="imgedit-crop button disabled" disabled><?php esc_html_e( 'Crop' ); ?></button>			<button type="button" class="imgedit-scale button" onclick="imageEdit.toggleControls(this);" aria-expanded="false" aria-controls="imgedit-scale"><?php esc_html_e( 'Scale' ); ?></button>			<div class="imgedit-rotate-menu-container">				<button type="button" aria-controls="imgedit-rotate-menu" class="imgedit-rotate button" aria-expanded="false" onclick="imageEdit.togglePopup(this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Image Rotation' ); ?></button>				<div id="imgedit-rotate-menu" class="imgedit-popup-menu">			<?php			// On some setups GD library does not provide imagerotate() - Ticket #11536.			if ( wp_image_editor_supports(				array(					'mime_type' => get_post_mime_type( $post_id ),					'methods'   => array( 'rotate' ),				)			) ) {				$note_no_rotate = '';				?>					<button type="button" class="imgedit-rleft button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 90&deg; left' ); ?></button>					<button type="button" class="imgedit-rright button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 90&deg; right' ); ?></button>					<button type="button" class="imgedit-rfull button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.rotate(180, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 180&deg;' ); ?></button>				<?php			} else {				$note_no_rotate = '<p class="note-no-rotate"><em>' . __( 'Image rotation is not supported by your web host.' ) . '</em></p>';				?>					<button type="button" class="imgedit-rleft button disabled" disabled></button>					<button type="button" class="imgedit-rright button disabled" disabled></button>				<?php			}			?>					<hr />					<button type="button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()" class="imgedit-flipv button"><?php esc_html_e( 'Flip vertical' ); ?></button>					<button type="button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()" class="imgedit-fliph button"><?php esc_html_e( 'Flip horizontal' ); ?></button>					<?php echo $note_no_rotate; ?>				</div>			</div>		</div>		<div class="imgedit-submit imgedit-menu">

Changelog

Introduced in 2.9.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 6.7.7 tag, from src/wp-admin/includes/image-edit.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.