WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 3 days ago

#19257 accepted enhancement

Allow post types to override the phrase "Featured image"

Reported by: johnbillion Owned by: johnbillion
Milestone: 4.3 Priority: normal
Severity: normal Version: 3.0
Component: Posts, Post Types Keywords: has-patch
Focuses: ui, administration Cc:

Description

It would be nice if the phrase "Featured image" could be filtered so it could be tailored to fit its post type. For example:

  • A post type of 'person' could set it to 'Mugshot'
  • A post type of 'album' could set it to 'Cover art'
  • A post type of 'company' could set it to 'Company Logo'

Patch upcoming.

Attachments (4)

19257.patch (7.7 KB) - added by johnbillion 4 years ago.
19257-2.patch (9.5 KB) - added by mordauk 12 days ago.
19257-tests.patch (1.6 KB) - added by mordauk 12 days ago.
19257.diff (12.0 KB) - added by valendesigns 3 days ago.

Download all attachments as: .zip

Change History (20)

comment:1 follow-up: @nacin4 years ago

Filtering the text itself is rather easy (if hacky), but it would be especially nice if set_post_thumbnail_size() and add_image_size() could be drilled down to individual post types.

See #18057 (patch on #18027) for something similar - the ability to define a "usage" for a featured image.

@johnbillion4 years ago

comment:2 follow-up: @johnbillion4 years ago

  • Keywords has-patch added

Here's my take on this. The attached patch adds three new labels to the post type objects. The defaults are:

  • featured_image => 'Featured Image'
  • set_featured_image => 'Set featured image'
  • remove_featured_image => 'Remove featured image'
  • use_featured_image => 'Use as featured image'

These strings are used in the featured image meta box and in the media lightbox.

A custom post type would set its own labels for featured images like so:

register_post_type( 'company', array(
	'labels' => array(
		'featured_image' => 'Company Logo',
		'set_featured_image' => 'Set company logo',
		'remove_featured_image' => 'Remove company logo',
		'use_featured_image' => 'Use as company logo'
	)
) );

comment:3 in reply to: ↑ 2 @DrewAPicture4 years ago

  • Cc xoodrew@… added

Replying to johnbillion:

A custom post type would set its own labels for featured images like so:

register_post_type( 'company', array(
	'labels' => array(
		'featured_image' => 'Company Logo',
		'set_featured_image' => 'Set company logo',
		'remove_featured_image' => 'Remove company logo',
		'use_featured_image' => 'Use as company logo'
	)
) );

+1 for this. This would be very helpful for many of my projects.

comment:4 @nacin4 years ago

  • Version changed from 3.3 to 3.0

comment:5 @jane4 years ago

  • Milestone changed from Awaiting Review to Future Release

Sounds good to me.

comment:6 @johnbillion3 years ago

I know it's late but this would be nice to see in 3.5.

comment:7 @JustinSainton3 years ago

+1 for the idea - not sure on the implementation of adding the labels vs. filters. But this would be super helpful. Currently filtering via gettext - which is hacky (like nacin said).

comment:8 in reply to: ↑ 1 @nacin3 years ago

Replying to nacin:

Filtering the text itself is rather easy (if hacky), but it would be especially nice if set_post_thumbnail_size() and add_image_size() could be drilled down to individual post types.

I think this should wait for this to occur. Filtering via gettext at least works. Adding an API for post types to modify the *labels* is completely lame if they can't do post-type-specific featured images.

The media, image, and thumbnail work in 3.5 should enable this to happen in 3.6 (probably not sooner).

comment:9 @chriscct72 weeks ago

  • Focuses ui administration added
  • Keywords needs-refresh good-first-bug added

This a pretty cool idea and would be useful for many plugins. Patch needs a refresh

@mordauk12 days ago

comment:10 @mordauk12 days ago

  • Keywords needs-testing needs-unit-tests added; needs-refresh good-first-bug removed

19257-2.patch is a refreshed and working patch.

https://cldup.com/IwxpJIymFp-3000x3000.png
https://cldup.com/vTp8hfdFGD-3000x3000.png
https://cldup.com/WHmUgjTCHD-3000x3000.png

@mordauk12 days ago

comment:11 @mordauk12 days ago

  • Keywords needs-unit-tests removed

19257-tests.patch adds a unit test for labels.

comment:12 @chriscct712 days ago

  • Owner set to chriscct7
  • Status changed from new to reviewing

comment:13 @slackbot6 days ago

This ticket was mentioned in Slack in #core by johnbillion. View the logs.

comment:14 @johnbillion6 days ago

  • Milestone changed from Future Release to 4.3
  • Owner changed from chriscct7 to johnbillion
  • Status changed from reviewing to accepted

comment:15 @valendesigns4 days ago

@johnbillion I started reviewing this on Wednesday, but I got sidetracked and I took yesterday off. I'll review it today in the next couple hours.

@valendesigns3 days ago

comment:16 @valendesigns3 days ago

  • Keywords needs-testing removed

Did a review and everything looks correct. There were some extra white spaces and the patch didn't apply clean anymore, so I refreshed it. As well, There were missing param docs in get_post_type_labels that I added in the process. Should be ready to go.

Note: See TracTickets for help on using tickets.