Make WordPress Core


Ignore:
Timestamp:
09/21/2012 10:52:54 PM (14 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/class-wp-media-list-table.php

    r21944 r21948  
    133133                $posts_columns['title'] = _x( 'File', 'column name' );
    134134                $posts_columns['author'] = __( 'Author' );
    135                 //$posts_columns['tags'] = _x( 'Tags', 'column name' );
     135
     136                $taxonomies = array();
     137
     138                $taxonomies = get_taxonomies_for_attachments( 'objects' );
     139                $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
     140
     141                $taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' );
     142                $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
     143
     144                foreach ( $taxonomies as $taxonomy ) {
     145                        if ( 'category' == $taxonomy )
     146                                $column_key = 'categories';
     147                        elseif ( 'post_tag' == $taxonomy )
     148                                $column_key = 'tags';
     149                        else
     150                                $column_key = 'taxonomy-' . $taxonomy;
     151
     152                        $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
     153                }
     154
    136155                /* translators: column name */
    137156                if ( !$this->detached ) {
    … …  
    249268?>
    250269                <td <?php echo $attributes ?>><?php the_author() ?></td>
    251 <?php
    252                 break;
    253 
    254         case 'tags':
    255 ?>
    256                 <td <?php echo $attributes ?>><?php
    257                 $tags = get_the_tags();
    258                 if ( !empty( $tags ) ) {
    259                         $out = array();
    260                         foreach ( $tags as $c )
    261                                 $out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'post_tag', 'display' ) ) . "</a>";
    262                         echo join( ', ', $out );
    263                 } else {
    264                         _e( 'No Tags' );
    265                 }
    266 ?>
    267                 </td>
    268270<?php
    269271                break;
    … …  
    340342
    341343        default:
     344                if ( 'categories' == $column_name )
     345                        $taxonomy = 'category';
     346                if ( 'tags' == $column_name )
     347                        $taxonomy = 'post_tag';
     348                elseif ( 0 === strpos( $column_name, 'taxonomy-' ) )
     349                        $taxonomy = substr( $column_name, 9 );
     350                else
     351                        $taxonomy = false;
     352
     353                if ( $taxonomy ) {
     354                        $taxonomy_object = get_taxonomy( $taxonomy );
     355                        echo '<td ' . $attributes . '>';
     356                        if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) {
     357                                $out = array();
     358                                foreach ( $terms as $t ) {
     359                                        $posts_in_term_qv = array();
     360                                        $posts_in_term_qv['taxonomy'] = $taxonomy;
     361                                        $posts_in_term_qv['term'] = $t->slug;
     362
     363                                        $out[] = sprintf( '<a href="%s">%s</a>',
     364                                                esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
     365                                                esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
     366                                        );
     367                                }
     368                                /* translators: used between list items, there is a space after the comma */
     369                                echo join( __( ', ' ), $out );
     370                        } else {
     371                                echo '&#8212;';
     372                        }
     373                        echo '</td>';
     374                        break;
     375                }
    342376?>
    343377                <td <?php echo $attributes ?>>
Note: See TracChangeset for help on using the changeset viewer.