WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 7 weeks 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:

Description

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 9 months ago.
Patch for remove_post_type_support() in attachment post type
23932-1.patch (4.6 KB) - added by antpb 9 months ago.
23932-2.patch (7.4 KB) - added by antpb 9 months ago.
23932-3.patch (233.0 KB) - added by antpb 9 months ago.
23932-4.patch (7.4 KB) - added by antpb 9 months ago.
23932-5.patch (6.5 KB) - added by antpb 5 months ago.
Patch update to remove theme changes
23932-6.patch (1.3 KB) - added by antpb 7 weeks ago.

Download all attachments as: .zip

Change History (23)

comment:1 @mordauk18 months 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.

comment:2 @ericlewis14 months 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 14 months ago by ericlewis (previous) (diff)

comment:3 @johnbillion9 months ago

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

comment:4 follow-up: @antpb9 months 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;
print_r($_wp_post_type_features);
}
Last edited 9 months ago by antpb (previous) (diff)

comment:5 in reply to: ↑ 4 @Solvitor9 months ago

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

comment:6 @antpb9 months 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.

@antpb9 months ago

Patch for remove_post_type_support() in attachment post type

comment:7 @antpb9 months ago

Found Bug, fixed and resubmitting patch.

@antpb9 months ago

comment:8 @antpb9 months 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.

@antpb9 months ago

comment:9 @antpb9 months ago

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

@antpb9 months ago

@antpb9 months ago

comment:10 @antpb9 months ago

Patch updated

comment:11 follow-up: @wonderboymusic5 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.

comment:12 in reply to: ↑ 11 @antpb5 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.

@antpb5 months ago

Patch update to remove theme changes

comment:13 @antpb5 months ago

  • Keywords has-patch added; needs-patch removed

comment:14 @antpb7 weeks 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.

@antpb7 weeks ago

comment:15 @nacin7 weeks 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.

comment:16 @nacin7 weeks 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.