Make WordPress Core


Ignore:
Timestamp:
09/21/2012 10:52:54 PM (13 years ago)
Author:
nacin
Message:

Use the regular post type UI for editing single media items (attachments).

  • Attachments now go through post.php, edit_post(), the like, and have show_ui set to true.
  • Taxonomies attached to the media library now appear in the admin menu (if show_ui).
  • Editing, cropping, uploading, etc. is still very rough, but mostly functional.

API-wise:

  • New function: get_taxonomies_for_attachments(). Like get_taxonomies(), for taxonomies specifically registered against attachments.
  • Brings taxonomy support from the posts list table to the media list table. Expect them to converge soon.
  • wp_insert_attachment() now handles taxonomies like wp_insert_post(). Also expect them to converge soon.
  • New edit_form_after_title hook.

props helenyhou, ocean90. see #21391.

File:
1 edited

Legend:

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

    r21944 r21948  
    858858/**
    859859 * Filters input from media_upload_form_handler() and assigns a default
    860  * post_title from the file name if none supplied. 
    861  *
    862  * Illustrates the use of the attachment_fields_to_save filter 
     860 * post_title from the file name if none supplied.
     861 *
     862 * Illustrates the use of the attachment_fields_to_save filter
    863863 * which can be used to add default values to any field before saving to DB.
    864864 *
     
    20962096}
    20972097
     2098/**
     2099 * Displays the image and editor in the post editor
     2100 *
     2101 * @since 3.5.0
     2102 */
     2103function edit_form_image_editor() {
     2104    $post = get_post();
     2105
     2106    $thumb_url = false;
     2107    if ( $attachment_id = intval( $post->ID ) )
     2108        $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 600 ), true );
     2109
     2110    $filename = esc_html( basename( $post->guid ) );
     2111    $title = esc_attr( $post->post_title );
     2112
     2113    $post_mime_types = get_post_mime_types();
     2114    $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
     2115    $type = array_shift( $keys );
     2116    $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
     2117
     2118    $media_dims = '';
     2119    $meta = wp_get_attachment_metadata( $post->ID );
     2120    if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
     2121        $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
     2122    $media_dims = apply_filters( 'media_meta', $media_dims, $post );
     2123
     2124    $att_url = wp_get_attachment_url( $post->ID );
     2125
     2126    $image_edit_button = '';
     2127    if ( gd_edit_image_support( $post->post_mime_type ) ) {
     2128        $nonce = wp_create_nonce( "image_editor-$post->ID" );
     2129        $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' ) . "' /> <img src='" . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . "' class='imgedit-wait-spin' alt='' />";
     2130    }
     2131
     2132    ?>
     2133    <div class="wp_attachment_holder">
     2134        <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>
     2135
     2136        <div class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>">
     2137            <p><img class="thumbnail" src="<?php echo $thumb_url[0]; ?>" style="max-width:100%" width="<?php echo $thumb_url[1]; ?>" alt="" /></p>
     2138            <p><?php echo $image_edit_button; ?></p>
     2139        </div>
     2140        <div style="display:none" class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"></div>
     2141
     2142        <div class="wp_attachment_details">
     2143            <p>
     2144                <label for="attachment_url"><strong><?php _e( 'File URL' ); ?></strong></label><br />
     2145                <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php echo esc_attr($att_url); ?>" /><br />
     2146            </p>
     2147            <p><strong><?php _e( 'File name:' ); ?></strong> <?php echo $filename; ?><br />
     2148            <strong><?php _e( 'File type:' ); ?></strong> <?php echo $post->post_mime_type; ?>
     2149            <?php
     2150                if ( $media_dims )
     2151                    echo '<br /><strong>' . __( 'Dimensions:' ) . '</strong> ' . $media_dims;
     2152            ?>
     2153            </p>
     2154        </div>
     2155    </div>
     2156    <?php
     2157}
     2158
    20982159add_filter( 'async_upload_image', 'get_media_item', 10, 2 );
    20992160add_filter( 'async_upload_audio', 'get_media_item', 10, 2 );
Note: See TracChangeset for help on using the changeset viewer.