Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use the regular post type UI for editing single media items (attachme…

…nts).

 * 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.



git-svn-id: http://core.svn.wordpress.org/trunk@21948 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
commit 33af30eb7f58401c211d3a4c59b697b17bb04dac 1 parent ffaa2d0
Andrew Nacin nacin authored
5 wp-admin/css/wp-admin.css
@@ -3759,7 +3759,7 @@ abbr.required {
3759 3759 }
3760 3760
3761 3761 .upload-php .fixed .column-parent {
3762   - width: 25%;
  3762 + width: 15%;
3763 3763 }
3764 3764
3765 3765 .js .html-uploader #plupload-upload-ui {
@@ -3938,7 +3938,8 @@ borger color while dragging a file over the uploader drop area */
3938 3938 margin: 8px 0;
3939 3939 }
3940 3940
3941   -.describe .imgedit-wrap table td {
  3941 +.describe .imgedit-wrap table td,
  3942 +.wp_attachment_holder .imgedit-wrap table td {
3942 3943 vertical-align: top;
3943 3944 padding-top: 0;
3944 3945 }
37 wp-admin/edit-form-advanced.php
@@ -63,6 +63,7 @@
63 63 9 => sprintf( __('Page scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview page</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
64 64 10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
65 65 );
  66 +$messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated' ) ); // Hack, for now.
66 67
67 68 $messages = apply_filters( 'post_updated_messages', $messages );
68 69
@@ -77,7 +78,7 @@
77 78
78 79 $notice = false;
79 80 $form_extra = '';
80   -if ( 'auto-draft' == $post->post_status ) {
  81 +if ( 'auto-draft' == get_post_status( $post ) ) {
81 82 if ( 'edit' == $action )
82 83 $post->post_title = '';
83 84 $autosave = false;
@@ -106,13 +107,21 @@
106 107 // All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
107 108 require_once('./includes/meta-boxes.php');
108 109
109   -add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', null, 'side', 'core');
  110 +if ( '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 +}
110 119
111 120 if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) )
112 121 add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core' );
113 122
114 123 // all taxonomies
115   -foreach ( get_object_taxonomies($post_type) as $tax_name ) {
  124 +foreach ( get_object_taxonomies( $post ) as $tax_name ) {
116 125 $taxonomy = get_taxonomy($tax_name);
117 126 if ( ! $taxonomy->show_ui )
118 127 continue;
@@ -144,10 +153,10 @@
144 153 if ( post_type_supports($post_type, 'comments') )
145 154 add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', null, 'normal', 'core');
146 155
147   -if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') )
  156 +if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') )
148 157 add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core');
149 158
150   -if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) )
  159 +if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )
151 160 add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
152 161
153 162 if ( post_type_supports($post_type, 'author') ) {
@@ -269,7 +278,7 @@
269 278 <input type="hidden" id="active_post_lock" value="<?php echo esc_attr( implode( ':', $active_post_lock ) ); ?>" />
270 279 <?php
271 280 }
272   -if ( 'draft' != $post->post_status )
  281 +if ( 'draft' != get_post_status( $post ) )
273 282 wp_original_referer_field(true, 'previous');
274 283
275 284 echo $form_extra;
@@ -296,10 +305,10 @@
296 305 if ( !empty($shortlink) )
297 306 $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>';
298 307
299   -if ( $post_type_object->public && ! ( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
  308 +if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
300 309 <div id="edit-slug-box">
301 310 <?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 ) )
303 312 echo $sample_permalink_html;
304 313 ?>
305 314 </div>
@@ -310,10 +319,14 @@
310 319 <?php
311 320 wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
312 321 ?>
313   -</div>
314   -<?php } ?>
  322 +</div><!-- /titlediv -->
  323 +<?php
  324 +}
315 325
316   -<?php if ( post_type_supports($post_type, 'editor') ) { ?>
  326 +do_action( 'edit_form_after_title' );
  327 +
  328 +if ( post_type_supports($post_type, 'editor') ) {
  329 +?>
317 330 <div id="postdivrich" class="postarea">
318 331
319 332 <?php wp_editor($post->post_content, 'content', array('dfw' => true, 'tabfocus_elements' => 'sample-permalink,post-preview') ); ?>
@@ -323,7 +336,7 @@
323 336 <td class="autosave-info">
324 337 <span class="autosave-message">&nbsp;</span>
325 338 <?php
326   - if ( 'auto-draft' != $post->post_status ) {
  339 + if ( 'auto-draft' != get_post_status( $post ) ) {
327 340 echo '<span id="last-edit">';
328 341 if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
329 342 $last_user = get_userdata($last_id);
2  wp-admin/edit-tags.php
@@ -26,7 +26,7 @@
26 26 $title = $tax->labels->name;
27 27
28 28 if ( '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";
30 30 $submenu_file = "edit-tags.php?taxonomy=$taxonomy&amp;post_type=$post_type";
31 31 } else if ( 'link_category' == $tax->name ) {
32 32 $parent_file = 'link-manager.php';
70 wp-admin/includes/class-wp-media-list-table.php
@@ -132,7 +132,26 @@ function get_columns() {
132 132 /* translators: column name */
133 133 $posts_columns['title'] = _x( 'File', 'column name' );
134 134 $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 +
136 155 /* translators: column name */
137 156 if ( !$this->detached ) {
138 157 $posts_columns['parent'] = _x( 'Attached to', 'column name' );
@@ -251,23 +270,6 @@ function display_rows() {
251 270 <?php
252 271 break;
253 272
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>
268   -<?php
269   - break;
270   -
271 273 case 'desc':
272 274 ?>
273 275 <td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td>
@@ -339,6 +341,38 @@ function display_rows() {
339 341 break;
340 342
341 343 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 + }
342 376 ?>
343 377 <td <?php echo $attributes ?>>
344 378 <?php do_action( 'manage_media_custom_column', $column_name, $id ); ?>
3  wp-admin/includes/class-wp-terms-list-table.php
@@ -299,6 +299,9 @@ function column_posts( $tag ) {
299 299 if ( 'post' != $this->screen->post_type )
300 300 $args['post_type'] = $this->screen->post_type;
301 301
  302 + if ( 'attachment' == $this->screen->post_type )
  303 + return "<a href='" . esc_url ( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>";
  304 +
302 305 return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
303 306 }
304 307
65 wp-admin/includes/media.php
@@ -857,9 +857,9 @@ function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
857 857
858 858 /**
859 859 * Filters input from media_upload_form_handler() and assigns a default
860   - * post_title from the file name if none supplied.
  860 + * post_title from the file name if none supplied.
861 861 *
862   - * Illustrates the use of the attachment_fields_to_save filter
  862 + * Illustrates the use of the attachment_fields_to_save filter
863 863 * which can be used to add default values to any field before saving to DB.
864 864 *
865 865 * @since 2.5.0
@@ -2095,6 +2095,67 @@ function multisite_over_quota_message() {
2095 2095 echo '<p>' . sprintf( __( 'Sorry, you have used all of your storage quota of %s MB.' ), get_space_allowed() ) . '</p>';
2096 2096 }
2097 2097
  2098 +/**
  2099 + * Displays the image and editor in the post editor
  2100 + *
  2101 + * @since 3.5.0
  2102 + */
  2103 +function 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 +
2098 2159 add_filter( 'async_upload_image', 'get_media_item', 10, 2 );
2099 2160 add_filter( 'async_upload_audio', 'get_media_item', 10, 2 );
2100 2161 add_filter( 'async_upload_video', 'get_media_item', 10, 2 );
106 wp-admin/includes/meta-boxes.php
@@ -51,7 +51,7 @@ function post_submit_meta_box($post) {
51 51 </div>
52 52 <?php endif; // public post type ?>
53 53 <div class="clear"></div>
54   -</div><?php // /minor-publishing-actions ?>
  54 +</div><!-- #minor-publishing-actions -->
55 55
56 56 <div id="misc-publishing-actions">
57 57
@@ -103,7 +103,7 @@ function post_submit_meta_box($post) {
103 103 </div>
104 104
105 105 <?php } ?>
106   -</div><?php // /misc-pub-section ?>
  106 +</div><!-- .misc-pub-section -->
107 107
108 108 <div class="misc-pub-section" id="visibility">
109 109 <?php _e('Visibility:'); ?> <span id="post-visibility-display"><?php
@@ -148,7 +148,7 @@ function post_submit_meta_box($post) {
148 148 </div>
149 149 <?php } ?>
150 150
151   -</div><?php // /misc-pub-section ?>
  151 +</div><!-- .misc-pub-section -->
152 152
153 153 <?php
154 154 // translators: Publish box date format, see http://php.net/date
@@ -230,6 +230,106 @@ function post_submit_meta_box($post) {
230 230 }
231 231
232 232 /**
  233 + * Display attachment submit form fields.
  234 + *
  235 + * @since 3.5.0
  236 + *
  237 + * @param object $post
  238 + */
  239 +function 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 + */
  305 +function 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>
  329 +<?php
  330 +}
  331 +
  332 +/**
233 333 * Display post format form elements.
234 334 *
235 335 * @since 3.1.0
12 wp-admin/includes/post.php
@@ -235,6 +235,16 @@ function edit_post( $post_data = null ) {
235 235 }
236 236 }
237 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 ) );
  245 + }
  246 + }
  247 +
238 248 add_meta( $post_ID );
239 249
240 250 update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
@@ -1064,7 +1074,7 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
1064 1074
1065 1075 list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
1066 1076
1067   - if ( 'publish' == $post->post_status ) {
  1077 + if ( 'publish' == get_post_status( $post ) ) {
1068 1078 $ptype = get_post_type_object($post->post_type);
1069 1079 $view_post = $ptype->labels->view_item;
1070 1080 $title = __('Click to edit this part of the permalink');
2  wp-admin/includes/screen.php
@@ -96,7 +96,7 @@ function get_hidden_meta_boxes( $screen ) {
96 96 if ( $use_defaults ) {
97 97 $hidden = array();
98 98 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 )
100 100 $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv');
101 101 else
102 102 $hidden = array( 'slugdiv' );
7 wp-admin/menu.php
@@ -64,6 +64,13 @@
64 64 $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php');
65 65 /* translators: add new file */
66 66 $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);
67 74
68 75 $menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'none' );
69 76 $submenu['link-manager.php'][5] = array( _x('All Links', 'admin menu'), 'manage_links', 'link-manager.php' );
12 wp-admin/post.php
@@ -85,8 +85,12 @@ function redirect_post($post_id = '') {
85 85 if ( ! $sendback ||
86 86 strpos( $sendback, 'post.php' ) !== false ||
87 87 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 + }
90 94 } else {
91 95 $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
92 96 }
@@ -148,6 +152,10 @@ function redirect_post($post_id = '') {
148 152 $parent_file = "edit.php";
149 153 $submenu_file = "edit.php";
150 154 $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';
151 159 } else {
152 160 if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true )
153 161 $parent_file = $post_type_object->show_in_menu;
14 wp-includes/admin-bar.php
@@ -487,21 +487,19 @@ function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
487 487
488 488 $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
489 489
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 ) )
491 491 $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
492   - unset( $cpts['post'] );
493   - }
494 492
495   - if ( current_user_can( 'upload_files' ) )
496   - $actions[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' );
  493 + if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) )
  494 + $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' );
497 495
498 496 if ( current_user_can( 'manage_links' ) )
499 497 $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
500 498
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 ) )
502 500 $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'] );
505 503
506 504 // Add any additional custom post types.
507 505 foreach ( $cpts as $cpt ) {
10 wp-includes/link-template.php
@@ -106,7 +106,7 @@ function get_permalink( $id = 0, $leavename = false ) {
@@ -292,9 +292,10 @@ function _get_page_link( $post = false, $leavename = false, $sample = false ) {
@@ -314,7 +315,10 @@ function get_attachment_link( $post = null ) {
29 wp-includes/media.php
@@ -986,6 +986,35 @@ function get_attachment_taxonomies($attachment) {
986 986 }
987 987
988 988 /**
  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 + */
  1000 +function 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 +/**
989 1018 * Check if the installed version of GD supports particular image type
990 1019 *
991 1020 * @since 2.9.0
41 wp-includes/post.php
@@ -52,13 +52,16 @@ function create_initial_post_types() {
52 52
53 53 register_post_type( 'attachment', array(
54 54 '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' ),
57 60 ),
58 61 'public' => true,
59   - 'show_ui' => false,
  62 + 'show_ui' => true,
60 63 '_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. */
62 65 'capability_type' => 'post',
63 66 'map_meta_cap' => true,
64 67 'hierarchical' => false,
@@ -66,7 +69,7 @@ function create_initial_post_types() {
66 69 'query_var' => false,
67 70 'show_in_nav_menus' => false,
68 71 'delete_with_user' => true,
69   - 'supports' => array( 'comments', 'author' ),
  72 + 'supports' => array( 'title', 'author', 'comments' ),
70 73 ) );
71 74
72 75 register_post_type( 'revision', array(
@@ -3768,13 +3771,12 @@ function wp_insert_attachment($object, $file = false, $parent = 0) {
3768 3771 if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) )
3769 3772 $post_status = 'inherit';
3770 3773
  3774 + if ( !empty($post_category) )
  3775 + $post_category = array_filter($post_category); // Filter out empty terms
  3776 +
3771 3777 // 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();
3778 3780 }
3779 3781
3780 3782 // Are we updating or creating?
@@ -3859,7 +3861,22 @@ function wp_insert_attachment($object, $file = false, $parent = 0) {
3859 3861 $wpdb->update( $wpdb->posts, compact("post_name"), array( 'ID' => $post_ID ) );
3860 3862 }
3861 3863
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 + }
3863 3880
3864 3881 if ( $file )
3865 3882 update_attached_file( $post_ID, $file );

0 comments on commit 33af30e

Please sign in to comment.
Something went wrong with that request. Please try again.