wp_ajax_image_editor()
- Since
- 3.1.0
- Source
wp-admin/includes/ajax-actions.php:2678
Compatibility
- WordPress
- since 3.1.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.
Performance profile
How much work a call to wp_ajax_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
- 38–63
- Plugin surface
- None
- Called by
- 0
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 77.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below wp_ajax_image_editor() - querycontent query
get_post()one call below wp_ajax_image_editor() - optionoption read or write
get_option()one call below wp_ajax_image_editor()
Further down the call graph this can also reach 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 · 30 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_ajax_image_editor() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($attachment_id) && empty($msg) | 38–45 | wp_die(), check_ajax_referer(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
!empty($attachment_id) && current_user_can() && empty($msg) | 40–47 | current_user_can(), check_ajax_referer(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
empty($attachment_id) && empty($msg) | 42–48 | wp_die(), check_ajax_referer(), wp_restore_image(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
empty($attachment_id) && empty($msg) | 43–47 | wp_die(), check_ajax_referer(), wp_save_image(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
empty($attachment_id) && !empty($msg) | 43–50 | wp_die(), check_ajax_referer(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
!empty($attachment_id) && !current_user_can() && empty($msg) | 43–50 | current_user_can(), wp_die(), check_ajax_referer(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
!empty($attachment_id) && current_user_can() && empty($msg) | 44–50 | current_user_can(), check_ajax_referer(), wp_restore_image(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
!empty($attachment_id) && current_user_can() && empty($msg) | 45–49 | current_user_can(), check_ajax_referer(), wp_save_image(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
!empty($attachment_id) && current_user_can() && !empty($msg) | 45–52 | current_user_can(), check_ajax_referer(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
empty($attachment_id) && !empty($msg) | 47–53 | wp_die(), check_ajax_referer(), wp_restore_image(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
!empty($attachment_id) && !current_user_can() && empty($msg) | 47–53 | current_user_can(), wp_die(), check_ajax_referer(), wp_restore_image(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
empty($attachment_id) && empty($msg) | 48–50 | wp_die(), check_ajax_referer(), wp_save_image(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
18 further outcomes, up to 63 instructions
empty($attachment_id) && !empty($msg) | 48–52 | wp_die(), check_ajax_referer(), wp_save_image(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
!empty($attachment_id) && !current_user_can() && empty($msg) | 48–52 | current_user_can(), wp_die(), check_ajax_referer(), wp_save_image(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
!empty($attachment_id) && !current_user_can() && !empty($msg) | 48–55 | current_user_can(), wp_die(), check_ajax_referer(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
!empty($attachment_id) && current_user_can() && !empty($msg) | 49–55 | current_user_can(), check_ajax_referer(), wp_restore_image(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
!empty($attachment_id) && current_user_can() && empty($msg) | 50–52 | current_user_can(), check_ajax_referer(), wp_save_image(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
!empty($attachment_id) && current_user_can() && !empty($msg) | 50–54 | current_user_can(), check_ajax_referer(), wp_save_image(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
empty($attachment_id) | 51–53 | wp_die(), check_ajax_referer(), wp_save_image(), wp_send_json_error(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
!empty($attachment_id) && !current_user_can() && !empty($msg) | 52–58 | current_user_can(), wp_die(), check_ajax_referer(), wp_restore_image(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
empty($attachment_id) | 53–55 | wp_die(), check_ajax_referer(), wp_save_image(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
!empty($attachment_id) && current_user_can() | 53–55 | current_user_can(), check_ajax_referer(), wp_save_image(), wp_send_json_error(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
!empty($attachment_id) && !current_user_can() && empty($msg) | 53–55 | current_user_can(), wp_die(), check_ajax_referer(), wp_save_image(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
!empty($attachment_id) && !current_user_can() && !empty($msg) | 53–57 | current_user_can(), wp_die(), check_ajax_referer(), wp_save_image(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
!empty($attachment_id) && current_user_can() | 55–57 | current_user_can(), check_ajax_referer(), wp_save_image(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
empty($attachment_id) && !empty($msg) | 56–58 | wp_die(), check_ajax_referer(), wp_save_image(), wp_send_json_error(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
!empty($attachment_id) && !current_user_can() | 56–58 | current_user_can(), wp_die(), check_ajax_referer(), wp_save_image(), wp_send_json_error(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message() |
!empty($attachment_id) && current_user_can() && !empty($msg) | 58–60 | current_user_can(), check_ajax_referer(), wp_save_image(), wp_send_json_error(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
!empty($attachment_id) && !current_user_can() | 58–60 | current_user_can(), wp_die(), check_ajax_referer(), wp_save_image(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
!empty($attachment_id) && !current_user_can() && !empty($msg) | 61–63 | current_user_can(), wp_die(), check_ajax_referer(), wp_save_image(), wp_send_json_error(), wp_send_json_success(), ob_start(), wp_image_editor(), ob_get_clean(), message(), message() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 77 | 38–63 | 8 | |
| 8.5 | 77 | 38–63 | 8 | |
| 8.4 | 77 | 38–63 | 8 | |
| 8.3 | 77 | 38–63 | 8 | |
| 8.2 | 77 | 38–63 | 8 | 1 more instruction than PHP 8.1 |
| 8.1 | 76 | 38–67 | 8 | |
| 7.4 | 76 | 38–67 | 8 |
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 · 8
- current_user_can()Returns whether the current user has the specified capability.
- wp_die()Kills WordPress execution and displays HTML page with an error message.
- check_ajax_referer()Verifies the Ajax request to prevent processing requests external of the blog.
- wp_save_image()Saves image to post, along with enqueued changes in `$_REQUEST['history']`.
- wp_send_json_error()Sends a JSON response back to an Ajax request, indicating failure.
- wp_send_json_success()Sends a JSON response back to an Ajax request, indicating success.
- wp_restore_image()Restores the metadata for a given attachment.
- wp_image_editor()Loads the WP image-editing interface.
Source code
function wp_ajax_image_editor() { $attachment_id = (int) $_POST['postid']; if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) { wp_die( -1 ); } check_ajax_referer( "image_editor-$attachment_id" ); require_once ABSPATH . 'wp-admin/includes/image-edit.php'; $msg = false; switch ( $_POST['do'] ) { case 'save': $msg = wp_save_image( $attachment_id ); if ( ! empty( $msg->error ) ) { wp_send_json_error( $msg ); } wp_send_json_success( $msg ); break; case 'scale': $msg = wp_save_image( $attachment_id ); break; case 'restore': $msg = wp_restore_image( $attachment_id ); break; } ob_start(); wp_image_editor( $attachment_id, $msg ); $html = ob_get_clean(); if ( ! empty( $msg->error ) ) { wp_send_json_error( array( 'message' => $msg, 'html' => $html, ) ); } wp_send_json_success( array( 'message' => $msg, 'html' => $html, ) );}Changelog
Introduced in 3.1.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 6.8.8 tag, from
src/wp-admin/includes/ajax-actions.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.