Make WordPress Core

Ticket #22186: 22186.diff

File 22186.diff, 5.3 KB (added by nacin, 13 years ago)
  • wp-admin/includes/ajax-actions.php

     
    18501850                wp_send_json_error();
    18511851
    18521852        $changes = $_REQUEST['changes'];
    1853         $args    = array();
     1853        $post    = get_post( $id, ARRAY_A );
    18541854
    1855         if ( ! empty( $changes['title'] ) )
    1856                 $args['post_title'] = $changes['title'];
     1855        if ( 'attachment' != $post['post_type'] )
     1856                wp_send_json_error();
    18571857
    1858         if ( ! empty( $changes['caption'] ) )
    1859                 $args['post_excerpt'] = $changes['caption'];
     1858        if ( isset( $changes['title'] ) )
     1859                $post['post_title'] = $changes['title'];
    18601860
    1861         if ( ! empty( $changes['alt'] ) )
    1862                 $args['_wp_attachment_image_alt'] = $changes['alt'];
     1861        if ( isset( $changes['caption'] ) )
     1862                $post['post_excerpt'] = $changes['caption'];
    18631863
    1864         if ( $args )
    1865                 edit_post( array_merge( $args, array( 'post_ID' => $id ) ) );
     1864        $post = apply_filters( 'attachment_fields_to_save', $post, $attachment );
    18661865
     1866        if ( isset( $post['errors'] ) ) {
     1867                $errors = array( $attachment_id => $post['errors'] ); // @todo return me and display me!
     1868                unset( $post['errors'] );
     1869        }
     1870
     1871        if ( isset( $changes['alt'] ) ) {
     1872                $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
     1873                $new_alt = stripslashes( $changes['alt'] );
     1874                if ( $alt != $new_alt ) {
     1875                        $new_alt = wp_strip_all_tags( $new_alt, true );
     1876                        update_post_meta( $id, '_wp_attachment_image_alt', addslashes( $new_alt ) );
     1877                }
     1878        }
     1879
     1880        wp_update_post( $post );
     1881
     1882        foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
     1883                if ( isset( $changes[ $taxonomy ] ) )
     1884                        wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $changes[ $taxonomy ] ) ), $taxonomy, false );
     1885        }
     1886
    18671887        wp_send_json_success();
    18681888}
  • wp-admin/includes/media.php

     
    12691269        return $item;
    12701270}
    12711271
     1272function get_bastardized_media_item( $attachment_id, $args = null ) {
     1273        $post = get_post( $attachment_id );
     1274
     1275        $default_args = array(
     1276                'errors' => null,
     1277        );
     1278
     1279        $args = wp_parse_args( $args, $default_args );
     1280        $args = apply_filters( 'get_media_item_args', $args );
     1281
     1282        $errors = $args['errors'];
     1283
     1284        $form_fields = get_attachment_fields_to_edit( $post, $errors );
     1285
     1286        $media_meta = apply_filters( 'media_meta', '', $post );
     1287
     1288        $defaults = array(
     1289                'input'      => 'text',
     1290                'required'   => false,
     1291                'value'      => '',
     1292                'extra_rows' => array(),
     1293        );
     1294
     1295        $hidden_fields = array();
     1296
     1297        unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'],
     1298                $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'],
     1299                $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] );
     1300
     1301        $item = '';
     1302        foreach ( $form_fields as $name => $field ) {
     1303                if ( $name[0] == '_' )
     1304                        continue;
     1305
     1306                if ( !empty( $field['tr'] ) ) {
     1307                        $item .= $field['tr'];
     1308                        continue;
     1309                }
     1310
     1311                $field = array_merge( $defaults, $field );
     1312
     1313                if ( $field['input'] == 'hidden' ) {
     1314                        $hidden_fields[$name] = $field['value'];
     1315                        continue;
     1316                }
     1317
     1318                $required      = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
     1319                $aria_required = $field['required'] ? " aria-required='true' " : '';
     1320                $class  = $name;
     1321                $class .= $field['required'] ? ' form-required' : '';
     1322
     1323                $item .= "\t\t<tr class='$class'>";
     1324                $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>";
     1325                $item .= "</th>\n\t\t\t<td class='field'>";
     1326
     1327                if ( !empty( $field[ $field['input'] ] ) )
     1328                        $item .= $field[ $field['input'] ];
     1329                elseif ( $field['input'] == 'textarea' ) {
     1330                        if ( 'post_content' == $name && user_can_richedit() ) {
     1331                                // sanitize_post() skips the post_content when user_can_richedit
     1332                                $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
     1333                        }
     1334                        $item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>';
     1335                } else {
     1336                        $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
     1337                }
     1338                if ( !empty( $field['helps'] ) )
     1339                        $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
     1340                $item .= "</td>\n\t\t</tr>\n";
     1341
     1342                $extra_rows = array();
     1343
     1344                if ( !empty( $field['errors'] ) )
     1345                        foreach ( array_unique( (array) $field['errors'] ) as $error )
     1346                                $extra_rows['error'][] = $error;
     1347
     1348                if ( !empty( $field['extra_rows'] ) )
     1349                        foreach ( $field['extra_rows'] as $class => $rows )
     1350                                foreach ( (array) $rows as $html )
     1351                                        $extra_rows[$class][] = $html;
     1352
     1353                foreach ( $extra_rows as $class => $rows )
     1354                        foreach ( $rows as $html )
     1355                                $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
     1356        }
     1357
     1358        if ( !empty( $form_fields['_final'] ) )
     1359                $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
     1360        if ( $item )
     1361                $item = '<table>' . $item . '</table>';
     1362
     1363        return compact( 'item', 'hidden_fields', 'media_meta' );
     1364}
     1365
    12721366/**
    12731367 * {@internal Missing Short Description}}
    12741368 *