Make WordPress Core

Opened 14 years ago

Last modified 7 months ago

#21912 new enhancement

Add return filter to current_theme_supports()

Reported by: DJPaul Owned by:
Priority: normal Milestone:
Component: Themes Version: 3.4
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

current_theme_supports() makes it hard for plugins to affect whether a theme supports a certain feature.

The use case I have is that I am building a plugin that utilises bbPress (and soon, BuddyPress)-style template compatibility parts. In those template parts, I display something very, very similar to a post thumbnail or custom header. I want to use the "Featured Image" metabox on the Post screen to set that image.

If I use the plugin on a theme that doesn't support post thumbnails, the metabox correctly doesn't appear, and so users have no way of choosing a featured image. While there are ways around this -- manual conditional registering of the Featured Image metabox, creating my own metabox, or calling add_theme_support/remove_theme_support like a toggle -- none of them are particularly elegant.

While current_theme_supports has a return filter, it's not reached by all code execution paths. The attached patch reworks the function so that the return value is always passed through the filter.

Attachments (1)

21912.001.patch​ (3.2 KB ) - added by DJPaul 14 years ago.

Download all attachments as: .zip

Change History (9)

#1 @nacin
14 years ago

Seems to me like manual registration of the meta box makes the most sense. You are *not* offering support for featured images, so tricking WordPress into thinking for a moment that you are, seems a bit weird.

I'm not entirely sure why current_theme_supports() has a filter at all, given that add/remove directly affect its value.

#2 @DJPaul
14 years ago

I am supporting featured images. I have a custom post type and I am showing the featured image in a specific place on the template. ​http://cl.ly/image/0E2u340n162L is a cropped screenshot showing what I mean.

(The post type is being used for much more than just body text and a featured image, otherwise I'd use a regular Post or Page).

#3 @scribu
14 years ago

I have a custom post type and I am showing the featured image in a specific place on the template.

Then you support the featured image only for that post type. Maybe the entire concept of "this theme supports featured images. period." is flawed.

#4 @SergeyBiryukov
14 years ago

  • Version trunk → 3.4

#5 @nacin
13 years ago

What about actually doing add_theme_support( 'post-thumbnails', 'your-post-type' ) in your plugin? (Or whatever the exact syntax is.) That would directly affect the return value of current_theme_supports() in pretty much exactly the way you'd like.

Unfortunately, you need to do a get(), array_merge(), then add(). See #22080. Because the theme support API is just a wrapper around a global array, I could go for a filter here after all.

#6 @DJPaul
13 years ago

Yeah, that's a workable interim solution which I wasn't aware of. Thanks for pointing it out.

#7 @chriscct7
11 years ago

  • Keywords needs-refresh added

This ticket was mentioned in ​PR #11603 on ​WordPress/wordpress-develop by ​@sainathpoojary.


7 months ago
#8

  • Keywords has-unit-tests added; needs-refresh removed

Trac ticket: #21912

Note: See TracTickets for help on using tickets.