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-includes/post.php

    r21943 r21948  
    5353        register_post_type( 'attachment', array(
    5454                'labels' => array(
    55                         'name' => __( 'Media' ),
    56                         'edit_item' => __( 'Edit Media' ),
     55                        'name' => _x('Media', 'post type general name'),
     56                        'name_admin_bar' => _x( 'Media', 'add new from admin bar' ),
     57                        'add_new' => _x( 'Add New', 'add new media' ),
     58                        'edit_item' => __( 'Edit Media' ),
     59                        'view_item' => __( 'View Attachment Page' ),
    5760                ),
    5861                'public' => true,
    59                 'show_ui' => false,
     62                'show_ui' => true,
    6063                '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
    61                 '_edit_link' => 'media.php?attachment_id=%d', /* internal use only. don't use this when registering your own post type. */
     64                '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
    6265                'capability_type' => 'post',
    6366                'map_meta_cap' => true,
    … …  
    6770                'show_in_nav_menus' => false,
    6871                'delete_with_user' => true,
    69                 'supports' => array( 'comments', 'author' ),
     72                'supports' => array( 'title', 'author', 'comments' ),
    7073        ) );
    7174
    … …  
    37693772                $post_status = 'inherit';
    37703773
     3774        if ( !empty($post_category) )
     3775                $post_category = array_filter($post_category); // Filter out empty terms
     3776
    37713777        // Make sure we set a valid category.
    3772         if ( !isset($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
    3773                 // 'post' requires at least one category.
    3774                 if ( 'post' == $post_type )
    3775                         $post_category = array( get_option('default_category') );
    3776                 else
    3777                         $post_category = array();
     3778        if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
     3779                $post_category = array();
    37783780        }
    37793781
    … …  
    38603862        }
    38613863
    3862         wp_set_post_categories($post_ID, $post_category);
     3864        if ( is_object_in_taxonomy($post_type, 'category') )
     3865                wp_set_post_categories( $post_ID, $post_category );
     3866
     3867        if ( isset( $tags_input ) && is_object_in_taxonomy($post_type, 'post_tag') )
     3868                wp_set_post_tags( $post_ID, $tags_input );
     3869
     3870        // support for all custom taxonomies
     3871        if ( !empty($tax_input) ) {
     3872                foreach ( $tax_input as $taxonomy => $tags ) {
     3873                        $taxonomy_obj = get_taxonomy($taxonomy);
     3874                        if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
     3875                                $tags = array_filter($tags);
     3876                        if ( current_user_can($taxonomy_obj->cap->assign_terms) )
     3877                                wp_set_post_terms( $post_ID, $tags, $taxonomy );
     3878                }
     3879        }
    38633880
    38643881        if ( $file )
Note: See TracChangeset for help on using the changeset viewer.