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.
Built from https://develop.svn.wordpress.org/trunk@52828


git-svn-id: http://core.svn.wordpress.org/trunk@52417 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-03-07 14:44:01 +00:00
parent f33f3979ca
commit 2399966d8c
2 changed files with 9 additions and 6 deletions

View File

@ -2607,18 +2607,21 @@ 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'
);
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.
if ( isset( $_wp_theme_features['html5'] ) ) {
$args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-52827';
$wp_version = '6.0-alpha-52828';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.