wp_image_editor( int $post_id, false|object $msg = false )
- Since
- 2.9.0
- Source
wp-admin/includes/image-edit.php:18
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
- Scaling
- Constant
- Instructions
- 431–541
- Plugin surface
- 1 hook
- Called by
- 2
Reaches the database via get_post().
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 629.
Third-party callbacks on 'image_edit_thumbnails_separately' run inside this call, and their cost is not bounded by anything here.
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()called directly - querycontent query
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($meta) && !$big && empty($backup_sizes) && !mime_type() && !$meta | 431–439 | wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_x(), 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_x(), 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() && !$meta && defined('IMAGE_EDIT_OVERWRITE') | 456–463 | wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_x(), 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_x(), 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() && !$meta | 459–468 | wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_x(), 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_x(), 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() && !$meta | 506–512 | wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_x(), 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_x(), 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(), esc_url(), esc_attr(), esc_attr(), _e(), _e(), _e(), _e(), _e(), _e() |
!isset($meta) && !$big && empty($backup_sizes) && !mime_type() && !$meta && defined('IMAGE_EDIT_OVERWRITE') | 531–536 | wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_x(), 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_x(), 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(), esc_url(), esc_attr(), esc_attr(), _e(), _e(), _e(), _e(), _e(), _e() |
!isset($meta) && !$big && empty($backup_sizes) && !mime_type() && !$meta | 534–541 | wp_create_nonce(), wp_get_attachment_metadata(), image_get_intermediate_size(), __(), exit(), get_post_meta(), apply_filters(), esc_html_e(), esc_html_x(), 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_x(), 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(), esc_url(), esc_attr(), esc_attr(), _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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 629 | 431–541 | 25 | |
| 8.5 | 629 | 431–541 | 25 | |
| 8.4 | 629 | 431–541 | 25 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 631 | 26–545 | 25 | |
| 8.2 | 631 | 26–545 | 25 | |
| 8.1 | 631 | 26–545 | 25 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 632 | 26–545 | 25 |
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:
- 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 · 17
- wp_create_nonce()Creates a cryptographic token tied to a specific action, user, user session, and window of time.
- wp_get_attachment_metadata()Retrieves attachment metadata for attachment ID.
- image_get_intermediate_size()Retrieves the image's intermediate size (resized) path, width, and height.
- __()Retrieves the translation of $text.
- get_post_meta()Retrieves a post meta field for the given post ID.
- wp_basename()i18n-friendly version of basename().
- apply_filters()Calls the callback functions that have been added to a filter hook.
- esc_html_e()Displays translated text that has been escaped for safe use in HTML output.
- esc_html_x()Translates string with gettext context, and escapes it for safe use in HTML output.
- wp_image_editor_supports()Tests whether there is an editor that supports a given mime type or methods.
- get_post_mime_type()Retrieves the mime type of an attachment based on the ID.
- esc_url()Checks and cleans a URL.
Show all 17
- admin_url()Retrieves the URL to the admin area for the current site.
- _e()Displays translated text.
- esc_attr_e()Displays translated text that has been escaped for safe use in an attribute.
- wp_constrain_dimensions()Calculates the new dimensions for a down-sampled image.
- esc_attr()Escaping for HTML attributes.
Used by · 2
- edit_form_image_editor()Displays the image and editor in the post editor
- wp_ajax_image_editor()Handles image editing via AJAX.
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 echo esc_html_x( 'Scale', 'verb' ); ?></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° 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° 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°' ); ?></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.
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/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.