Make WordPress Core

Changeset 52828


Ignore:
Timestamp:
03/07/2022 02:42:49 PM (3 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/theme.php

    r52812 r52828  
    26082608        case 'html5':
    26092609            // You can't just pass 'html5', you need to pass an array of types.
    2610             if ( empty( $args[0] ) ) {
    2611                 // Build an array of types for back-compat.
    2612                 $args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) );
    2613             } elseif ( ! isset( $args[0] ) || ! is_array( $args[0] ) ) {
     2610            if ( empty( $args[0] ) || ! is_array( $args[0] ) ) {
    26142611                _doing_it_wrong(
    26152612                    "add_theme_support( 'html5' )",
     
    26172614                    '3.6.1'
    26182615                );
    2619                 return false;
     2616
     2617                if ( ! empty( $args[0] ) && ! is_array( $args[0] ) ) {
     2618                    return false;
     2619                }
     2620
     2621                // Build an array of types for back-compat.
     2622                $args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) );
    26202623            }
    26212624
  • trunk/tests/phpunit/tests/theme/support.php

    r52812 r52828  
    7777    /**
    7878     * @ticket 24932
     79     *
     80     * @expectedIncorrectUsage add_theme_support( 'html5' )
    7981     */
    8082    public function test_supports_html5() {
     
    8284        $this->assertFalse( current_theme_supports( 'html5' ) );
    8385        $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
     86
     87        /*
     88         * If the second parameter is not specified, it should throw a _doing_it_wrong() notice
     89         * and fall back to `array( 'comment-list', 'comment-form', 'search-form' )` for back-compat.
     90         */
    8491        $this->assertNotFalse( add_theme_support( 'html5' ) );
    8592        $this->assertTrue( current_theme_supports( 'html5' ) );
     
    99106        $this->assertFalse( current_theme_supports( 'html5' ) );
    100107        $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
     108
     109        // The second parameter should be an array.
    101110        $this->assertFalse( add_theme_support( 'html5', 'comment-form' ) );
    102111        $this->assertNotFalse( add_theme_support( 'html5', array( 'comment-form' ) ) );
Note: See TracChangeset for help on using the changeset viewer.