Make WordPress Core


Ignore:
Timestamp:
10/26/2020 08:29:04 AM (5 years ago)
Author:
youknowriad
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-supports.php

    r49226 r49310  
    2323     */
    2424    private $block_supports = array();
     25
     26    /**
     27     * Tracks the current block to be rendered.
     28     *
     29     * @var array
     30     */
     31    public static $block_to_render = null;
    2532
    2633    /**
     
    7380    }
    7481
    75 
    7682    /**
    7783     * Generates an array of HTML attributes, such as classes, by applying to
     
    8086     * @since 5.6.0
    8187     *
    82      * @param  array $parsed_block Block as parsed from content.
    8388     * @return array               Array of HTML attributes.
    8489     */
    85     public function apply_block_supports( $parsed_block ) {
    86         $block_attributes = $parsed_block['attrs'];
     90    public function apply_block_supports() {
     91        $block_attributes = self::$block_to_render['attrs'];
    8792        $block_type       = WP_Block_Type_Registry::get_instance()->get_registered(
    88             $parsed_block['blockName']
     93            self::$block_to_render['blockName']
    8994        );
    9095
     
    156161 * @since 5.6.0
    157162 *
    158  * @global array    $current_parsed_block Block currently being parsed.
    159  *
    160163 * @param array $extra_attributes Optional. Extra attributes to render on the block wrapper.
    161164 *
     
    163166 */
    164167function get_block_wrapper_attributes( $extra_attributes = array() ) {
    165     global $current_parsed_block;
    166     $new_attributes = WP_Block_Supports::get_instance()->apply_block_supports( $current_parsed_block );
     168    $new_attributes = WP_Block_Supports::get_instance()->apply_block_supports();
    167169
    168170    if ( empty( $new_attributes ) && empty( $extra_attributes ) ) {
     
    209211    return implode( ' ', $normalized_attributes );
    210212}
    211 
Note: See TracChangeset for help on using the changeset viewer.