Make WordPress Core

Opened 4 years ago

Closed 20 months ago

#23932 closed enhancement (fixed)

Support for remove_post_type_support() in attachment post type

Reported by: flyingtrolleycars Owned by: antpb
Milestone: 4.3 Priority: normal
Severity: normal Version: 3.5.1
Component: Media Keywords: good-first-bug has-patch
Focuses: Cc:


In the past it was possible to remove certain fields from the media editor by hooking "attachment_fields_to_edit" and unset'ing the fields you didn't want included (e.g. caption).

After the media library got the major rework in WP3.5 its longer possible to remove those fields.

I believe that since the attachment post type has been more closely lined up to normal posts it should support remove_post_type_support() et al.

The easiest (and probably popular) case for this is removing the editor. I believe this code should do the trick:

remove_post_type_support( 'attachment', 'editor' );

Attachments (7)

23932.patch (5.0 KB) - added by antpb 2 years ago.
Patch for remove_post_type_support() in attachment post type
23932-1.patch (4.6 KB) - added by antpb 2 years ago.
23932-2.patch (7.4 KB) - added by antpb 2 years ago.
23932-3.patch (233.0 KB) - added by antpb 2 years ago.
23932-4.patch (7.4 KB) - added by antpb 2 years ago.
23932-5.patch (6.5 KB) - added by antpb 23 months ago.
Patch update to remove theme changes
23932-6.patch (1.3 KB) - added by antpb 20 months ago.

Download all attachments as: .zip

Change History (23)

#1 @mordauk
3 years ago

I'd love to see this. I'd think that removing support for "caption", for example, would remove the caption field both from the media modal and also the edit media screen.

#2 @ericlewis
3 years ago

  • Keywords needs-patch added

Caption maps to post_excerpt, Description maps to post_content, the remove_post_type_support() calls should respect that.

remove_post_type_support( 'attachment', 'title' ) works properly for the Edit Media screen, but not in the modal.

Alt text is saved as post meta under the _wp_attachment_image_alt key, so that can't be disabled via the same mechanism.

Needs patch.

Last edited 3 years ago by ericlewis (previous) (diff)

#3 @johnbillion
2 years ago

  • Keywords good-first-bug added
  • Owner set to antpb
  • Status changed from new to assigned

#4 follow-up: @antpb
2 years ago

In posts.php the array was not registering 'caption' for global $_wp_post_type_features;

This includes caption into the array

		'supports' => array( 'title', 'author', 'comments', 'caption' ),

Tested the array's output by printing it to screen. The below function (added to theme's function.php) gives the desired removal of the caption from the array but the media panel is not determining to show it based on this array. Continuing to look into where that is linked.

add_action( 'init' , 'my_remove_post_type_support' , 10 );
function my_remove_post_type_support() {
remove_post_type_support( 'attachment', 'caption' );
global $_wp_post_type_features;
Last edited 2 years ago by antpb (previous) (diff)

#5 in reply to: ↑ 4 @Solvitor
2 years ago

Fun pair programming at #wcsf14. @antpb will push it over the line!

#6 @antpb
2 years ago

  • Keywords has-patch dev-feedback needs-unit-tests added; needs-patch removed

First pass. Worked with Solvitor on this one so please share the credit!

We added 'alt' 'description' and 'caption' to the array that links up.

2 years ago

Patch for remove_post_type_support() in attachment post type

#7 @antpb
2 years ago

Found Bug, fixed and resubmitting patch.

2 years ago

#8 @antpb
2 years ago

Noticed that the embed edit image panel was overlooked and revised media-template.php to omit captions and alt text if defined with remove_post_type_support

Adding updated patch.

2 years ago

#9 @antpb
2 years ago

Noticed unnecessary comment in closing of if statement. Revised patch to follow.

2 years ago

2 years ago

#10 @antpb
2 years ago

Patch updated

#11 follow-up: @wonderboymusic
23 months ago

  • Keywords needs-patch added; has-patch dev-feedback needs-unit-tests removed

There is code in the theme that shouldn't be in the patch.

#12 in reply to: ↑ 11 @antpb
23 months ago

Replying to wonderboymusic:

There is code in the theme that shouldn't be in the patch.

Removed theme code from patch. Here's the update.

23 months ago

Patch update to remove theme changes

#13 @antpb
23 months ago

  • Keywords has-patch added; needs-patch removed

#14 @antpb
20 months ago

As per Nacin's suggestion I have removed all of the post supports except title as it is the only one that is already registered as reported and may have the need to be removed. I have tested this and it seems to be working fine when adding the removal of the title post type and also without the removal.

20 months ago

#15 @nacin
20 months ago

  • Milestone changed from Awaiting Review to 4.3

It doesn't look like there is much of a demand for this, so I suggested to @antpb that we simply fix this for 'title', since it's an existing supports argument.

Adding new 'supports' arguments is a bit tenuous, and has gotten us to consider things like a separate 'disables' flag. (This came up with #21391 and elsewhere, but hasn't had a real need yet.)

In this case, I don't see a major reason to disable other fields, though. And if you needed to, you could still hide or remove them via JS or PHP. There's also the old disable_captions filter we kept around after 3.5.

Committing 23932-6.patch.

#16 @nacin
20 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 32773:

Media: Support title fields to be removed from attachments.

props antpb.
fixes #23932.

Note: See TracTickets for help on using tickets.