WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 3 months ago

#18790 new defect (bug)

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

Reported by: Jesper800 Owned by:
Milestone: Awaiting Review 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 3 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 @kawauso4 years ago

  • Keywords needs-patch added

comment:2 @toscho4 years ago

  • Cc info@… added

@andrewsfreeman3 years ago

comment:3 @andrewsfreeman3 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.

Version 0, edited 3 years ago by andrewsfreeman (next)

comment:4 @obenland3 months 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.

Note: See TracTickets for help on using tickets.