WordPress.org

Make WordPress Core

Changeset 22783


Ignore:
Timestamp:
11/21/2012 06:53:00 PM (8 years ago)
Author:
nacin
Message:

Support attachment_fields_to_save and attachment_fields_to_edit for attachments going through post.php. see #22186. see #21391.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/css/wp-admin-rtl.css

    r22755 r22783  
    921921    padding-left: 0;
    922922    padding-right: 18px;
     923}
     924
     925.compat-attachment-fields th {
     926    padding-right: 0;
     927    padding-left: 10px;
    923928}
    924929
  • trunk/wp-admin/css/wp-admin.css

    r22755 r22783  
    34013401}
    34023402
     3403.compat-attachment-fields th {
     3404    padding-top: 5px;
     3405    padding-right: 10px;
     3406}
     3407
    34033408/*------------------------------------------------------------------------------
    34043409  11.2 - Post Revisions
  • trunk/wp-admin/includes/media.php

    r22765 r22783  
    12771277    $default_args = array(
    12781278        'errors' => null,
     1279        'taxonomies' => false,
    12791280    );
    12801281
     
    12841285    $form_fields = array();
    12851286
    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;
     1287    if ( $args['taxonomies'] ) {
     1288        foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
     1289            $t = (array) get_taxonomy($taxonomy);
     1290            if ( ! $t['public'] || ! $t['show_ui'] )
     1291                continue;
     1292            if ( empty($t['label']) )
     1293                $t['label'] = $taxonomy;
     1294            if ( empty($t['args']) )
     1295                $t['args'] = array();
     1296
     1297            $terms = get_object_term_cache($post->ID, $taxonomy);
     1298            if ( false === $terms )
     1299                $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
     1300
     1301            $values = array();
     1302
     1303            foreach ( $terms as $term )
     1304                $values[] = $term->slug;
     1305            $t['value'] = join(', ', $values);
     1306
     1307            $form_fields[$taxonomy] = $t;
     1308        }
    13061309    }
    13071310
     
    13331336
    13341337        $name = "attachments[$attachment_id][$id]";
     1338        $id_attr = "attachments-$attachment_id-$id";
    13351339
    13361340        if ( !empty( $field['tr'] ) ) {
     
    13421346
    13431347        if ( $field['input'] == 'hidden' ) {
    1344             $hidden_fields[$id] = $field['value'];
     1348            $hidden_fields[$name] = $field['value'];
    13451349            continue;
    13461350        }
     
    13481352        $required      = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
    13491353        $aria_required = $field['required'] ? " aria-required='true' " : '';
    1350         $class  = 'compat-item-' . $name;
     1354        $class  = 'compat-field-' . $id;
    13511355        $class .= $field['required'] ? ' form-required' : '';
    13521356
    13531357        $item .= "\t\t<tr class='$class'>";
    1354         $item .= "\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>";
     1358        $item .= "\t\t\t<th valign='top' scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>";
    13551359        $item .= "</th>\n\t\t\t<td class='field'>";
    13561360
     
    13621366                $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
    13631367            }
    1364             $item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>';
     1368            $item .= "<textarea id='$id_attr' name='$name' $aria_required>" . $field['value'] . '</textarea>';
    13651369        } else {
    1366             $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
     1370            $item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
    13671371        }
    13681372        if ( !empty( $field['helps'] ) )
     
    13891393        $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
    13901394    if ( $item )
    1391         $item = '<table>' . $item . '</table>';
     1395        $item = '<table class="compat-attachment-fields">' . $item . '</table>';
    13921396
    13931397    return array(
     
    22862290    </div>
    22872291    <?php
     2292    $extras = get_compat_media_markup( $post->ID );
     2293    echo $extras['item'];
     2294    foreach ( $extras['hidden'] as $hidden_field => $value ) {
     2295        echo '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n";
     2296    }
    22882297}
    22892298
  • trunk/wp-admin/includes/post.php

    r22769 r22783  
    239239            update_post_meta( $post_ID, '_wp_attachment_image_alt', addslashes( $image_alt ) );
    240240        }
     241
     242        if ( isset( $post_data['attachments'][ $post_ID ] ) )
     243            $post_data = apply_filters( 'attachment_fields_to_save', $post_data, $post_data['attachments'][ $post_ID ] );
    241244    }
    242245
  • trunk/wp-includes/media.php

    r22770 r22783  
    12941294
    12951295    if ( function_exists('get_compat_media_markup') )
    1296         $response['compat'] = get_compat_media_markup( $attachment->ID );
     1296        $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'taxonomies' => true ) );
    12971297
    12981298    return apply_filters( 'wp_prepare_attachment_for_js', $response, $attachment, $meta );
Note: See TracChangeset for help on using the changeset viewer.