Opened 13 years ago
Last modified 6 years ago
#18790 new defect (bug)
add_theme_support with post type doesn't add theme support but overwrites it
Reported by: |
|
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)
Change History (6)
#4
@
10 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
@
9 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.
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.