WordPress.org

Make WordPress Core

Changeset 22670


Ignore:
Timestamp:
11/19/2012 07:20:47 AM (9 years ago)
Author:
nacin
Message:

Avoid doing all of the extra work in get_attachment_fields_to_edit() for fields we will just discard. We just need the filter, and the taxonomies. see #22186.

File:
1 edited

Legend:

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

    r22628 r22670  
    12821282    $args = apply_filters( 'get_media_item_args', $args );
    12831283
    1284     $errors = $args['errors'];
    1285 
    1286     $form_fields = get_attachment_fields_to_edit( $post, $errors );
     1284    $form_fields = array();
     1285
     1286    foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
     1287        $t = (array) get_taxonomy($taxonomy);
     1288        if ( ! $t['public'] || ! $t['show_ui'] )
     1289            continue;
     1290        if ( empty($t['label']) )
     1291            $t['label'] = $taxonomy;
     1292        if ( empty($t['args']) )
     1293            $t['args'] = array();
     1294
     1295        $terms = get_object_term_cache($post->ID, $taxonomy);
     1296        if ( false === $terms )
     1297            $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
     1298
     1299        $values = array();
     1300
     1301        foreach ( $terms as $term )
     1302            $values[] = $term->slug;
     1303        $t['value'] = join(', ', $values);
     1304
     1305        $form_fields[$taxonomy] = $t;
     1306    }
     1307
     1308    // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
     1309    // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
     1310    $form_fields = array_merge_recursive($form_fields, (array) $args['errors'] );
     1311
     1312    $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
     1313
     1314    unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'],
     1315        $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'],
     1316        $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] );
    12871317
    12881318    $media_meta = apply_filters( 'media_meta', '', $post );
     
    12961326
    12971327    $hidden_fields = array();
    1298 
    1299     unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'],
    1300         $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'],
    1301         $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] );
    13021328
    13031329    $item = '';
Note: See TracChangeset for help on using the changeset viewer.