attachment_submitbox_metadata() – Displays non-editable attachment metadata in the publish meta box.

You appear to be a bot. Output may be restricted

Description

Displays non-editable attachment metadata in the publish meta box.

Usage

attachment_submitbox_metadata();

Parameters

Returns

void

Source

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


Lines:

1 to 100 of 209
function attachment_submitbox_metadata() {
  $post          = get_post();
  $attachment_id = $post->ID;

  $file     = get_attached_file( $attachment_id );
  $filename = esc_html( wp_basename( $file ) );

  $media_dims = '';
  $meta       = wp_get_attachment_metadata( $attachment_id );

  if ( isset( $meta['width'], $meta['height'] ) ) {
    $media_dims .= "<span id='media-dims-$attachment_id'>{$meta['width']} × {$meta['height']}</span> ";
  }
  
/** This filter is documented in wp-admin/includes/media.php */
  $media_dims = apply_filters( 'media_meta', $media_dims, $post );

  $att_url = wp_get_attachment_url( $attachment_id );

  $author = new WP_User( $post->post_author );

  $uploaded_by_name = __( '(no author)' );
  $uploaded_by_link = '';

  if ( $author->exists() ) {
    $uploaded_by_name = $author->display_name ? $author->display_name : $author->nickname;
    $uploaded_by_link = get_edit_user_link( $author->ID );
  }
  ?>
	<div class="misc-pub-section misc-pub-uploadedby">
		<?php if ( $uploaded_by_link ) { ?>
			<?php _e( 'Uploaded by:' ); ?> <a href="<?php echo $uploaded_by_link; ?>"><strong><?php echo $uploaded_by_name; ?></strong></a>
		<?php } else { ?>
			<?php _e( 'Uploaded by:' ); ?> <strong><?php echo $uploaded_by_name; ?></strong>
		<?php } ?>
	</div>

	<?php
  if ( $post->post_parent ) {
    $post_parent = get_post( $post->post_parent );
    if ( $post_parent ) {
      $uploaded_to_title = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );
      $uploaded_to_link  = get_edit_post_link( $post->post_parent, 'raw' );
      ?>
			<div class="misc-pub-section misc-pub-uploadedto">
				<?php if ( $uploaded_to_link ) { ?>
					<?php _e( 'Uploaded to:' ); ?> <a href="<?php echo $uploaded_to_link; ?>"><strong><?php echo $uploaded_to_title; ?></strong></a>
				<?php } else { ?>
					<?php _e( 'Uploaded to:' ); ?> <strong><?php echo $uploaded_to_title; ?></strong>
				<?php } ?>
			</div>
			<?php
    }
  }
  ?>

	<div class="misc-pub-section misc-pub-attachment">
		<label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
		<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" />
		<span class="copy-to-clipboard-container">
			<button type="button" class="button copy-attachment-url edit-media" data-clipboard-target="#attachment_url"><?php _e( 'Copy URL to clipboard' ); ?></button>
			<span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span>
		</span>
	</div>
	<div class="misc-pub-section misc-pub-filename">
		<?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong>
	</div>
	<div class="misc-pub-section misc-pub-filetype">
		<?php _e( 'File type:' ); ?>
		<strong>
		<?php

    if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) {
      echo esc_html( strtoupper( $matches[1] ) );
      list( $mime_type ) = explode( '/', $post->post_mime_type );
      if ( 'image' !== $mime_type && ! empty( $meta['mime_type'] ) ) {
        if ( "$mime_type/" . strtolower( $matches[1] ) !== $meta['mime_type'] ) {
          echo ' (' . $meta['mime_type'] . ')';
        }
      }
    } else {
      echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) );
    }

    ?>
		</strong>
	</div>

	<?php

  $file_size = false;

  if ( isset( $meta['filesize'] ) ) {
    $file_size = $meta['filesize'];
  } elseif ( file_exists( $file ) ) {
    $file_size = wp_filesize( $file );
  }

  if ( ! empty( $file_size ) ) {
    ?>
		<div class="misc-pub-section misc-pub-filesize">

 View on GitHub View on Trac