Make WordPress Core

Ticket #22938: 22938.patch

File 22938.patch, 2.9 KB (added by jessepollak, 10 years ago)
  • src/wp-admin/includes/ajax-actions.php

     
    23002300        wp_update_post( $post );
    23012301
    23022302        foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
    2303                 if ( isset( $attachment_data[ $taxonomy ] ) )
    2304                         wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false );
     2303                if ( isset( $attachment_data[ $taxonomy ] ) ) {
     2304                        if ( !is_array( $attachment_data[ $taxonomy ] ) ) $attachment_data[ $taxonomy ] = array($attachment_data[ $taxonomy ]);
     2305                        wp_set_object_terms( $id, array_map( 'intval', $attachment_data[ $taxonomy ] ), $taxonomy, false );
     2306                }
    23052307        }
    23062308
    23072309        if ( ! $attachment = wp_prepare_attachment_for_js( $id ) )
  • src/wp-admin/includes/media.php

     
    15701570                        if ( empty($t['args']) )
    15711571                                $t['args'] = array();
    15721572
    1573                         $terms = get_object_term_cache($post->ID, $taxonomy);
    1574                         if ( false === $terms )
    1575                                 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
     1573                        $t['taxonomy'] = true;
    15761574
    1577                         $values = array();
     1575                        $inputname = $taxonomy . 'checklist';
     1576                        $t['input'] = $inputname;
    15781577
    1579                         foreach ( $terms as $term )
    1580                                 $values[] = $term->slug;
    1581                         $t['value'] = join(', ', $values);
    1582                         $t['taxonomy'] = true;
     1578                        $thtml = '<div class="categorydiv"><ul>';
     1579                        ob_start();
     1580                                wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'checked_ontop' => false ) );
     1581                        $thtml .= ob_get_contents();
     1582                        ob_end_clean();
    15831583
     1584                        // right now wp_terms_checklist can only return input elements
     1585                        // with post_category[] as the name
     1586                        //
     1587                        // TODO:  rewrite Walker_Category_Checklist to be more modular
     1588                        // so the input names can be changed
     1589                        $thtml = str_replace('post_category[]', 'attachments[' . $post->ID . '][' . $taxonomy . ']', $thtml);
     1590                        $thtml .= '</ul></div>';
     1591
     1592                        $t[$inputname] = $thtml;
     1593
    15841594                        $form_fields[$taxonomy] = $t;
    15851595                }
    15861596        }
  • src/wp-includes/js/media-views.js

     
    69086908                        }
    69096909
    69106910                        _.each( this.$el.serializeArray(), function( pair ) {
    6911                                 data[ pair.name ] = pair.value;
     6911                                if (data[ pair.name ]) {
     6912                                        // this case handles checkbox inputs where multiple can
     6913                                        // be selected (like categories on an attachment)
     6914                                        if (!_.isArray(data[ pair.name ])) data[ pair.name ] = [data[ pair.name ]];
     6915                                        data[ pair.name ].push(pair.value);
     6916                                } else {
     6917                                        data[ pair.name ] = pair.value;
     6918                                }
    69126919                        });
    69136920
    69146921                        this.controller.trigger( 'attachment:compat:waiting', ['waiting'] );