Make WordPress Core

Opened 13 years ago

Last modified 5 years ago

#18790 new defect (bug)

add_theme_support with post type doesn't add theme support but overwrites it

Reported by: jesper800's profile Jesper800 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Themes Keywords: has-patch
Focuses: Cc:

Description

The function add_theme_support has an optional second parameter, which allows you to add support for post thumbnails for certain post types.

You would expect this function to add the theme support for that post type, but instead it overwrites the theme support for that feature, which results in the theme support being set for just the post type(s) that were passed.

Reproduce:

function add_thumbnails_support()
{
	add_theme_support('post-thumbnails', array('my_post_type'));
	print_r(get_theme_support('post-thumbnails'));
	
	add_theme_support('post-thumbnails', array('another_post_type'));
	print_r(get_theme_support('post-thumbnails'));
}

add_action('after_setup_theme', 'add_thumbnails_support');

Attachments (1)

18790.patch (790 bytes) - added by andrewsfreeman 12 years ago.

Download all attachments as: .zip

Change History (6)

#1 @kawauso
13 years ago

  • Keywords needs-patch added

#2 @toscho
13 years ago

  • Cc info@… added

#3 @andrewsfreeman
12 years ago

  • Cc andrewsfreeman added
  • Keywords has-patch added; needs-patch removed

I came across this problem today, wondering why my plugin didn't work as usual. A workaround I found was to just turn it on everywhere on init, but it would be nice to turn it on for a particular plugin's CPT.

My patch is simple - if it's already set and an array, merge the arrays. If it's already set to true (thumbnails everywhere), keep it true. Tested it on multiple CPTs and hooks.

It may possibly be redundant to make sure it is true, because otherwise it just wouldn't be set. Would be willing to re-upload if that is preferred.

Last edited 12 years ago by andrewsfreeman (previous) (diff)

#4 @obenland
9 years ago

I think I can get behind this. HTML% support works similarly. I wonder if this would cause any backwards compatibility concerns with implementations where developers counted on it being overwritten.

#5 @patrickmjones
8 years ago

Was about to report this ticket myself. I can't imagine a good reason to depend on trampling over what post types have added support for post-thumbnails. The API is pretty meaningless if calling it breaks the theme or other plugins. The patch will work for me and I thank you for that, but in the mean time my plugins can not be distributed (for years). I hope a solution can be made - new API functionality, rolling in the patch, etc. Thanks again, goodbye.

Note: See TracTickets for help on using tickets.