From 173806d7a11704285d065558864f5981a24428ef Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Thu, 6 Dec 2012 00:41:06 +0000 Subject: [PATCH] Restore the Description field to the media UI in 3.5. We tried in vain -- a noble but ultimately failed effort -- to reduce the number of fields for attachments from four (title, caption, alt, description) to one (caption for images, title otherwise). Alternative text needed to stay for accessibility reasons, of course. Eventually title returned due to heavy plugin reliance. Description is too used by too many plugins (often times incorrectly -- the caption is more likely the proper field), hence its less-than-triumphant return today. Version 3.5 has tried to streamline media in a number of ways. Removing fields may have been too much at once, as it forced not only a user interface change, but a paradigm change as well. Finally, on upload we populate the description field with IPTC/EXIF captions, rather than the caption field. See #22768, this should be fixed. For now, Description stays. This commit also restores 'Title' attribute editing to the main tab of the Edit Image dialog. The "Title" field no longer populates title attributes for tags by design (for accessibility and other purposes, see #18984). So, here is a more obvious 'workaround' for the tooltip community. Finally, this: * Cleans up the post.php attachment editor, including by showing a prettier form of the mime type. * Enables plugins to specifically hide attachment_fields_to_edit from either post.php (where you can create meta boxes) or the modal (which you may not want to clutter), for compatibility reasons. * Hides the 'Describe this file...' placeholder when a field is read-only in the modal. props nacin, helenyhou. fixes #22759. git-svn-id: http://core.svn.wordpress.org/trunk@23083 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/css/wp-admin.css | 8 +++ wp-admin/edit-form-advanced.php | 1 - wp-admin/includes/ajax-actions.php | 7 +-- wp-admin/includes/media.php | 57 +++++++++++++------ wp-admin/includes/meta-boxes.php | 24 -------- wp-includes/js/media-editor.js | 3 +- wp-includes/js/media-views.js | 3 +- .../plugins/wpeditimage/editimage.html | 30 +++++----- wp-includes/media.php | 23 +++++--- 9 files changed, 84 insertions(+), 72 deletions(-) diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css index f4e2351398..0128cdef12 100644 --- a/wp-admin/css/wp-admin.css +++ b/wp-admin/css/wp-admin.css @@ -3407,6 +3407,10 @@ td.plugin-title p { display: none; } +#post-body-content .compat-attachment-fields { + margin-bottom: 20px; +} + .compat-attachment-fields th { padding-top: 5px; padding-right: 10px; @@ -4391,6 +4395,10 @@ span.imgedit-scale-warn { padding: 2px 10px; } +.wp_attachment_details { + margin-bottom: 20px; +} + /*------------------------------------------------------------------------------ 15.0 - Comments Screen ------------------------------------------------------------------------------*/ diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index d0b1ed579d..7d142d9af4 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -107,7 +107,6 @@ 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_content_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' ); diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index c33e383776..c39effe75e 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -1884,6 +1884,9 @@ function wp_ajax_save_attachment() { if ( isset( $changes['caption'] ) ) $post['post_excerpt'] = $changes['caption']; + if ( isset( $changes['description'] ) ) + $post['post_content'] = $changes['description']; + if ( isset( $changes['alt'] ) ) { $alt = get_post_meta( $id, '_wp_attachment_image_alt', true ); $new_alt = stripslashes( $changes['alt'] ); @@ -1923,10 +1926,6 @@ function wp_ajax_save_attachment_compat() { if ( 'attachment' != $post['post_type'] ) wp_send_json_error(); - // Handle the description field automatically, if a plugin adds it back. - if ( isset( $attachment_data['post_content'] ) ) - $post['post_content'] = $attachment_data['post_content']; - $post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data ); if ( isset( $post['errors'] ) ) { diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index e584b634e6..326505280c 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -1286,8 +1286,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) { $default_args = array( 'errors' => null, - 'taxonomies' => false, - 'description' => false, + 'in_modal' => false, ); $user_can_edit = current_user_can( 'edit_post', $attachment_id ); @@ -1297,7 +1296,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) { $form_fields = array(); - if ( $args['taxonomies'] ) { + if ( $args['in_modal'] ) { foreach ( get_attachment_taxonomies($post) as $taxonomy ) { $t = (array) get_taxonomy($taxonomy); if ( ! $t['public'] || ! $t['show_ui'] ) @@ -1329,19 +1328,18 @@ function get_compat_media_markup( $attachment_id, $args = null ) { $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'], - $form_fields['post_title'], $form_fields['post_excerpt'], + $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'], $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] ); - if ( ! $args['description'] ) - unset( $form_fields['post_content'] ); - $media_meta = apply_filters( 'media_meta', '', $post ); $defaults = array( - 'input' => 'text', - 'required' => false, - 'value' => '', - 'extra_rows' => array(), + 'input' => 'text', + 'required' => false, + 'value' => '', + 'extra_rows' => array(), + 'show_in_edit' => true, + 'show_in_modal' => true, ); $hidden_fields = array(); @@ -1361,6 +1359,9 @@ function get_compat_media_markup( $attachment_id, $args = null ) { $field = array_merge( $defaults, $field ); + if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) ) + continue; + if ( $field['input'] == 'hidden' ) { $hidden_fields[$name] = $field['value']; continue; @@ -2282,12 +2283,12 @@ function edit_form_image_editor() { $att_url = wp_get_attachment_url( $post->ID ); - $image_edit_button = ''; - if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { - $nonce = wp_create_nonce( "image_editor-$post->ID" ); - $image_edit_button = " "; - } - + if ( wp_attachment_is_image( $post->ID ) ) : + $image_edit_button = ''; + if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { + $nonce = wp_create_nonce( "image_editor-$post->ID" ); + $image_edit_button = " "; + } ?>
@@ -2298,6 +2299,7 @@ function edit_form_image_editor() {
+

@@ -2312,6 +2314,20 @@ function edit_form_image_editor() {

+ 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' ); + $editor_args = array( + 'textarea_name' => 'content', + 'textarea_rows' => 5, + 'media_buttons' => false, + 'tinymce' => false, + 'quicktags' => $quicktags_settings, + ); + ?> + + + post_content, 'attachment_content', $editor_args ); ?> +
ID ); @@ -2348,7 +2364,12 @@ function attachment_submitbox_metadata() {
- post_mime_type; ?> + ID ), $matches ) ) + echo esc_html( strtoupper( $matches[1] ) ); + else + echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); + ?>
diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index 39f7b04131..2b0b2864fc 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -295,30 +295,6 @@ function attachment_submit_meta_box( $post ) { 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' ); - $editor_args = array( - 'textarea_name' => 'content', - 'textarea_rows' => 5, - 'media_buttons' => false, - 'tinymce' => false, - 'quicktags' => $quicktags_settings, - ); -?> -

- - post_content, 'attachment_content', $editor_args ); ?> -

- - + -