Make WordPress Core

Changeset 25193


Ignore:
Timestamp:
08/31/2013 01:29:08 AM (13 years ago)
Author:
nacin
Message:

Fix 'html5' theme support.

  • Require it to have a second argument when adding.
  • Merge, rather than replace, on second add.
  • Make current_theme_supports() work when two arguments are passed.

Adds unit tests.

props nathanrice for initial patch.
see #24932 for trunk.

Location:
trunk
Files:
2 edited

Legend:

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

    r25025 r25193  
    12721272                        break;
    12731273
     1274                case 'html5' :
     1275                        // You can't just pass 'html5', you need to pass an array of types.
     1276                        if ( ! is_array( $args[0] ) )
     1277                                return false;
     1278
     1279                        // Calling 'html5' again merges, rather than overwrites.
     1280                        if ( isset( $_wp_theme_features['html5'] ) )
     1281                                $args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] );
     1282                        break;
     1283
    12741284                case 'custom-header-uploads' :
    12751285                        return add_theme_support( 'custom-header', array( 'uploads' => true ) );
     
    15551565                        break;
    15561566
     1567                case 'html5':
    15571568                case 'post-formats':
    15581569                        // specific post formats can be registered by passing an array of types to
    15591570                        // add_theme_support()
    1560                         $post_format = $args[0];
    1561                         return in_array( $post_format, $_wp_theme_features[$feature][0] );
     1571
     1572                        // Specific areas of HTML5 support *must* be passed via an array to add_theme_support()
     1573
     1574                        $type = $args[0];
     1575                        return in_array( $type, $_wp_theme_features[$feature][0] );
    15621576                        break;
    15631577
  • trunk/tests/phpunit/tests/theme/support.php

    r25002 r25193  
    7979        }
    8080
     81        /**
     82         * @ticket 24932
     83         */
     84        function test_supports_html5() {
     85                remove_theme_support( 'html5' );
     86                $this->assertFalse( current_theme_supports( 'html5' ) );
     87                $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
     88                $this->assertFalse( add_theme_support( 'html5' ) );
     89                $this->assertFalse( current_theme_supports( 'html5' ) );
     90                $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
     91        }
     92
     93        /**
     94         * @ticket 24932
     95         */
     96        function test_supports_html5_subset() {
     97                remove_theme_support( 'html5' );
     98                $this->assertFalse( current_theme_supports( 'html5' ) );
     99                $this->assertFalse( current_theme_supports( 'html5', 'comment-form' ) );
     100                $this->assertFalse( add_theme_support( 'html5', 'comment-form' ) );
     101                $this->assertNotSame( false, add_theme_support( 'html5', array( 'comment-form' ) ) );
     102                $this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) );
     103
     104                // This will return true, which might help a plugin author decide what markup to serve,
     105                // but core should never check for it.
     106                $this->assertTrue( current_theme_supports( 'html5' ) );
     107
     108                // It appends, rather than replaces.
     109                $this->assertFalse( current_theme_supports( 'html5', 'comments-list' ) );
     110                $this->assertNotSame( false, add_theme_support( 'html5', array( 'comments-list' ) ) );
     111                $this->assertTrue( current_theme_supports( 'html5', 'comment-form' ) );
     112                $this->assertTrue( current_theme_supports( 'html5', 'comments-list' ) );
     113                $this->assertFalse( current_theme_supports( 'html5', 'search-form' ) );
     114
     115                // Removal is all or nothing.
     116                $this->assertTrue( remove_theme_support( 'html5' ) );
     117                $this->assertFalse( current_theme_supports( 'html5', 'comments-list' ) );
     118                $this->assertFalse( current_theme_supports( 'html5', 'comments-form' ) );
     119                $this->assertFalse( current_theme_supports( 'html5', 'search-form' ) );
     120        }
     121
    81122        function supports_foobar( $yesno, $args, $feature ) {
    82123                if ( $args[0] == $feature[0] )
Note: See TracChangeset for help on using the changeset viewer.