WordPress.org

Make WordPress Core

Changeset 21948


Ignore:
Timestamp:
09/21/12 22:52:54 (19 months 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.

Location:
trunk
Files:
15 edited

Legend:

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

    r21944 r21948  
    37603760 
    37613761.upload-php .fixed .column-parent { 
    3762     width: 25%; 
     3762    width: 15%; 
    37633763} 
    37643764 
     
    39393939} 
    39403940 
    3941 .describe .imgedit-wrap table td { 
     3941.describe .imgedit-wrap table td, 
     3942.wp_attachment_holder .imgedit-wrap table td { 
    39423943    vertical-align: top; 
    39433944    padding-top: 0; 
  • trunk/wp-admin/edit-form-advanced.php

    r21944 r21948  
    6464    10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 
    6565); 
     66$messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated' ) ); // Hack, for now. 
    6667 
    6768$messages = apply_filters( 'post_updated_messages', $messages ); 
     
    7879$notice = false; 
    7980$form_extra = ''; 
    80 if ( 'auto-draft' == $post->post_status ) { 
     81if ( 'auto-draft' == get_post_status( $post ) ) { 
    8182    if ( 'edit' == $action ) 
    8283        $post->post_title = ''; 
     
    107108require_once('./includes/meta-boxes.php'); 
    108109 
    109 add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', null, 'side', 'core'); 
     110if ( 'attachment' == $post_type ) { 
     111    wp_enqueue_script( 'image-edit' ); 
     112    wp_enqueue_style( 'imgareaselect' ); 
     113    add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' ); 
     114    add_meta_box( 'attachmentdata', __('Attachment Page Content'), 'attachment_data_meta_box', null, 'normal', 'core' ); 
     115    add_action( 'edit_form_after_title', 'edit_form_image_editor' ); 
     116} else { 
     117    add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core' ); 
     118} 
    110119 
    111120if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) ) 
     
    113122 
    114123// all taxonomies 
    115 foreach ( get_object_taxonomies($post_type) as $tax_name ) { 
     124foreach ( get_object_taxonomies( $post ) as $tax_name ) { 
    116125    $taxonomy = get_taxonomy($tax_name); 
    117126    if ( ! $taxonomy->show_ui ) 
     
    145154    add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', null, 'normal', 'core'); 
    146155 
    147 if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') ) 
     156if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') ) 
    148157    add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core'); 
    149158 
    150 if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) 
     159if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) ) 
    151160    add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core'); 
    152161 
     
    270279<?php 
    271280} 
    272 if ( 'draft' != $post->post_status ) 
     281if ( 'draft' != get_post_status( $post ) ) 
    273282    wp_original_referer_field(true, 'previous'); 
    274283 
     
    297306    $sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr($shortlink) . '" /><a href="#" class="button button-small" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink') . '</a>'; 
    298307 
    299 if ( $post_type_object->public && ! ( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?> 
     308if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?> 
    300309    <div id="edit-slug-box"> 
    301310    <?php 
    302         if ( ! empty($post->ID) && ! empty($sample_permalink_html) && 'auto-draft' != $post->post_status ) 
     311        if ( $sample_permalink_html && 'auto-draft' != get_post_status( $post ) ) 
    303312            echo $sample_permalink_html; 
    304313    ?> 
     
    311320wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); 
    312321?> 
    313 </div> 
    314 <?php } ?> 
    315  
    316 <?php if ( post_type_supports($post_type, 'editor') ) { ?> 
     322</div><!-- /titlediv --> 
     323<?php 
     324} 
     325 
     326do_action( 'edit_form_after_title' ); 
     327 
     328if ( post_type_supports($post_type, 'editor') ) { 
     329?> 
    317330<div id="postdivrich" class="postarea"> 
    318331 
     
    324337    <span class="autosave-message">&nbsp;</span> 
    325338<?php 
    326     if ( 'auto-draft' != $post->post_status ) { 
     339    if ( 'auto-draft' != get_post_status( $post ) ) { 
    327340        echo '<span id="last-edit">'; 
    328341        if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) { 
  • trunk/wp-admin/edit-tags.php

    r21365 r21948  
    2727 
    2828if ( 'post' != $post_type ) { 
    29     $parent_file = "edit.php?post_type=$post_type"; 
     29    $parent_file = ( 'attachment' == $post_type ) ? 'upload.php' : "edit.php?post_type=$post_type"; 
    3030    $submenu_file = "edit-tags.php?taxonomy=$taxonomy&amp;post_type=$post_type"; 
    3131} else if ( 'link_category' == $tax->name ) { 
  • 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 ?>> 
  • trunk/wp-admin/includes/class-wp-terms-list-table.php

    r21914 r21948  
    299299        if ( 'post' != $this->screen->post_type ) 
    300300            $args['post_type'] = $this->screen->post_type; 
     301 
     302        if ( 'attachment' == $this->screen->post_type ) 
     303            return "<a href='" . esc_url ( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>"; 
    301304 
    302305        return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>"; 
  • trunk/wp-admin/includes/media.php

    r21944 r21948  
    858858/** 
    859859 * Filters input from media_upload_form_handler() and assigns a default 
    860  * post_title from the file name if none supplied.  
    861  * 
    862  * Illustrates the use of the attachment_fields_to_save filter  
     860 * post_title from the file name if none supplied. 
     861 * 
     862 * Illustrates the use of the attachment_fields_to_save filter 
    863863 * which can be used to add default values to any field before saving to DB. 
    864864 * 
     
    20962096} 
    20972097 
     2098/** 
     2099 * Displays the image and editor in the post editor 
     2100 * 
     2101 * @since 3.5.0 
     2102 */ 
     2103function edit_form_image_editor() { 
     2104    $post = get_post(); 
     2105 
     2106    $thumb_url = false; 
     2107    if ( $attachment_id = intval( $post->ID ) ) 
     2108        $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 600 ), true ); 
     2109 
     2110    $filename = esc_html( basename( $post->guid ) ); 
     2111    $title = esc_attr( $post->post_title ); 
     2112 
     2113    $post_mime_types = get_post_mime_types(); 
     2114    $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); 
     2115    $type = array_shift( $keys ); 
     2116    $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />"; 
     2117 
     2118    $media_dims = ''; 
     2119    $meta = wp_get_attachment_metadata( $post->ID ); 
     2120    if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) ) 
     2121        $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> "; 
     2122    $media_dims = apply_filters( 'media_meta', $media_dims, $post ); 
     2123 
     2124    $att_url = wp_get_attachment_url( $post->ID ); 
     2125 
     2126    $image_edit_button = ''; 
     2127    if ( gd_edit_image_support( $post->post_mime_type ) ) { 
     2128        $nonce = wp_create_nonce( "image_editor-$post->ID" ); 
     2129        $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <img src='" . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . "' class='imgedit-wait-spin' alt='' />"; 
     2130    } 
     2131 
     2132    ?> 
     2133    <div class="wp_attachment_holder"> 
     2134        <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> 
     2135 
     2136        <div class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>"> 
     2137            <p><img class="thumbnail" src="<?php echo $thumb_url[0]; ?>" style="max-width:100%" width="<?php echo $thumb_url[1]; ?>" alt="" /></p> 
     2138            <p><?php echo $image_edit_button; ?></p> 
     2139        </div> 
     2140        <div style="display:none" class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"></div> 
     2141 
     2142        <div class="wp_attachment_details"> 
     2143            <p> 
     2144                <label for="attachment_url"><strong><?php _e( 'File URL' ); ?></strong></label><br /> 
     2145                <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php echo esc_attr($att_url); ?>" /><br /> 
     2146            </p> 
     2147            <p><strong><?php _e( 'File name:' ); ?></strong> <?php echo $filename; ?><br /> 
     2148            <strong><?php _e( 'File type:' ); ?></strong> <?php echo $post->post_mime_type; ?> 
     2149            <?php 
     2150                if ( $media_dims ) 
     2151                    echo '<br /><strong>' . __( 'Dimensions:' ) . '</strong> ' . $media_dims; 
     2152            ?> 
     2153            </p> 
     2154        </div> 
     2155    </div> 
     2156    <?php 
     2157} 
     2158 
    20982159add_filter( 'async_upload_image', 'get_media_item', 10, 2 ); 
    20992160add_filter( 'async_upload_audio', 'get_media_item', 10, 2 ); 
  • trunk/wp-admin/includes/meta-boxes.php

    r21944 r21948  
    5252<?php endif; // public post type ?> 
    5353<div class="clear"></div> 
    54 </div><?php // /minor-publishing-actions ?> 
     54</div><!-- #minor-publishing-actions --> 
    5555 
    5656<div id="misc-publishing-actions"> 
     
    104104 
    105105<?php } ?> 
    106 </div><?php // /misc-pub-section ?> 
     106</div><!-- .misc-pub-section --> 
    107107 
    108108<div class="misc-pub-section" id="visibility"> 
     
    149149<?php } ?> 
    150150 
    151 </div><?php // /misc-pub-section ?> 
     151</div><!-- .misc-pub-section --> 
    152152 
    153153<?php 
     
    227227</div> 
    228228 
     229<?php 
     230} 
     231 
     232/** 
     233 * Display attachment submit form fields. 
     234 * 
     235 * @since 3.5.0 
     236 * 
     237 * @param object $post 
     238 */ 
     239function attachment_submit_meta_box( $post ) { 
     240    global $action; 
     241 
     242    $post_type = $post->post_type; 
     243    $post_type_object = get_post_type_object($post_type); 
     244    $can_publish = current_user_can($post_type_object->cap->publish_posts); 
     245?> 
     246<div class="submitbox" id="submitpost"> 
     247 
     248<div id="minor-publishing"> 
     249 
     250<?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?> 
     251<div style="display:none;"> 
     252<?php submit_button( __( 'Save' ), 'button', 'save' ); ?> 
     253</div> 
     254 
     255 
     256<div id="misc-publishing-actions"> 
     257    <?php 
     258    // translators: Publish box date format, see http://php.net/date 
     259    $datef = __( 'M j, Y @ G:i' ); 
     260    $stamp = __('Uploaded on: <b>%1$s</b>'); 
     261    $date = date_i18n( $datef, strtotime( $post->post_date ) ); 
     262    ?> 
     263    <div class="misc-pub-section curtime"> 
     264        <span id="timestamp"><?php printf($stamp, $date); ?></span> 
     265    </div><!-- .misc-pub-section --> 
     266 
     267    <?php do_action('attachment_submitbox_misc_actions'); ?> 
     268</div><!-- #misc-publishing-actions --> 
     269<div class="clear"></div> 
     270</div><!-- #minor-publishing --> 
     271 
     272<div id="major-publishing-actions"> 
     273    <div id="delete-action"> 
     274    <?php 
     275    if ( current_user_can( 'delete_post', $post->ID ) ) 
     276        if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { 
     277            echo "<a class='submitdelete deletion' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; 
     278        } else { 
     279            $delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; 
     280            echo  "<a class='submitdelete deletion'$delete_ays href='" . get_delete_post_link( $post->ID, null, true ) . "''>" . __( 'Delete Permanently' ) . "</a>"; 
     281        } 
     282    ?> 
     283    </div> 
     284 
     285    <div id="publishing-action"> 
     286        <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-loading" id="ajax-loading" alt="" /> 
     287        <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Update') ?>" /> 
     288        <input name="save" type="submit" class="button-primary button-large" id="publish" accesskey="p" value="<?php esc_attr_e('Update') ?>" /> 
     289    </div> 
     290    <div class="clear"></div> 
     291</div><!-- #major-publishing-actions --> 
     292 
     293</div> 
     294 
     295<?php 
     296} 
     297 
     298/** 
     299 * Display attachment/media-specific information 
     300 * 
     301 * @since 3.5.0 
     302 * 
     303 * @param object $post 
     304 */ 
     305function attachment_data_meta_box( $post ) { 
     306    $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); 
     307    $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' ); 
     308    $editor_args = array( 
     309        'textarea_name' => 'content', 
     310        'textarea_rows' => 5, 
     311        'media_buttons' => false, 
     312        'tinymce' => false, 
     313        'quicktags' => $quicktags_settings, 
     314    ); 
     315?> 
     316<p> 
     317    <label class="screen-reader-text" for="content"><strong><?php _e( 'Attachment Page Content' ); ?></strong></label> 
     318    <?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?> 
     319</p> 
     320 
     321<p> 
     322    <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> 
     323    <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> 
     324</p> 
     325<p> 
     326    <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br /> 
     327    <input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" /> 
     328</p> 
    229329<?php 
    230330} 
  • trunk/wp-admin/includes/post.php

    r21944 r21948  
    233233                continue; 
    234234            delete_meta( $key ); 
     235        } 
     236    } 
     237 
     238    // Attachment stuff 
     239    if ( 'attachment' == $post_data['post_type'] && isset( $post_data['_wp_attachment_image_alt'] ) ) { 
     240        $image_alt = get_post_meta( $post_ID, '_wp_attachment_image_alt', true ); 
     241        if ( $image_alt != stripslashes( $post_data['_wp_attachment_image_alt'] ) ) { 
     242            $image_alt = wp_strip_all_tags( stripslashes( $post_data['_wp_attachment_image_alt'] ), true ); 
     243            // update_meta expects slashed 
     244            update_post_meta( $post_ID, '_wp_attachment_image_alt', addslashes( $image_alt ) ); 
    235245        } 
    236246    } 
     
    10651075    list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); 
    10661076 
    1067     if ( 'publish' == $post->post_status ) { 
     1077    if ( 'publish' == get_post_status( $post ) ) { 
    10681078        $ptype = get_post_type_object($post->post_type); 
    10691079        $view_post = $ptype->labels->view_item; 
  • trunk/wp-admin/includes/screen.php

    r21687 r21948  
    9797        $hidden = array(); 
    9898        if ( 'post' == $screen->base ) { 
    99             if ( 'post' == $screen->post_type || 'page' == $screen->post_type ) 
     99            if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type ) 
    100100                $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv'); 
    101101            else 
  • trunk/wp-admin/menu.php

    r21877 r21948  
    6565    /* translators: add new file */ 
    6666    $submenu['upload.php'][10] = array( _x('Add New', 'file'), 'upload_files', 'media-new.php'); 
     67    foreach ( get_taxonomies_for_attachments( 'objects' ) as $tax ) { 
     68        if ( ! $tax->show_ui ) 
     69            continue; 
     70 
     71        $submenu['upload.php'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&amp;post_type=attachment' ); 
     72    } 
     73    unset($tax); 
    6774 
    6875$menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'none' ); 
  • trunk/wp-admin/post.php

    r21651 r21948  
    8686     strpos( $sendback, 'post.php' ) !== false || 
    8787     strpos( $sendback, 'post-new.php' ) !== false ) { 
    88     $sendback = admin_url( 'edit.php' ); 
    89     $sendback .= ( ! empty( $post_type ) ) ? '?post_type=' . $post_type : ''; 
     88    if ( 'attachment' == $post_type ) { 
     89        $sendback = admin_url( 'upload.php' ); 
     90    } else { 
     91        $sendback = admin_url( 'edit.php' ); 
     92        $sendback .= ( ! empty( $post_type ) ) ? '?post_type=' . $post_type : ''; 
     93    } 
    9094} else { 
    9195    $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback ); 
     
    149153        $submenu_file = "edit.php"; 
    150154        $post_new_file = "post-new.php"; 
     155    } elseif ( 'attachment' == $post_type ) { 
     156        $parent_file = 'upload.php'; 
     157        $submenu_file = 'upload.php'; 
     158        $post_new_file = 'media-new.php'; 
    151159    } else { 
    152160        if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true ) 
  • trunk/wp-includes/admin-bar.php

    r21818 r21948  
    488488    $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); 
    489489 
    490     if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) { 
     490    if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) 
    491491        $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); 
    492         unset( $cpts['post'] ); 
    493     } 
    494  
    495     if ( current_user_can( 'upload_files' ) ) 
    496         $actions[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' ); 
     492 
     493    if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) 
     494        $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); 
    497495 
    498496    if ( current_user_can( 'manage_links' ) ) 
    499497        $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); 
    500498 
    501     if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) { 
     499    if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) 
    502500        $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); 
    503         unset( $cpts['page'] ); 
    504     } 
     501 
     502    unset( $cpts['post'], $cpts['page'], $cpts['attachment'] ); 
    505503 
    506504    // Add any additional custom post types. 
  • trunk/wp-includes/link-template.php

    r21937 r21948  
    107107        return get_page_link($post->ID, $leavename, $sample); 
    108108    elseif ( $post->post_type == 'attachment' ) 
    109         return get_attachment_link($post->ID); 
     109        return get_attachment_link( $post->ID, $leavename ); 
    110110    elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) ) 
    111111        return get_post_permalink($post->ID, $leavename, $sample); 
     
    293293 * 
    294294 * @param mixed $post Optional. Post ID or object. 
    295  * @return string 
    296  */ 
    297 function get_attachment_link( $post = null ) { 
     295 * @param bool $leavename Optional. Leave name. 
     296 * @return string 
     297 */ 
     298function get_attachment_link( $post = null, $leavename = false ) { 
    298299    global $wp_rewrite; 
    299300 
     
    315316 
    316317        if ( strpos($parentlink, '?') === false ) 
    317             $link = user_trailingslashit( trailingslashit($parentlink) . $name ); 
     318            $link = user_trailingslashit( trailingslashit($parentlink) . '%postname%' ); 
     319 
     320        if ( ! $leavename ) 
     321            $link = str_replace( '%postname%', $name, $link ); 
    318322    } 
    319323 
  • trunk/wp-includes/media.php

    r21909 r21948  
    987987 
    988988/** 
     989 * Return all of the taxonomy names that are registered for attachments. 
     990 * 
     991 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video. 
     992 * 
     993 * @since 3.5.0 
     994 * @see get_attachment_taxonomies() 
     995 * @uses get_taxonomies() 
     996 * 
     997 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default. 
     998 * @return array The names of all taxonomy of $object_type. 
     999 */ 
     1000function get_taxonomies_for_attachments( $output = 'names' ) { 
     1001    $taxonomies = array(); 
     1002    foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) { 
     1003        foreach ( $taxonomy->object_type as $object_type ) { 
     1004            if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) { 
     1005                if ( 'names' == $output ) 
     1006                    $taxonomies[] = $taxonomy->name; 
     1007                else 
     1008                    $taxonomies[ $taxonomy->name ] = $taxonomy; 
     1009                break; 
     1010            } 
     1011        } 
     1012    } 
     1013 
     1014    return $taxonomies; 
     1015} 
     1016 
     1017/** 
    9891018 * Check if the installed version of GD supports particular image type 
    9901019 * 
  • 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.