Make WordPress Core

Changeset 43790


Ignore:
Timestamp:
10/22/2018 07:57:07 PM (6 years ago)
Author:
danielbachhuber
Message:

Themes: Introduce responsive embeds support.

Responsive embeds is a way for a theme to opt in to WordPress dynamically scaling the width/height of an embed. When a theme supports responsive embeds, a wp-embed-responsive class is added to the <body> tag. This information is also presented through the REST API for clients to respect.

Props desrosj.
Fixes #45125.

Location:
branches/5.0
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/post-template.php

    r41583 r43790  
    721721    if ( has_custom_logo() ) {
    722722        $classes[] = 'wp-custom-logo';
     723    }
     724
     725    if ( current_theme_supports( 'responsive-embeds' ) ) {
     726        $classes[] = 'wp-embed-responsive';
    723727    }
    724728
  • branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php

    r43735 r43790  
    112112            $data['theme_supports']['formats'] = $formats;
    113113
    114             $data['theme_supports']['post-thumbnails'] = false;
    115             $post_thumbnails                           = get_theme_support( 'post-thumbnails' );
     114            $data['theme_supports']['post-thumbnails']   = false;
     115            $data['theme_supports']['responsive-embeds'] = (bool) get_theme_support( 'responsive-embeds' );
     116            $post_thumbnails                             = get_theme_support( 'post-thumbnails' );
    116117
    117118            if ( $post_thumbnails ) {
     
    157158                    'readonly'    => true,
    158159                    'properties'  => array(
    159                         'formats'         => array(
     160                        'formats'           => array(
    160161                            'description' => __( 'Post formats supported.' ),
    161162                            'type'        => 'array',
    162163                            'readonly'    => true,
    163164                        ),
    164                         'post-thumbnails' => array(
     165                        'post-thumbnails'   => array(
    165166                            'description' => __( 'Whether the theme supports post thumbnails.' ),
    166167                            'type'        => array( 'array', 'bool' ),
     168                            'readonly'    => true,
     169                        ),
     170                        'responsive-embeds' => array(
     171                            'description' => __( 'Whether the theme supports responsive embedded content.', 'gutenberg' ),
     172                            'type'        => 'bool',
    167173                            'readonly'    => true,
    168174                        ),
  • branches/5.0/src/wp-includes/theme.php

    r43040 r43790  
    22112211 * @since 4.5.0 The `customize-selective-refresh-widgets` feature was added
    22122212 * @since 4.7.0 The `starter-content` feature was added
     2213 * @since 5.0.0 The `responsive-embeds` feature was added.
    22132214 *
    22142215 * @global array $_wp_theme_features
     
    22162217 * @param string $feature  The feature being added. Likely core values include 'post-formats',
    22172218 *                         'post-thumbnails', 'html5', 'custom-logo', 'custom-header-uploads',
    2218  *                         'custom-header', 'custom-background', 'title-tag', 'starter-content', etc.
     2219 *                         'custom-header', 'custom-background', 'title-tag', 'starter-content',
     2220 *                         'responsive-embeds/', etc.
    22192221 * @param mixed  $args,... Optional extra arguments to pass along with certain features.
    22202222 * @return void|bool False on failure, void otherwise.
  • branches/5.0/tests/phpunit/tests/rest-api/rest-themes-controller.php

    r43735 r43790  
    190190        $this->assertArrayHasKey( 'theme_supports', $properties );
    191191
    192         $this->assertEquals( 2, count( $properties['theme_supports']['properties'] ) );
     192        $this->assertEquals( 3, count( $properties['theme_supports']['properties'] ) );
    193193        $this->assertArrayHasKey( 'formats', $properties['theme_supports']['properties'] );
    194194        $this->assertArrayHasKey( 'post-thumbnails', $properties['theme_supports']['properties'] );
     195        $this->assertArrayHasKey( 'responsive-embeds', $properties['theme_supports']['properties'] );
    195196    }
    196197
     
    221222        $this->assertTrue( isset( $result[0]['theme_supports']['formats'] ) );
    222223        $this->assertSame( array( 'standard', 'aside', 'video' ), $result[0]['theme_supports']['formats'] );
     224    }
     225
     226    /**
     227     * Test when a theme does not support responsive embeds.
     228     *
     229     * @ticket 45016
     230     */
     231    public function test_theme_supports_responsive_embeds_false() {
     232        remove_theme_support( 'responsive-embeds' );
     233        $response = self::perform_active_theme_request();
     234
     235        $result = $response->get_data();
     236        $this->assertTrue( isset( $result[0]['theme_supports'] ) );
     237        $this->assertTrue( isset( $result[0]['theme_supports']['responsive-embeds'] ) );
     238        $this->assertFalse( $result[0]['theme_supports']['responsive-embeds'] );
     239    }
     240
     241    /**
     242     * Test when a theme supports responsive embeds.
     243     *
     244     * @ticket 45016
     245     */
     246    public function test_theme_supports_responsive_embeds_true() {
     247        remove_theme_support( 'responsive-embeds' );
     248        add_theme_support( 'responsive-embeds' );
     249        $response = self::perform_active_theme_request();
     250        $result   = $response->get_data();
     251        $this->assertTrue( isset( $result[0]['theme_supports'] ) );
     252        $this->assertTrue( $result[0]['theme_supports']['responsive-embeds'] );
    223253    }
    224254
  • branches/5.0/tests/phpunit/tests/theme/support.php

    r39919 r43790  
    192192        $this->assertFalse( current_theme_supports( 'menus' ) );
    193193    }
     194
     195    /**
     196     * @ticket 45125
     197     */
     198    function test_responsive_embeds() {
     199        add_theme_support( 'responsive-embeds' );
     200        $this->assertTrue( current_theme_supports( 'responsive-embeds' ) );
     201        remove_theme_support( 'responsive-embeds' );
     202        $this->assertFalse( current_theme_supports( 'responsive-embeds' ) );
     203        add_theme_support( 'responsive-embeds' );
     204        $this->assertTrue( current_theme_supports( 'responsive-embeds' ) );
     205    }
    194206}
Note: See TracChangeset for help on using the changeset viewer.