Make WordPress Core

Opened 13 years ago

Closed 9 years ago

#19257 closed enhancement (fixed)

Allow post types to override the phrase "Featured image"

Reported by: johnbillion's profile johnbillion Owned by: johnbillion's profile johnbillion
Milestone: 4.3 Priority: normal
Severity: normal Version: 3.0
Component: Posts, Post Types Keywords:
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 13 years ago.
19257-2.patch (9.5 KB) - added by mordauk 9 years ago.
19257-tests.patch (1.6 KB) - added by mordauk 9 years ago.
19257.diff (12.0 KB) - added by valendesigns 9 years ago.

Download all attachments as: .zip

Change History (29)

#1 follow-up: @nacin
13 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.

@johnbillion
13 years ago

#2 follow-up: @johnbillion
13 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'
	)
) );

#3 in reply to: ↑ 2 @DrewAPicture
13 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.

#4 @nacin
13 years ago

  • Version changed from 3.3 to 3.0

#5 @jane
13 years ago

  • Milestone changed from Awaiting Review to Future Release

Sounds good to me.

#6 @johnbillion
12 years ago

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

#7 @JustinSainton
12 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).

#8 in reply to: ↑ 1 @nacin
12 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).

#9 @chriscct7
9 years 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

@mordauk
9 years ago

#10 @mordauk
9 years 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

@mordauk
9 years ago

#11 @mordauk
9 years ago

  • Keywords needs-unit-tests removed

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

#12 @chriscct7
9 years ago

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

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


9 years ago

#14 @johnbillion
9 years ago

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

#15 @valendesigns
9 years 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.

@valendesigns
9 years ago

#16 @valendesigns
9 years 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.

#17 @johnbillion
9 years ago

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

In 32673:

Introduce featured_image, set_featured_image, remove_featured_image, and use_featured_image post type labels when registering a post type in order to override the 'Featured Image' text and its related phrases.

Props johnbillion, mordauk, valendesigns.
Fixes #19257.

#18 @johnbillion
9 years ago

  • Keywords needs-patch added; has-patch removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

r32673 is causing notices on the Media screen:

Trying to get property of non-object in ~/wp-includes/media.php on line 3011

Looks like $post at that point can be null.

#19 @SergeyBiryukov
9 years ago

In 32675:

Avoid a PHP notice in wp_enqueue_media() if $post is null.

see #19257.

#20 @SergeyBiryukov
9 years ago

[32673] broke make/core: get_post_types() does not exist in wp-admin/load-scripts.php (only exists if SCRIPT_DEBUG is true).

#21 @SergeyBiryukov
9 years ago

It looks like WPSetAsThumbnail() is never used in post-3.5 media UI and is only kept for back compat, so this part can be reverted.

#22 @SergeyBiryukov
9 years ago

In 32676:

Revert a part of [32673] that caused a fatal error with SCRIPT_DEBUG disabled.

see #19257.

#23 @obenland
9 years ago

@johnbillion, what is left to do here?

This ticket was mentioned in Slack in #design by stephdau. View the logs.


9 years ago

#25 @johnbillion
9 years ago

  • Keywords needs-patch removed
  • Resolution set to fixed
  • Status changed from reopened to closed

This wasn't as stable as I'd hoped, but Sergey's tweaks all look good, and no other breakage reports in 3 weeks. Closing.

Note: See TracTickets for help on using tickets.