get_media_item() – Retrieve HTML form for modifying the image attachment.

You appear to be a bot. Output may be restricted

Description

Retrieves HTML form for modifying the image attachment.

Usage

$string = get_media_item( $attachment_id, $args );

Parameters

$attachment_id
( int ) required – Attachment ID for modification.
$args
( string|array ) optional – Optional. Override defaults.

Returns

string HTML form for attachment.

Source

File name: wordpress/wp-admin/includes/media.php
Lines:

1 to 100 of 284
function get_media_item( $attachment_id, $args = null ) {
  global $redir_tab;

  $thumb_url     = false;
  $attachment_id = (int) $attachment_id;

  if ( $attachment_id ) {
    $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true );

    if ( $thumb_url ) {
      $thumb_url = $thumb_url[0];
    }
  }

  $post            = get_post( $attachment_id );
  $current_post_id = ! empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0;

  $default_args = array(
    'errors'     => null,
    'send'       => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true,
    'delete'     => true,
    'toggle'     => true,
    'show_title' => true,
  );

  $parsed_args = wp_parse_args( $args, $default_args );

  
/**
 * Filters the arguments used to retrieve an image for the edit image form.
 *
 * @since 3.1.0
 *
 * @see get_media_item
 *
 * @param array $parsed_args An array of arguments.
 */
  $parsed_args = apply_filters( 'get_media_item_args', $parsed_args );

  $toggle_on  = __( 'Show' );
  $toggle_off = __( 'Hide' );

  $file     = get_attached_file( $post->ID );
  $filename = esc_html( wp_basename( $file ) );
  $title    = esc_attr( $post->post_title );

  $post_mime_types = get_post_mime_types();
  $keys            = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
  $type            = reset( $keys );
  $type_html       = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";

  $form_fields = get_attachment_fields_to_edit( $post, $parsed_args['errors'] );

  if ( $parsed_args['toggle'] ) {
    $class        = empty( $parsed_args['errors'] ) ? 'startclosed' : 'startopen';
    $toggle_links = "
		<a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
		<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
  } else {
    $class        = '';
    $toggle_links = '';
  }

  $display_title = ( ! empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case.
  $display_title = $parsed_args['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '&hellip;' ) . '</span></div>' : '';

  $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' === $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' === $redir_tab ) );
  $order   = '';

  foreach ( $form_fields as $key => $val ) {
    if ( 'menu_order' === $key ) {
      if ( $gallery ) {
        $order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' /></div>";
      } else {
        $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
      }

      unset( $form_fields['menu_order'] );
      break;
    }
  }

  $media_dims = '';
  $meta       = wp_get_attachment_metadata( $post->ID );

  if ( isset( $meta['width'], $meta['height'] ) ) {
    $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> ";
  }

  
/**
 * Filters the media metadata.
 *
 * @since 2.5.0
 *
 * @param string  $media_dims The HTML markup containing the media dimensions.
 * @param WP_Post $post       The WP_Post attachment object.
 */
  $media_dims = apply_filters( 'media_meta', $media_dims, $post );

  $image_edit_button = '';

 

 View on GitHub View on Trac