[wp-trac] [WordPress Trac] #22080: add_theme_support should merge post-thumbnail post types by default (currently stomps)

WordPress Trac noreply at wordpress.org
Mon Apr 25 05:17:41 UTC 2016


#22080: add_theme_support should merge post-thumbnail post types by default
(currently stomps)
-------------------------------------+-----------------------------
 Reporter:  alexkingorg              |       Owner:
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  Future Release
Component:  Post Thumbnails          |     Version:  2.9
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-refresh  |     Focuses:
-------------------------------------+-----------------------------

Comment (by jmichaelward):

 I just uploaded a proposed patch to this issue. It checks for two cases
 when users attempt to add post-thumbnail support to a theme:

 1. If `get_theme_support( 'post-thumbnails' )` returns a boolean value of
 `true`, the function returns. Post thumbnails have already been declared
 for all post types.

 2. Next, if the arguments are an array and the global `$_wp_theme_features
 ['post-thumbnails']` value is an array, those values will get merged and
 non-unique values will be discarded. These new arguments get applied at
 the end of the function.

 In the third-party realm, this code change can cause some compatibility
 issues depending on the checks that are being run. In WooCommerce's case,
 they're only calling `add_theme_support( 'post-thumbnails' )` if the
 current theme supports post thumbnails. With the fixed case, this would be
 true when a user adds, for instance, `add_theme_support( 'post-
 thumbnails', array( 'post' ) );` to `functions.php`, as post thumbnails
 would no longer be available to WooCommerce's product post type because
 the check would return `true`. This can be fixed by Woo by updating their
 conditional check from:

 {{{
 function add_thumbnail_support() {
     if ( ! current_theme_supports( 'post-thumbnails' ) ) {
         add_theme_support( 'post-thumbnails' );
     }

     add_post_type_support( 'product', 'thumbnail' );
 }
 }}}

 to:

 {{{
 function add_thumbnail_support() {
     if ( ! current_theme_supports( 'post-thumbnails' ) || ! in_array(
 'product', get_theme_support( 'post-thumbnails' ) ) ) {
             add_theme_support( 'post-thumbnails', array( 'product' ) );
     }

     add_post_type_support( 'product', 'thumbnail' );
 }
 }}}

 The caveat here is there's no telling how many plugins might be running
 similar checks. I'd appreciate any feedback or insight others can provide
 into this issue.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/22080#comment:30>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list