Opened 6 months ago

Closed 6 months ago

#22642 closed enhancement (fixed)

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

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

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 months ago.
22642.2.diff (1.3 KB) - added by nacin 6 months ago.
22642.3.diff (2.1 KB) - added by nacin 6 months ago.

Download all attachments as: .zip

Change History (10)

nacin6 months 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 );
  • 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.

nacin6 months 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.

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

nacin6 months ago

Working beautifully.

  • Keywords commit added

Looks good.

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