WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/06/2012 12:41:06 AM (9 years ago)
Author:
nacin
Message:

Restore the Description field to the media UI in 3.5.

We tried in vain -- a noble but ultimately failed effort -- to reduce the number of fields for attachments from four (title, caption, alt, description) to one (caption for images, title otherwise). Alternative text needed to stay for accessibility reasons, of course.

Eventually title returned due to heavy plugin reliance. Description is too used by too many plugins (often times incorrectly -- the caption is more likely the proper field), hence its less-than-triumphant return today.

Version 3.5 has tried to streamline media in a number of ways. Removing fields may have been too much at once, as it forced not only a user interface change, but a paradigm change as well.

Finally, on upload we populate the description field with IPTC/EXIF captions, rather than the caption field. See #22768, this should be fixed. For now, Description stays.

This commit also restores 'Title' attribute editing to the main tab of the Edit Image dialog. The "Title" field no longer populates title attributes for <img> tags by design (for accessibility and other purposes, see #18984). So, here is a more obvious 'workaround' for the tooltip community.

Finally, this:

  • Cleans up the post.php attachment editor, including by showing a prettier form of the mime type.
  • Enables plugins to specifically hide attachment_fields_to_edit from either post.php (where you can create meta boxes) or the modal (which you may not want to clutter), for compatibility reasons.
  • Hides the 'Describe this file...' placeholder when a field is read-only in the modal.

props nacin, helenyhou.
fixes #22759.

File:
1 edited

Legend:

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

    r23072 r23083  
    12871287    $default_args = array(
    12881288        'errors' => null,
    1289         'taxonomies' => false,
    1290         'description' => false,
     1289        'in_modal' => false,
    12911290    );
    12921291
     
    12981297    $form_fields = array();
    12991298
    1300     if ( $args['taxonomies'] ) {
     1299    if ( $args['in_modal'] ) {
    13011300        foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
    13021301            $t = (array) get_taxonomy($taxonomy);
     
    13301329
    13311330    unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'],
    1332         $form_fields['post_title'], $form_fields['post_excerpt'],
     1331        $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'],
    13331332        $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] );
    13341333
    1335     if ( ! $args['description'] )
    1336         unset( $form_fields['post_content'] );
    1337 
    13381334    $media_meta = apply_filters( 'media_meta', '', $post );
    13391335
    13401336    $defaults = array(
    1341         'input'      => 'text',
    1342         'required'   => false,
    1343         'value'      => '',
    1344         'extra_rows' => array(),
     1337        'input'         => 'text',
     1338        'required'      => false,
     1339        'value'         => '',
     1340        'extra_rows'    => array(),
     1341        'show_in_edit'  => true,
     1342        'show_in_modal' => true,
    13451343    );
    13461344
     
    13611359
    13621360        $field = array_merge( $defaults, $field );
     1361
     1362        if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) )
     1363            continue;
    13631364
    13641365        if ( $field['input'] == 'hidden' ) {
     
    22832284    $att_url = wp_get_attachment_url( $post->ID );
    22842285
    2285     $image_edit_button = '';
    2286     if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
    2287         $nonce = wp_create_nonce( "image_editor-$post->ID" );
    2288         $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>";
    2289     }
    2290 
     2286    if ( wp_attachment_is_image( $post->ID ) ) :
     2287        $image_edit_button = '';
     2288        if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
     2289            $nonce = wp_create_nonce( "image_editor-$post->ID" );
     2290            $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>";
     2291        }
    22912292    ?>
    22922293    <div class="wp_attachment_holder">
     
    22992300        <div style="display:none" class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"></div>
    23002301    </div>
     2302    <?php endif; ?>
    23012303
    23022304    <div class="wp_attachment_details">
     
    23122314        </p>
    23132315    <?php endif; ?>
     2316
     2317    <?php
     2318        $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' );
     2319        $editor_args = array(
     2320            'textarea_name' => 'content',
     2321            'textarea_rows' => 5,
     2322            'media_buttons' => false,
     2323            'tinymce' => false,
     2324            'quicktags' => $quicktags_settings,
     2325        );
     2326    ?>
     2327
     2328    <label for="content"><strong><?php _e( 'Description' ); ?></strong></label>
     2329    <?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
    23142330
    23152331    </div>
     
    23492365    </div>
    23502366    <div class="misc-pub-section">
    2351         <?php _e( 'File type:' ); ?> <strong><?php echo $post->post_mime_type; ?></strong>
     2367        <?php _e( 'File type:' ); ?> <strong><?php
     2368            if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) )
     2369                echo esc_html( strtoupper( $matches[1] ) );
     2370            else
     2371                echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) );
     2372        ?></strong>
    23522373    </div>
    23532374
Note: See TracChangeset for help on using the changeset viewer.