Post Thumbnails: When using add_theme_support( ‘post-thumbnails’, array( $post_types) )
merge the supported post_types.
Allow the adding of post-thumbnail support for one or more post_types without unsetting any previously added post_types. This matches the behavior of other uses of `add_theme_support()` and the expectations of a function with a prefix of “add”. To unset post-thumbnail support use `remove_theme_support()` instead. Fixes #22080 Props alexkingorg, jmichaelward, and flixos90. git-svn-id: https://develop.svn.wordpress.org/trunk@37308 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
274902b03a
commit
2ff19ab7d3
@ -1535,6 +1535,24 @@ function add_theme_support( $feature ) {
|
||||
$args = array_slice( func_get_args(), 1 );
|
||||
|
||||
switch ( $feature ) {
|
||||
case 'post-thumbnails':
|
||||
// All post types are already supported.
|
||||
if ( true === get_theme_support( 'post-thumbnails' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Merge post types with any that already declared their support
|
||||
* for post thumbnails.
|
||||
*/
|
||||
if ( is_array( $args[0] ) && is_array( $_wp_theme_features['post-thumbnails'][0] ) ) {
|
||||
$post_types = array_unique( array_merge( $args[0], $_wp_theme_features['post-thumbnails'][0] ) );
|
||||
|
||||
$args = array( $post_types );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'post-formats' :
|
||||
if ( is_array( $args[0] ) ) {
|
||||
$post_formats = get_post_format_slugs();
|
||||
|
@ -52,6 +52,23 @@ class Tests_Theme_Support extends WP_UnitTestCase {
|
||||
$this->assertFalse( current_theme_supports( 'post-thumbnails' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 22080
|
||||
*/
|
||||
public function test_post_thumbnails_mixed_args() {
|
||||
add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
|
||||
add_theme_support( 'post-thumbnails', array( 'page' ) );
|
||||
$this->assertTrue( current_theme_support( 'post-thumbnails', 'post' ) );
|
||||
$this->assertFalse( current_theme_supports( 'post-thumbnails', 'book' ) );
|
||||
$this->assertEquals(
|
||||
array( 0 => array( 'post', 'page' ) ),
|
||||
get_theme_support( 'post-thumbnails' )
|
||||
);
|
||||
|
||||
add_theme_support( 'post-thumbnails' );
|
||||
$this->assertTrue( current_theme_supports( 'post-thumbnails', 'book' ) );
|
||||
}
|
||||
|
||||
public function test_post_thumbnails_types_true() {
|
||||
// array of arguments, with the key of 'types' holding the post types.
|
||||
add_theme_support( 'post-thumbnails', array( 'types' => true ) );
|
||||
|
Loading…
Reference in New Issue
Block a user