WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#22642 closed enhancement (fixed)

Media: API to add back the description field in the new media popup

Reported by: batmoo Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

Description was dropped as a field in the media popup. Would be nice to have a allow plugins to re-add the field.

Attachments (3)

22642.diff (687 bytes) - added by nacin 6 years ago.
22642.2.diff (1.3 KB) - added by nacin 6 years ago.
22642.3.diff (2.1 KB) - added by nacin 6 years ago.

Download all attachments as: .zip

Change History (10)

@nacin
6 years ago

#1 @nacin
6 years ago

With the patch:

add_filter( 'attachment_fields_to_edit', function( $fields, $post ) {
	$fields['post_content'] = array(
			'label'      => __('Description'),
			'value'      => $post->post_content,
			'input'      => 'textarea'
	);
	return $fields;
}, 10, 2 );

#2 @nacin
6 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 3.5

On why the unset() calls are there: get_attachment_fields_to_edit() returns all of those fields: align, caption, size choices, etc. But because it returns all of those fields, it is very slow. (In particular, image_downsize() is slow. See #22598 for how we work around that.) So instead, we just apply the raw filter.

I kept the unset() calls because it is possible that a plugin could be re-defining some of those fields in a bad way (rather than just appending to the array), and we wouldn't want that, as we already handle those fields in newer, better ways.

The exception is Description (post_content). We don't handle it, but it was something get_attachment_fields_to_edit() previously returned. Stop unsetting it, and now a plugin can add it back with just a few lines of code.

@nacin
6 years ago

#3 @nacin
6 years ago

Second patch tosses in a save handler for free. Since it used to be a default field, I figure we can just continue to account for it in core.

#4 @batmoo
6 years ago

Patch and code snippet work nicely for the media popup but duplicates the description field on the "Edit Media" screen.

@nacin
6 years ago

#5 @batmoo
6 years ago

Working beautifully.

#6 @koopersmith
6 years ago

  • Keywords commit added

Looks good.

#7 @ryan
6 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In 22929:

Introduce API to add back the description field in the new media popup.

Props nacin
fixes #22642

Note: See TracTickets for help on using tickets.