Make WordPress Core

Opened 12 years ago

Last modified 5 years ago

#21912 new enhancement

Add return filter to current_theme_supports()

Reported by: djpaul's profile DJPaul Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Themes Keywords: has-patch needs-refresh
Focuses: Cc:

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 12 years ago.

Download all attachments as: .zip

Change History (8)

@DJPaul
12 years ago

#1 @nacin
12 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
12 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
12 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
11 years ago

  • Version changed from trunk to 3.4

#5 @nacin
11 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
11 years ago

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

#7 @chriscct7
9 years ago

  • Keywords needs-refresh added
Note: See TracTickets for help on using tickets.