mirror of
git://develop.git.wordpress.org/
synced 2025-03-21 04:20:01 +01:00
Themes: Correct the logic for displaying a _doing_it_wrong()
notice for add_theme_support( 'html5' )
.
* Calling `add_theme_support( 'html5' )` without passing an array of supported types should throw a `_doing_it_wrong()` notice: "You need to pass an array of types". * If the second parameter is not specified, it should fall back to an array of `comment-list`, `comment-form`, and `search-form` for backward compatibility. * If the second parameter is not an array, the function should return `false`. The latter two points are covered by existing unit tests. The first one is now addressed by `@expectedIncorrectUsage`. Follow-up to [25193], [25235], [25785]. Props audrasjb, peterwilsoncc, SergeyBiryukov. Fixes #51657. git-svn-id: https://develop.svn.wordpress.org/trunk@52828 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c3a8e5c9fd
commit
4cee32dd66
@ -2607,16 +2607,19 @@ function add_theme_support( $feature, ...$args ) {
|
||||
|
||||
case 'html5':
|
||||
// You can't just pass 'html5', you need to pass an array of types.
|
||||
if ( empty( $args[0] ) ) {
|
||||
// Build an array of types for back-compat.
|
||||
$args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) );
|
||||
} elseif ( ! isset( $args[0] ) || ! is_array( $args[0] ) ) {
|
||||
if ( empty( $args[0] ) || ! is_array( $args[0] ) ) {
|
||||
_doing_it_wrong(
|
||||
"add_theme_support( 'html5' )",
|
||||
__( 'You need to pass an array of types.' ),
|
||||
'3.6.1'
|
||||
);
|
||||
return false;
|
||||
|
||||
if ( ! empty( $args[0] ) && ! is_array( $args[0] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Build an array of types for back-compat.
|
||||
$args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) );
|
||||
}
|
||||
|
||||
// Calling 'html5' again merges, rather than overwrites.
|
||||
|
@ -76,11 +76,18 @@ class Tests_Theme_Support extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 24932
|
||||
*
|
||||
* @expectedIncorrectUsage add_theme_support( 'html5' )
|
||||
*/
|
||||
public function test_supports_html5() {
|
||||
remove_theme_support( 'html5' );
|
||||
$this->assertFalse( current_theme_supports( 'html5' ) );
|
||||
$this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
|
||||
|
||||
/*
|
||||
* If the second parameter is not specified, it should throw a _doing_it_wrong() notice
|
||||
* and fall back to `array( 'comment-list', 'comment-form', 'search-form' )` for back-compat.
|
||||
*/
|
||||
$this->assertNotFalse( add_theme_support( 'html5' ) );
|
||||
$this->assertTrue( current_theme_supports( 'html5' ) );
|
||||
$this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) );
|
||||
@ -98,6 +105,8 @@ class Tests_Theme_Support extends WP_UnitTestCase {
|
||||
remove_theme_support( 'html5' );
|
||||
$this->assertFalse( current_theme_supports( 'html5' ) );
|
||||
$this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
|
||||
|
||||
// The second parameter should be an array.
|
||||
$this->assertFalse( add_theme_support( 'html5', 'comment-form' ) );
|
||||
$this->assertNotFalse( add_theme_support( 'html5', array( 'comment-form' ) ) );
|
||||
$this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user