edit_form_image_editor( WP_Post $post )
- Since
- 3.5.0
- Source
wp-admin/includes/media.php:3119
Displays the image and editor in the post editor
Parameters
$postWP_Post- A post object.
Hooks fired · 2
2 hooks fire while edit_form_image_editor() runs, in this order:
- do_action( wp_edit_form_attachment_display )actionline 3224 (+105 into the body)
Fires when an attachment type can't be rendered in the edit form.
- apply_filters( activate_tinymce_for_media_description )filterline 3275 (+156 into the body)
Filters the TinyMCE argument for the media description field on the attachment details screen.
Uses · 25
- wp_get_attachment_image_src()Retrieves an image to represent an attachment.
- get_post_meta()Retrieves a post meta field for the given post ID.
- wp_get_attachment_url()Retrieves the URL for an attachment.
- wp_attachment_is_image()Determines whether an attachment is an image.
- wp_image_editor_supports()Tests whether there is an editor that supports a given mime type or methods.
- wp_create_nonce()Creates a cryptographic token tied to a specific action, user, user session, and window of time.
- esc_attr__()Retrieves the translation of $text and escapes it for safe use in an attribute.
- set_url_scheme()Sets the scheme for a URL.
- wp_image_editor()Loads the WP image-editing interface.
- wp_attachment_is()Verifies an attachment is of a given type.
- wp_maybe_generate_attachment_metadata()Maybe attempts to generate attachment metadata, if missing.
- wp_audio_shortcode()Builds the Audio shortcode output.
Show all 25
- wp_get_attachment_metadata()Retrieves attachment metadata for attachment ID.
- get_post_thumbnail_id()Retrieves the post thumbnail ID.
- wp_video_shortcode()Builds the Video shortcode output.
- do_action()Calls the callback functions that have been added to an action hook.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- _e()Displays translated text.
- esc_attr()Escaping for HTML attributes.
- __()Retrieves the translation of $text.
- esc_url()Checks and cleans a URL.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_editor()Renders an editor.
- format_to_edit()Acts on text which is about to be edited.
- get_compat_media_markup()
Source
function edit_form_image_editor( $post ) { $open = isset( $_GET['image-editor'] ); if ( $open ) { require_once ABSPATH . 'wp-admin/includes/image-edit.php'; } $thumb_url = false; $attachment_id = (int) $post->ID; if ( $attachment_id ) { $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); } $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); $att_url = wp_get_attachment_url( $post->ID ); ?> <div class="wp_attachment_holder wp-clearfix"> <?php if ( wp_attachment_is_image( $post->ID ) ) : $image_edit_button = ''; if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { $nonce = wp_create_nonce( "image_editor-$post->ID" ); $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; } $open_style = ''; $not_open_style = ''; if ( $open ) { $open_style = ' style="display:none"'; } else { $not_open_style = ' style="display:none"'; } ?> <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> <div<?php echo $open_style; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> <p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p> <p><?php echo $image_edit_button; ?></p> </div> <div<?php echo $not_open_style; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> <?php if ( $open ) { wp_image_editor( $attachment_id ); } ?> </div> <?php elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ) : wp_maybe_generate_attachment_metadata( $post ); echo wp_audio_shortcode( array( 'src' => $att_url ) ); elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ) : wp_maybe_generate_attachment_metadata( $post ); $meta = wp_get_attachment_metadata( $attachment_id ); $w = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0; $h = ! empty( $meta['height'] ) ? $meta['height'] : 0; if ( $h && $w < $meta['width'] ) { $h = round( ( $meta['height'] * $w ) / $meta['width'] ); } $attr = array( 'src' => $att_url ); if ( ! empty( $w ) && ! empty( $h ) ) { $attr['width'] = $w; $attr['height'] = $h; } $thumb_id = get_post_thumbnail_id( $attachment_id );History
Introduced in 3.5.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.9.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.