Make WordPress Core


Ignore:
Timestamp:
11/05/2012 02:04:22 PM (11 years ago)
Author:
ryan
Message:

Attachment editor improvements. Put the non-editable metadata into the submit/publish box.

Props helenyhou
see #21391

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r22105 r22364  
    21232123    $filename = esc_html( basename( $post->guid ) );
    21242124    $title = esc_attr( $post->post_title );
     2125    $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
    21252126
    21262127    $post_mime_types = get_post_mime_types();
     
    21522153        </div>
    21532154        <div style="display:none" class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"></div>
    2154 
    2155         <div class="wp_attachment_details">
    2156             <p>
    2157                 <label for="attachment_url"><strong><?php _e( 'File URL' ); ?></strong></label><br />
    2158                 <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php echo esc_attr($att_url); ?>" /><br />
    2159             </p>
    2160             <p><strong><?php _e( 'File name:' ); ?></strong> <?php echo $filename; ?><br />
    2161             <strong><?php _e( 'File type:' ); ?></strong> <?php echo $post->post_mime_type; ?>
    2162             <?php
    2163                 if ( $media_dims )
    2164                     echo '<br /><strong>' . __( 'Dimensions:' ) . '</strong> ' . $media_dims;
    2165             ?>
    2166             </p>
    2167         </div>
     2155    </div>
     2156
     2157    <div class="wp_attachment_details">
     2158        <p>
     2159            <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
     2160            <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
     2161        </p>
     2162        <p>
     2163            <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
     2164            <input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" />
     2165        </p>
    21682166    </div>
    21692167    <?php
     2168    // need a filter on this content
     2169}
     2170
     2171/**
     2172 * Displays non-editable attachment metadata in the publish metabox
     2173 *
     2174 * @since 3.5.0
     2175 */
     2176function attachment_submitbox_metadata() {
     2177    $post = get_post();
     2178
     2179    $filename = esc_html( basename( $post->guid ) );
     2180
     2181    $media_dims = '';
     2182    $meta = wp_get_attachment_metadata( $post->ID );
     2183    if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
     2184        $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
     2185    $media_dims = apply_filters( 'media_meta', $media_dims, $post );
     2186
     2187    $att_url = wp_get_attachment_url( $post->ID );
     2188?>
     2189    <div class="misc-pub-section">
     2190            <label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
     2191            <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php echo esc_attr($att_url); ?>" />
     2192    </div>
     2193    <div class="misc-pub-section">
     2194        <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong>
     2195    </div>
     2196    <div class="misc-pub-section">
     2197        <?php _e( 'File type:' ); ?> <strong><?php echo $post->post_mime_type; ?></strong>
     2198    </div>
     2199
     2200<?php if ( $media_dims ) : ?>
     2201    <div class="misc-pub-section">
     2202        <?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong>
     2203    </div>
     2204<?php
     2205    endif;
    21702206}
    21712207
     
    21822218add_filter( 'media_upload_gallery', 'media_upload_gallery' );
    21832219add_filter( 'media_upload_library', 'media_upload_library' );
     2220
     2221add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' );
Note: See TracChangeset for help on using the changeset viewer.