Block Editor: Fix WP_Block_Supports class compatibility with Gutenberg-provided class.
When using WordPress trunk with Gutenberg master, there's an incompatibility causing the dynamic block generated classes to be omitted. This commit refactors the block supports to fix that problem. Props nosolosw. Fixes #51606. Built from https://develop.svn.wordpress.org/trunk@49310 git-svn-id: http://core.svn.wordpress.org/trunk@49072 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4bb4107f50
commit
bf5917edf3
|
@ -647,24 +647,11 @@ function _excerpt_render_inner_columns_blocks( $columns, $allowed_blocks ) {
|
|||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Block currently being parsed.
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
global $current_parsed_block;
|
||||
|
||||
$current_parsed_block = array(
|
||||
'blockName' => null,
|
||||
'attributes' => null,
|
||||
);
|
||||
|
||||
/**
|
||||
* Renders a single block into a HTML string.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @global array $current_parsed_block Block currently being parsed.
|
||||
* @global WP_Post $post The post to edit.
|
||||
* @global WP_Query $wp_query WordPress Query object.
|
||||
* @global WP_Query $wp_query WordPress Query object.
|
||||
|
@ -673,7 +660,7 @@ $current_parsed_block = array(
|
|||
* @return string String of rendered HTML.
|
||||
*/
|
||||
function render_block( $parsed_block ) {
|
||||
global $post, $wp_query, $current_parsed_block;
|
||||
global $post, $wp_query;
|
||||
|
||||
/**
|
||||
* Allows render_block() to be short-circuited, by returning a non-null value.
|
||||
|
@ -688,8 +675,6 @@ function render_block( $parsed_block ) {
|
|||
return $pre_render;
|
||||
}
|
||||
|
||||
$current_parsed_block = $parsed_block;
|
||||
|
||||
$source_block = $parsed_block;
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,6 +23,13 @@ class WP_Block_Supports {
|
|||
*/
|
||||
private $block_supports = array();
|
||||
|
||||
/**
|
||||
* Tracks the current block to be rendered.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $block_to_render = null;
|
||||
|
||||
/**
|
||||
* Container for the main instance of the class.
|
||||
*
|
||||
|
@ -72,20 +79,18 @@ class WP_Block_Supports {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates an array of HTML attributes, such as classes, by applying to
|
||||
* the given block all of the features that the block supports.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param array $parsed_block Block as parsed from content.
|
||||
* @return array Array of HTML attributes.
|
||||
*/
|
||||
public function apply_block_supports( $parsed_block ) {
|
||||
$block_attributes = $parsed_block['attrs'];
|
||||
public function apply_block_supports() {
|
||||
$block_attributes = self::$block_to_render['attrs'];
|
||||
$block_type = WP_Block_Type_Registry::get_instance()->get_registered(
|
||||
$parsed_block['blockName']
|
||||
self::$block_to_render['blockName']
|
||||
);
|
||||
|
||||
// If no render_callback, assume styles have been previously handled.
|
||||
|
@ -155,15 +160,12 @@ class WP_Block_Supports {
|
|||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @global array $current_parsed_block Block currently being parsed.
|
||||
*
|
||||
* @param array $extra_attributes Optional. Extra attributes to render on the block wrapper.
|
||||
*
|
||||
* @return string String of HTML classes.
|
||||
*/
|
||||
function get_block_wrapper_attributes( $extra_attributes = array() ) {
|
||||
global $current_parsed_block;
|
||||
$new_attributes = WP_Block_Supports::get_instance()->apply_block_supports( $current_parsed_block );
|
||||
$new_attributes = WP_Block_Supports::get_instance()->apply_block_supports();
|
||||
|
||||
if ( empty( $new_attributes ) && empty( $extra_attributes ) ) {
|
||||
return '';
|
||||
|
@ -208,4 +210,3 @@ function get_block_wrapper_attributes( $extra_attributes = array() ) {
|
|||
|
||||
return implode( ' ', $normalized_attributes );
|
||||
}
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ class WP_Block {
|
|||
* @return string Rendered block output.
|
||||
*/
|
||||
public function render( $options = array() ) {
|
||||
global $post, $current_parsed_block;
|
||||
global $post;
|
||||
$options = wp_parse_args(
|
||||
$options,
|
||||
array(
|
||||
|
@ -206,20 +206,18 @@ class WP_Block {
|
|||
if ( ! $options['dynamic'] || empty( $this->block_type->skip_inner_blocks ) ) {
|
||||
$index = 0;
|
||||
foreach ( $this->inner_content as $chunk ) {
|
||||
if ( is_string( $chunk ) ) {
|
||||
$block_content .= $chunk;
|
||||
} else {
|
||||
$parent_parsed_block = $current_parsed_block;
|
||||
$current_parsed_block = $this->inner_blocks[ $index ]->parsed_block;
|
||||
$block_content .= $this->inner_blocks[ $index++ ]->render();
|
||||
$current_parsed_block = $parent_parsed_block;
|
||||
}
|
||||
$block_content .= is_string( $chunk ) ?
|
||||
$chunk :
|
||||
$this->inner_blocks[ $index++ ]->render();
|
||||
}
|
||||
}
|
||||
|
||||
if ( $is_dynamic ) {
|
||||
$global_post = $post;
|
||||
$parent = WP_Block_Supports::$block_to_render;
|
||||
WP_Block_Supports::$block_to_render = $this->parsed_block;
|
||||
$block_content = (string) call_user_func( $this->block_type->render_callback, $this->attributes, $block_content, $this );
|
||||
WP_Block_Supports::$block_to_render = $parent;
|
||||
$post = $global_post;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.6-beta1-49309';
|
||||
$wp_version = '5.6-beta1-49310';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue