WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 2 months ago

#19257 closed enhancement (fixed)

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:
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 4 months ago.
19257-tests.patch (1.6 KB) - added by mordauk 4 months ago.
19257.diff (12.0 KB) - added by valendesigns 3 months ago.

Download all attachments as: .zip

Change History (29)

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 @chriscct74 months 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

@mordauk4 months ago

comment:10 @mordauk4 months 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

@mordauk4 months ago

comment:11 @mordauk4 months ago

  • Keywords needs-unit-tests removed

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

comment:12 @chriscct74 months ago

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

comment:13 @slackbot4 months ago

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

comment:14 @johnbillion4 months ago

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

comment:15 @valendesigns4 months 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 months ago

comment:16 @valendesigns3 months 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.

comment:17 @johnbillion3 months 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.

comment:18 @johnbillion3 months 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.

comment:19 @SergeyBiryukov3 months ago

In 32675:

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

see #19257.

comment:20 @SergeyBiryukov3 months ago

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

comment:21 @SergeyBiryukov3 months 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.

comment:22 @SergeyBiryukov3 months ago

In 32676:

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

see #19257.

comment:23 @obenland3 months ago

@johnbillion, what is left to do here?

comment:24 @slackbot3 months ago

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

comment:25 @johnbillion2 months 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.