WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 7 weeks ago

#23932 assigned enhancement

Support for remove_post_type_support() in attachment post type

Reported by: flyingtrolleycars Owned by: antpb
Milestone: Awaiting Review 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 (6)

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

Download all attachments as: .zip

Change History (19)

comment:1 @mordauk15 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 @ericlewis11 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 11 months ago by ericlewis (previous) (diff)

comment:3 @johnbillion6 months ago

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

comment:4 follow-up: @antpb6 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 6 months ago by antpb (previous) (diff)

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

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

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

@antpb6 months ago

Patch for remove_post_type_support() in attachment post type

comment:7 @antpb6 months ago

Found Bug, fixed and resubmitting patch.

@antpb6 months ago

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

@antpb6 months ago

comment:9 @antpb6 months ago

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

@antpb6 months ago

@antpb6 months ago

comment:10 @antpb6 months ago

Patch updated

comment:11 follow-up: @wonderboymusic7 weeks 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 @antpb7 weeks 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.

@antpb7 weeks ago

Patch update to remove theme changes

comment:13 @antpb7 weeks ago

  • Keywords has-patch added; needs-patch removed
Note: See TracTickets for help on using tickets.