diff --git a/lib/class-wp-block-supports.php b/lib/class-wp-block-supports.php index 8a65dc74640749..031312a45fd8e4 100644 --- a/lib/class-wp-block-supports.php +++ b/lib/class-wp-block-supports.php @@ -67,14 +67,12 @@ public function register( $block_support_name, $block_support_config ) { * Generates an array of HTML attributes, such as classes, by applying to * the given block all of the features that the block supports. * - * @param array $parsed_block Block as parsed from content. + * @param string $block_name The name of the block to be processed. + * @param array $block_attributes The attributes of the block to be processed. * @return array Array of HTML attributes. */ - public function apply_block_supports( $parsed_block ) { - $block_attributes = $parsed_block['attrs']; - $block_type = WP_Block_Type_Registry::get_instance()->get_registered( - $parsed_block['blockName'] - ); + public function apply_block_supports( $block_name, $block_attributes ) { + $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name ); // If no render_callback, assume styles have been previously handled. if ( ! $block_type || empty( $block_type ) ) { @@ -139,13 +137,14 @@ private function register_attributes() { * Generates a string of attributes by applying to the current block being * rendered all of the features that the block supports. * - * @param array $extra_attributes Optional. Extra attributes to render on the block wrapper. + * @param string $block_name The name of the block to be processed. + * @param array $block_attributes The attributes of the block to be processed. + * @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 ); +function get_block_wrapper_attributes( $block_name, $block_attributes, $extra_attributes = array() ) { + $new_attributes = WP_Block_Supports::get_instance()->apply_block_supports( $block_name, $block_attributes ); if ( empty( $new_attributes ) && empty( $extra_attributes ) ) { return ''; diff --git a/lib/class-wp-block.php b/lib/class-wp-block.php index d7788c1d614dc5..cd029050745660 100644 --- a/lib/class-wp-block.php +++ b/lib/class-wp-block.php @@ -203,7 +203,6 @@ public function __get( $name ) { */ public function render( $options = array() ) { global $post; - global $current_parsed_block; $options = array_replace( array( 'dynamic' => true, @@ -217,14 +216,9 @@ public function render( $options = array() ) { 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(); } } diff --git a/lib/compat.php b/lib/compat.php index 2c4dfb9033c103..e63a7a5af514ad 100644 --- a/lib/compat.php +++ b/lib/compat.php @@ -366,18 +366,11 @@ function gutenberg_replace_default_block_categories( $default_categories ) { } add_filter( 'block_categories', 'gutenberg_replace_default_block_categories' ); -global $current_parsed_block; -$current_parsed_block = array( - 'blockName' => null, - 'attributes' => null, -); - /** * Shim that hooks into `pre_render_block` so as to override `render_block` with * a function that assigns block context. * * The context handling can be removed when plugin support requires WordPress 5.5.0+. - * The global current_parsed_block assignment can be removed when plugin support requires WordPress 5.6.0+. * * @see https://core.trac.wordpress.org/ticket/49927 * @see https://core.trac.wordpress.org/changeset/48243 @@ -389,7 +382,6 @@ function gutenberg_replace_default_block_categories( $default_categories ) { */ function gutenberg_render_block_with_assigned_block_context( $pre_render, $parsed_block ) { global $post, $wp_query; - global $current_parsed_block; /* * If a non-null value is provided, a filter has run at an earlier priority @@ -399,8 +391,6 @@ function gutenberg_render_block_with_assigned_block_context( $pre_render, $parse return $pre_render; } - $current_parsed_block = $parsed_block; - $source_block = $parsed_block; /** This filter is documented in src/wp-includes/blocks.php */ diff --git a/packages/block-library/src/archives/index.php b/packages/block-library/src/archives/index.php index 04e7e4957cb3a8..4f241b7cd7bd57 100644 --- a/packages/block-library/src/archives/index.php +++ b/packages/block-library/src/archives/index.php @@ -10,11 +10,13 @@ * * @see WP_Widget_Archives * - * @param array $attributes The block attributes. + * @param Array $attributes The block attributes. + * @param String $content InnerBlocks content of the Block. + * @param WPBlock $block Block object. * * @return string Returns the post content with archives added. */ -function render_block_core_archives( $attributes ) { +function render_block_core_archives( $attributes, $content, $block ) { $show_post_count = ! empty( $attributes['showPostCounts'] ); $class = ''; @@ -97,7 +99,11 @@ function render_block_core_archives( $attributes ) { ); } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => $classnames ) + ); return sprintf( '
' . get_the_excerpt( $block->context['postId'] ); if ( ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'] ) { diff --git a/packages/block-library/src/post-featured-image/index.php b/packages/block-library/src/post-featured-image/index.php index 2822fb352f8a73..a06d672cfcb12c 100644 --- a/packages/block-library/src/post-featured-image/index.php +++ b/packages/block-library/src/post-featured-image/index.php @@ -25,7 +25,10 @@ function render_block_core_post_featured_image( $attributes, $content, $block ) $featured_image = sprintf( '%2s', get_the_permalink( $post_ID ), $featured_image ); } - $wrapper_attributes = get_block_wrapper_attributes(); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes + ); return '
' . $featured_image . '
'; } diff --git a/packages/block-library/src/post-hierarchical-terms/index.php b/packages/block-library/src/post-hierarchical-terms/index.php index bf26204b57e654..78a069ca898bd6 100644 --- a/packages/block-library/src/post-hierarchical-terms/index.php +++ b/packages/block-library/src/post-hierarchical-terms/index.php @@ -34,7 +34,11 @@ function render_block_core_post_hierarchical_terms( $attributes, $content, $bloc ); } $terms_links = trim( $terms_links, ' | ' ); - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => $align_class_name ) + ); return sprintf( '%2$s
', diff --git a/packages/block-library/src/site-title/index.php b/packages/block-library/src/site-title/index.php index 6cbd6988f9c102..24f2f33a92336e 100644 --- a/packages/block-library/src/site-title/index.php +++ b/packages/block-library/src/site-title/index.php @@ -8,11 +8,13 @@ /** * Renders the `core/site-title` block on the server. * - * @param array $attributes The block attributes. + * @param array $attributes Block attributes. + * @param string $content Block default content. + * @param WP_Block $block Block instance. * * @return string The render. */ -function render_block_core_site_title( $attributes ) { +function render_block_core_site_title( $attributes, $content, $block ) { $tag_name = 'h1'; $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; @@ -21,7 +23,11 @@ function render_block_core_site_title( $attributes ) { } $link = sprintf( '%2$s', get_bloginfo( 'url' ), get_bloginfo( 'name' ) ); - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => $align_class_name ) + ); return sprintf( '<%1$s %2$s>%3$s%1$s>', diff --git a/packages/block-library/src/social-link/index.php b/packages/block-library/src/social-link/index.php index f2320da312fc51..6951e3f442da8c 100644 --- a/packages/block-library/src/social-link/index.php +++ b/packages/block-library/src/social-link/index.php @@ -33,7 +33,11 @@ function render_block_core_social_link( $attributes, $content, $block ) { } $icon = block_core_social_link_get_icon( $service ); - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'wp-social-link wp-social-link-' . $service . $class_name ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => 'wp-social-link wp-social-link-' . $service . $class_name ) + ); return '%2$s
', diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index 50629eb83534f3..5f37469f5ee011 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -8,11 +8,13 @@ /** * Renders the `core/template-part` block on the server. * - * @param array $attributes The block attributes. + * @param array $attributes Block attributes. + * @param string $content Block default content. + * @param WP_Block $block Block instance. * * @return string The render. */ -function render_block_core_template_part( $attributes ) { +function render_block_core_template_part( $attributes, $content, $block ) { $content = null; if ( ! empty( $attributes['postId'] ) && get_post_status( $attributes['postId'] ) ) { @@ -63,7 +65,10 @@ function render_block_core_template_part( $attributes ) { } $content = do_shortcode( $content ); $html_tag = esc_attr( $attributes['tagName'] ); - $wrapper_attributes = get_block_wrapper_attributes(); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes + ); return "<$html_tag $wrapper_attributes>" . str_replace( ']]>', ']]>', $content ) . "$html_tag>"; } diff --git a/phpunit/class-block-supported-styles-test.php b/phpunit/class-block-supported-styles-test.php index 19765f6a2b6611..7bca908b8ebd38 100644 --- a/phpunit/class-block-supported-styles-test.php +++ b/phpunit/class-block-supported-styles-test.php @@ -94,12 +94,12 @@ private function get_content_from_block( $block ) { /** * Returns the rendered output for the current block. * - * @param array $block Block to render. + * @param WPBlock $block Block to render. */ private function render_example_block( $block ) { - global $current_parsed_block; - $current_parsed_block = $block; - $wrapper_attributes = get_block_wrapper_attributes( + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $block->attributes, array( 'class' => 'foo-bar-class', 'style' => 'test: style;',