edit_form_image_editor

Displays the image and editor in the post editor.

Description

edit_form_image_editor( (WP_Post) $post ); 

Parameters (1)

0. $post (WP_Post)
A post object.

Usage

  1. if ( !function_exists( 'edit_form_image_editor' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // A post object. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = edit_form_image_editor($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/media.php  
  1. function edit_form_image_editor( $post ) { 
  2. $open = isset( $_GET['image-editor'] ); 
  3. if ( $open ) 
  4. require_once ABSPATH . 'wp-admin/includes/image-edit.php'; 
  5.  
  6. $thumb_url = false; 
  7. if ( $attachment_id = intval( $post->ID ) ) 
  8. $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); 
  9.  
  10. $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); 
  11.  
  12. $att_url = wp_get_attachment_url( $post->ID ); ?> 
  13. <div class="wp_attachment_holder wp-clearfix"> 
  14. <?php 
  15. if ( wp_attachment_is_image( $post->ID ) ) : 
  16. $image_edit_button = ''; 
  17. if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { 
  18. $nonce = wp_create_nonce( "image_editor-$post->ID" ); 
  19. $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>"; 
  20. ?> 
  21.  
  22. <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> 
  23.  
  24. <div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> 
  25. <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> 
  26. <p><?php echo $image_edit_button; ?></p> 
  27. </div> 
  28. <div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> 
  29. <?php if ( $open )wp_image_editor $attachment_id ); ?> 
  30. </div> 
  31. <?php 
  32. elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ): 
  33.  
  34.  
  35. echo wp_audio_shortcode( array( 'src' => $att_url ) ); 
  36.  
  37. elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ): 
  38.  
  39.  
  40. $meta = wp_get_attachment_metadata( $attachment_id ); 
  41. $w = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0; 
  42. $h = ! empty( $meta['height'] ) ? $meta['height'] : 0; 
  43. if ( $h && $w < $meta['width'] ) { 
  44. $h = round( ( $meta['height'] * $w ) / $meta['width'] ); 
  45.  
  46. $attr = array( 'src' => $att_url ); 
  47. if ( ! empty( $w ) && ! empty( $h ) ) { 
  48. $attr['width'] = $w; 
  49. $attr['height'] = $h; 
  50.  
  51. $thumb_id = get_post_thumbnail_id( $attachment_id ); 
  52. if ( ! empty( $thumb_id ) ) { 
  53. $attr['poster'] = wp_get_attachment_url( $thumb_id ); 
  54.  
  55. echo wp_video_shortcode( $attr ); 
  56.  
  57. elseif ( isset( $thumb_url[0] ) ): 
  58.  
  59. ?> 
  60. <div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> 
  61. <p id="thumbnail-head-<?php echo $attachment_id; ?>"> 
  62. <img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /> 
  63. </p> 
  64. </div> 
  65. <?php 
  66.  
  67. else: 
  68.  
  69. /** 
  70. * Fires when an attachment type can't be rendered in the edit form. 
  71. * @since 4.6.0 
  72. * @param WP_Post $post A post object. 
  73. */ 
  74.  
  75. endif; ?> 
  76. </div> 
  77. <div class="wp_attachment_details edit-form-section"> 
  78. <p> 
  79. <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> 
  80. <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> 
  81. </p> 
  82.  
  83.  
  84. <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?> 
  85. <p> 
  86. <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br /> 
  87. <input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" /> 
  88. </p> 
  89. <?php endif; ?> 
  90.  
  91. <?php 
  92. $quicktags_settings = array( 'buttons' => 'strong, em, link, block, del, ins, img, ul, ol, li, code, close' ); 
  93. $editor_args = array( 
  94. 'textarea_name' => 'content',  
  95. 'textarea_rows' => 5,  
  96. 'media_buttons' => false,  
  97. 'tinymce' => false,  
  98. 'quicktags' => $quicktags_settings,  
  99. ); 
  100. ?> 
  101.  
  102. <label for="attachment_content"><strong><?php _e( 'Description' ); ?></strong><?php 
  103. if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { 
  104. echo ': ' . __( 'Displayed on attachment pages.' ); 
  105. } ?></label> 
  106. <?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?> 
  107.  
  108. </div> 
  109. <?php 
  110. $extras = get_compat_media_markup( $post->ID ); 
  111. echo $extras['item']; 
  112. echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n";