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.

Built from https://develop.svn.wordpress.org/branches/5.0@43790


git-svn-id: http://core.svn.wordpress.org/branches/5.0@43619 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
danielbachhuber 2018-10-23 06:07:39 +00:00
parent 8efbcce93b
commit 8caf4f9260
6 changed files with 51 additions and 38 deletions

View File

@ -16,11 +16,6 @@ function render_block_core_categories( $attributes ) {
static $block_id = 0;
$block_id++;
$align = 'center';
if ( isset( $attributes['align'] ) && in_array( $attributes['align'], array( 'left', 'right', 'full' ), true ) ) {
$align = $attributes['align'];
}
$args = array(
'echo' => false,
'hierarchical' => ! empty( $attributes['showHierarchy'] ),
@ -46,10 +41,14 @@ function render_block_core_categories( $attributes ) {
$type = 'list';
}
$class = "wp-block-categories wp-block-categories-{$type} align{$align}";
$class = "wp-block-categories wp-block-categories-{$type}";
if ( isset( $attributes['align'] ) ) {
$class .= " align{$attributes['align']}";
}
if ( isset( $attributes['className'] ) ) {
$class .= ' ' . $attributes['className'];
$class .= " {$attributes['className']}";
}
$block_content = sprintf(

View File

@ -5,32 +5,34 @@
* @package gutenberg
*/
/**
* Get the post title.
*
* The post title is fetched and if it is blank then a default string is
* returned.
*
* Copied from `wp-admin/includes/template.php`, but we can't include that
* file because:
*
* 1. It causes bugs with test fixture generation and strange Docker 255 error
* codes.
* 2. It's in the admin; ideally we *shouldn't* be including files from the
* admin for a block's output. It's a very small/simple function as well,
* so duplicating it isn't too terrible.
*
* @since 3.3.0
*
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
* @return string The post title if set; "(no title)" if no title is set.
*/
function gutenberg_draft_or_post_title( $post = 0 ) {
$title = get_the_title( $post );
if ( empty( $title ) ) {
$title = __( '(no title)', 'gutenberg' );
if ( ! function_exists( 'gutenberg_draft_or_post_title' ) ) {
/**
* Get the post title.
*
* The post title is fetched and if it is blank then a default string is
* returned.
*
* Copied from `wp-admin/includes/template.php`, but we can't include that
* file because:
*
* 1. It causes bugs with test fixture generation and strange Docker 255 error
* codes.
* 2. It's in the admin; ideally we *shouldn't* be including files from the
* admin for a block's output. It's a very small/simple function as well,
* so duplicating it isn't too terrible.
*
* @since 3.3.0
*
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
* @return string The post title if set; "(no title)" if no title is set.
*/
function gutenberg_draft_or_post_title( $post = 0 ) {
$title = get_the_title( $post );
if ( empty( $title ) ) {
$title = __( '(no title)', 'gutenberg' );
}
return esc_html( $title );
}
return esc_html( $title );
}
/**

View File

@ -722,6 +722,10 @@ function get_body_class( $class = '' ) {
$classes[] = 'wp-custom-logo';
}
if ( current_theme_supports( 'responsive-embeds' ) ) {
$classes[] = 'wp-embed-responsive';
}
$page = $wp_query->get( 'page' );
if ( ! $page || $page < 2 )

View File

@ -111,8 +111,9 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
$formats = array_merge( array( 'standard' ), $formats );
$data['theme_supports']['formats'] = $formats;
$data['theme_supports']['post-thumbnails'] = false;
$post_thumbnails = get_theme_support( 'post-thumbnails' );
$data['theme_supports']['post-thumbnails'] = false;
$data['theme_supports']['responsive-embeds'] = (bool) get_theme_support( 'responsive-embeds' );
$post_thumbnails = get_theme_support( 'post-thumbnails' );
if ( $post_thumbnails ) {
// $post_thumbnails can contain a nested array of post types.
@ -156,16 +157,21 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
'type' => 'array',
'readonly' => true,
'properties' => array(
'formats' => array(
'formats' => array(
'description' => __( 'Post formats supported.' ),
'type' => 'array',
'readonly' => true,
),
'post-thumbnails' => array(
'post-thumbnails' => array(
'description' => __( 'Whether the theme supports post thumbnails.' ),
'type' => array( 'array', 'bool' ),
'readonly' => true,
),
'responsive-embeds' => array(
'description' => __( 'Whether the theme supports responsive embedded content.', 'gutenberg' ),
'type' => 'bool',
'readonly' => true,
),
),
),
),

View File

@ -2210,12 +2210,14 @@ function get_theme_starter_content() {
* @since 4.1.0 The `title-tag` feature was added
* @since 4.5.0 The `customize-selective-refresh-widgets` feature was added
* @since 4.7.0 The `starter-content` feature was added
* @since 5.0.0 The `responsive-embeds` feature was added.
*
* @global array $_wp_theme_features
*
* @param string $feature The feature being added. Likely core values include 'post-formats',
* 'post-thumbnails', 'html5', 'custom-logo', 'custom-header-uploads',
* 'custom-header', 'custom-background', 'title-tag', 'starter-content', etc.
* 'custom-header', 'custom-background', 'title-tag', 'starter-content',
* 'responsive-embeds/', etc.
* @param mixed $args,... Optional extra arguments to pass along with certain features.
* @return void|bool False on failure, void otherwise.
*/

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-43789';
$wp_version = '5.0-alpha-43790';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.