Permalink
Browse files

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...
1 parent ffaa2d0 commit 33af30eb7f58401c211d3a4c59b697b17bb04dac @nacin nacin committed Sep 21, 2012
@@ -3759,7 +3759,7 @@ abbr.required {
}
.upload-php .fixed .column-parent {
- width: 25%;
+ width: 15%;
}
.js .html-uploader #plupload-upload-ui {
@@ -3938,7 +3938,8 @@ borger color while dragging a file over the uploader drop area */
margin: 8px 0;
}
-.describe .imgedit-wrap table td {
+.describe .imgedit-wrap table td,
+.wp_attachment_holder .imgedit-wrap table td {
vertical-align: top;
padding-top: 0;
}
@@ -63,6 +63,7 @@
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) ) ),
10 => sprintf( __('Page draft updated. <a target="_blank" href="%s">Preview page</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
+$messages['attachment'] = array_fill( 1, 10, __( 'Media attachment updated' ) ); // Hack, for now.
$messages = apply_filters( 'post_updated_messages', $messages );
@@ -77,7 +78,7 @@
$notice = false;
$form_extra = '';
-if ( 'auto-draft' == $post->post_status ) {
+if ( 'auto-draft' == get_post_status( $post ) ) {
if ( 'edit' == $action )
$post->post_title = '';
$autosave = false;
@@ -106,13 +107,21 @@
// All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
require_once('./includes/meta-boxes.php');
-add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', null, 'side', 'core');
+if ( 'attachment' == $post_type ) {
+ wp_enqueue_script( 'image-edit' );
+ wp_enqueue_style( 'imgareaselect' );
+ add_meta_box( 'submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core' );
+ add_meta_box( 'attachmentdata', __('Attachment Page Content'), 'attachment_data_meta_box', null, 'normal', 'core' );
+ add_action( 'edit_form_after_title', 'edit_form_image_editor' );
+} else {
+ add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core' );
+}
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) )
add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core' );
// all taxonomies
-foreach ( get_object_taxonomies($post_type) as $tax_name ) {
+foreach ( get_object_taxonomies( $post ) as $tax_name ) {
$taxonomy = get_taxonomy($tax_name);
if ( ! $taxonomy->show_ui )
continue;
@@ -144,10 +153,10 @@
if ( post_type_supports($post_type, 'comments') )
add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', null, 'normal', 'core');
-if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') )
+if ( ( 'publish' == get_post_status( $post ) || 'private' == get_post_status( $post ) ) && post_type_supports($post_type, 'comments') )
add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core');
-if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) )
+if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) )
add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
if ( post_type_supports($post_type, 'author') ) {
@@ -269,7 +278,7 @@
<input type="hidden" id="active_post_lock" value="<?php echo esc_attr( implode( ':', $active_post_lock ) ); ?>" />
<?php
}
-if ( 'draft' != $post->post_status )
+if ( 'draft' != get_post_status( $post ) )
wp_original_referer_field(true, 'previous');
echo $form_extra;
@@ -296,10 +305,10 @@
if ( !empty($shortlink) )
$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>';
-if ( $post_type_object->public && ! ( 'pending' == $post->post_status && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
+if ( $post_type_object->public && ! ( 'pending' == get_post_status( $post ) && !current_user_can( $post_type_object->cap->publish_posts ) ) ) { ?>
<div id="edit-slug-box">
<?php
- if ( ! empty($post->ID) && ! empty($sample_permalink_html) && 'auto-draft' != $post->post_status )
+ if ( $sample_permalink_html && 'auto-draft' != get_post_status( $post ) )
echo $sample_permalink_html;
?>
</div>
@@ -310,10 +319,14 @@
<?php
wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
?>
-</div>
-<?php } ?>
+</div><!-- /titlediv -->
+<?php
+}
-<?php if ( post_type_supports($post_type, 'editor') ) { ?>
+do_action( 'edit_form_after_title' );
+
+if ( post_type_supports($post_type, 'editor') ) {
+?>
<div id="postdivrich" class="postarea">
<?php wp_editor($post->post_content, 'content', array('dfw' => true, 'tabfocus_elements' => 'sample-permalink,post-preview') ); ?>
@@ -323,7 +336,7 @@
<td class="autosave-info">
<span class="autosave-message">&nbsp;</span>
<?php
- if ( 'auto-draft' != $post->post_status ) {
+ if ( 'auto-draft' != get_post_status( $post ) ) {
echo '<span id="last-edit">';
if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
$last_user = get_userdata($last_id);
@@ -26,7 +26,7 @@
$title = $tax->labels->name;
if ( 'post' != $post_type ) {
- $parent_file = "edit.php?post_type=$post_type";
+ $parent_file = ( 'attachment' == $post_type ) ? 'upload.php' : "edit.php?post_type=$post_type";
$submenu_file = "edit-tags.php?taxonomy=$taxonomy&amp;post_type=$post_type";
} else if ( 'link_category' == $tax->name ) {
$parent_file = 'link-manager.php';
@@ -132,7 +132,26 @@ function get_columns() {
/* translators: column name */
$posts_columns['title'] = _x( 'File', 'column name' );
$posts_columns['author'] = __( 'Author' );
- //$posts_columns['tags'] = _x( 'Tags', 'column name' );
+
+ $taxonomies = array();
+
+ $taxonomies = get_taxonomies_for_attachments( 'objects' );
+ $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
+
+ $taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' );
+ $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
+
+ foreach ( $taxonomies as $taxonomy ) {
+ if ( 'category' == $taxonomy )
+ $column_key = 'categories';
+ elseif ( 'post_tag' == $taxonomy )
+ $column_key = 'tags';
+ else
+ $column_key = 'taxonomy-' . $taxonomy;
+
+ $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
+ }
+
/* translators: column name */
if ( !$this->detached ) {
$posts_columns['parent'] = _x( 'Attached to', 'column name' );
@@ -251,23 +270,6 @@ function display_rows() {
<?php
break;
- case 'tags':
-?>
- <td <?php echo $attributes ?>><?php
- $tags = get_the_tags();
- if ( !empty( $tags ) ) {
- $out = array();
- foreach ( $tags as $c )
- $out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'post_tag', 'display' ) ) . "</a>";
- echo join( ', ', $out );
- } else {
- _e( 'No Tags' );
- }
-?>
- </td>
-<?php
- break;
-
case 'desc':
?>
<td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td>
@@ -339,6 +341,38 @@ function display_rows() {
break;
default:
+ if ( 'categories' == $column_name )
+ $taxonomy = 'category';
+ if ( 'tags' == $column_name )
+ $taxonomy = 'post_tag';
+ elseif ( 0 === strpos( $column_name, 'taxonomy-' ) )
+ $taxonomy = substr( $column_name, 9 );
+ else
+ $taxonomy = false;
+
+ if ( $taxonomy ) {
+ $taxonomy_object = get_taxonomy( $taxonomy );
+ echo '<td ' . $attributes . '>';
+ if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) {
+ $out = array();
+ foreach ( $terms as $t ) {
+ $posts_in_term_qv = array();
+ $posts_in_term_qv['taxonomy'] = $taxonomy;
+ $posts_in_term_qv['term'] = $t->slug;
+
+ $out[] = sprintf( '<a href="%s">%s</a>',
+ esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
+ esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
+ );
+ }
+ /* translators: used between list items, there is a space after the comma */
+ echo join( __( ', ' ), $out );
+ } else {
+ echo '&#8212;';
+ }
+ echo '</td>';
+ break;
+ }
?>
<td <?php echo $attributes ?>>
<?php do_action( 'manage_media_custom_column', $column_name, $id ); ?>
@@ -299,6 +299,9 @@ function column_posts( $tag ) {
if ( 'post' != $this->screen->post_type )
$args['post_type'] = $this->screen->post_type;
+ if ( 'attachment' == $this->screen->post_type )
+ return "<a href='" . esc_url ( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>";
+
return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
}
@@ -857,9 +857,9 @@ function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
/**
* Filters input from media_upload_form_handler() and assigns a default
- * post_title from the file name if none supplied.
+ * post_title from the file name if none supplied.
*
- * Illustrates the use of the attachment_fields_to_save filter
+ * Illustrates the use of the attachment_fields_to_save filter
* which can be used to add default values to any field before saving to DB.
*
* @since 2.5.0
@@ -2095,6 +2095,67 @@ function multisite_over_quota_message() {
echo '<p>' . sprintf( __( 'Sorry, you have used all of your storage quota of %s MB.' ), get_space_allowed() ) . '</p>';
}
+/**
+ * Displays the image and editor in the post editor
+ *
+ * @since 3.5.0
+ */
+function edit_form_image_editor() {
+ $post = get_post();
+
+ $thumb_url = false;
+ if ( $attachment_id = intval( $post->ID ) )
+ $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 600 ), true );
+
+ $filename = esc_html( basename( $post->guid ) );
+ $title = esc_attr( $post->post_title );
+
+ $post_mime_types = get_post_mime_types();
+ $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
+ $type = array_shift( $keys );
+ $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
+
+ $media_dims = '';
+ $meta = wp_get_attachment_metadata( $post->ID );
+ if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
+ $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
+ $media_dims = apply_filters( 'media_meta', $media_dims, $post );
+
+ $att_url = wp_get_attachment_url( $post->ID );
+
+ $image_edit_button = '';
+ if ( gd_edit_image_support( $post->post_mime_type ) ) {
+ $nonce = wp_create_nonce( "image_editor-$post->ID" );
+ $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='' />";
+ }
+
+ ?>
+ <div class="wp_attachment_holder">
+ <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>
+
+ <div class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>">
+ <p><img class="thumbnail" src="<?php echo $thumb_url[0]; ?>" style="max-width:100%" width="<?php echo $thumb_url[1]; ?>" alt="" /></p>
+ <p><?php echo $image_edit_button; ?></p>
+ </div>
+ <div style="display:none" class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"></div>
+
+ <div class="wp_attachment_details">
+ <p>
+ <label for="attachment_url"><strong><?php _e( 'File URL' ); ?></strong></label><br />
+ <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php echo esc_attr($att_url); ?>" /><br />
+ </p>
+ <p><strong><?php _e( 'File name:' ); ?></strong> <?php echo $filename; ?><br />
+ <strong><?php _e( 'File type:' ); ?></strong> <?php echo $post->post_mime_type; ?>
+ <?php
+ if ( $media_dims )
+ echo '<br /><strong>' . __( 'Dimensions:' ) . '</strong> ' . $media_dims;
+ ?>
+ </p>
+ </div>
+ </div>
+ <?php
+}
+
add_filter( 'async_upload_image', 'get_media_item', 10, 2 );
add_filter( 'async_upload_audio', 'get_media_item', 10, 2 );
add_filter( 'async_upload_video', 'get_media_item', 10, 2 );
Oops, something went wrong.

0 comments on commit 33af30e

Please sign in to comment.