From b5b25e954fd4f89a67321b99d7c6d8851050abd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:07:26 +0200 Subject: [PATCH 01/37] Try pass get_block_wrapper_attributes the data it needs --- lib/class-wp-block-supports.php | 90 +++++++++++++++++++ .../block-library/src/social-link/index.php | 6 +- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-block-supports.php b/lib/class-wp-block-supports.php index 8a65dc74640749..ccdc7305424a55 100644 --- a/lib/class-wp-block-supports.php +++ b/lib/class-wp-block-supports.php @@ -81,6 +81,39 @@ public function apply_block_supports( $parsed_block ) { return array(); } + $output = array(); + foreach ( $this->block_supports as $name => $block_support_config ) { + if ( ! isset( $block_support_config['apply'] ) ) { + continue; + } + + $new_attributes = call_user_func( + $block_support_config['apply'], + $block_type, + $block_attributes + ); + + if ( ! empty( $new_attributes ) ) { + foreach ( $new_attributes as $attribute_name => $attribute_value ) { + if ( empty( $output[ $attribute_name ] ) ) { + $output[ $attribute_name ] = $attribute_value; + } else { + $output[ $attribute_name ] .= " $attribute_value"; + } + } + } + } + return $output; + } + + public function apply_block_supports_without_global( $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 ) ) { + return array(); + } + $output = array(); foreach ( $this->block_supports as $name => $block_support_config ) { if ( ! isset( $block_support_config['apply'] ) ) { @@ -144,6 +177,7 @@ private function register_attributes() { * @return string String of HTML classes. */ function get_block_wrapper_attributes( $extra_attributes = array() ) { + error_log( 'WITH' ); global $current_parsed_block; $new_attributes = WP_Block_Supports::get_instance()->apply_block_supports( $current_parsed_block ); @@ -191,4 +225,60 @@ function get_block_wrapper_attributes( $extra_attributes = array() ) { return implode( ' ', $normalized_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. + * + * @return string String of HTML classes. + */ +function get_block_wrapper_attributes_without_global( $block_name, $block_attributes, $extra_attributes = array() ) { + error_log( 'WITHOUT' ); + $new_attributes = WP_Block_Supports::get_instance()->apply_block_supports_without_global( $block_name, $block_attributes ); + + if ( empty( $new_attributes ) && empty( $extra_attributes ) ) { + return ''; + } + + // This is hardcoded on purpose. + // We only support a fixed list of attributes. + $attributes_to_merge = array( 'style', 'class' ); + $attributes = array(); + foreach ( $attributes_to_merge as $attribute_name ) { + if ( empty( $new_attributes[ $attribute_name ] ) && empty( $extra_attributes[ $attribute_name ] ) ) { + continue; + } + + if ( empty( $new_attributes[ $attribute_name ] ) ) { + $attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ]; + continue; + } + + if ( empty( $extra_attributes[ $attribute_name ] ) ) { + $attributes[ $attribute_name ] = $new_attributes[ $attribute_name ]; + continue; + } + + $attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ] . ' ' . $new_attributes[ $attribute_name ]; + } + + foreach ( $extra_attributes as $attribute_name => $value ) { + if ( ! in_array( $attribute_name, $attributes_to_merge, true ) ) { + $attributes[ $attribute_name ] = $value; + } + } + + if ( empty( $attributes ) ) { + return ''; + } + + $normalized_attributes = array(); + foreach ( $attributes as $key => $value ) { + $normalized_attributes[] = $key . '="' . esc_attr( $value ) . '"'; + } + + return implode( ' ', $normalized_attributes ); +} + add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 ); diff --git a/packages/block-library/src/social-link/index.php b/packages/block-library/src/social-link/index.php index f2320da312fc51..99fea8c46d114f 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_without_global( + $block->name, + $attributes, + array( 'class' => 'wp-social-link wp-social-link-' . $service . $class_name ) + ); return '
  • ' . $icon . '
  • '; } From c5a7c89ecf002cb048d921203855239da84d8b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:17:53 +0200 Subject: [PATCH 02/37] Update get_block_wrapper_attributes to get the data it needs as params --- lib/class-wp-block-supports.php | 107 +++----------------------------- 1 file changed, 8 insertions(+), 99 deletions(-) diff --git a/lib/class-wp-block-supports.php b/lib/class-wp-block-supports.php index ccdc7305424a55..031312a45fd8e4 100644 --- a/lib/class-wp-block-supports.php +++ b/lib/class-wp-block-supports.php @@ -67,46 +67,11 @@ 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'] - ); - - // If no render_callback, assume styles have been previously handled. - if ( ! $block_type || empty( $block_type ) ) { - return array(); - } - - $output = array(); - foreach ( $this->block_supports as $name => $block_support_config ) { - if ( ! isset( $block_support_config['apply'] ) ) { - continue; - } - - $new_attributes = call_user_func( - $block_support_config['apply'], - $block_type, - $block_attributes - ); - - if ( ! empty( $new_attributes ) ) { - foreach ( $new_attributes as $attribute_name => $attribute_value ) { - if ( empty( $output[ $attribute_name ] ) ) { - $output[ $attribute_name ] = $attribute_value; - } else { - $output[ $attribute_name ] .= " $attribute_value"; - } - } - } - } - return $output; - } - - public function apply_block_supports_without_global( $block_name, $block_attributes ) { + 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. @@ -172,70 +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. - * - * @return string String of HTML classes. - */ -function get_block_wrapper_attributes( $extra_attributes = array() ) { - error_log( 'WITH' ); - global $current_parsed_block; - $new_attributes = WP_Block_Supports::get_instance()->apply_block_supports( $current_parsed_block ); - - if ( empty( $new_attributes ) && empty( $extra_attributes ) ) { - return ''; - } - - // This is hardcoded on purpose. - // We only support a fixed list of attributes. - $attributes_to_merge = array( 'style', 'class' ); - $attributes = array(); - foreach ( $attributes_to_merge as $attribute_name ) { - if ( empty( $new_attributes[ $attribute_name ] ) && empty( $extra_attributes[ $attribute_name ] ) ) { - continue; - } - - if ( empty( $new_attributes[ $attribute_name ] ) ) { - $attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ]; - continue; - } - - if ( empty( $extra_attributes[ $attribute_name ] ) ) { - $attributes[ $attribute_name ] = $new_attributes[ $attribute_name ]; - continue; - } - - $attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ] . ' ' . $new_attributes[ $attribute_name ]; - } - - foreach ( $extra_attributes as $attribute_name => $value ) { - if ( ! in_array( $attribute_name, $attributes_to_merge, true ) ) { - $attributes[ $attribute_name ] = $value; - } - } - - if ( empty( $attributes ) ) { - return ''; - } - - $normalized_attributes = array(); - foreach ( $attributes as $key => $value ) { - $normalized_attributes[] = $key . '="' . esc_attr( $value ) . '"'; - } - - return implode( ' ', $normalized_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_without_global( $block_name, $block_attributes, $extra_attributes = array() ) { - error_log( 'WITHOUT' ); - $new_attributes = WP_Block_Supports::get_instance()->apply_block_supports_without_global( $block_name, $block_attributes ); +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 ''; From 93f5244bb6ca32c8a2ef84b9f296f051b511ae68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:18:43 +0200 Subject: [PATCH 03/37] Social Link: update get_block_wrapper_attributes --- packages/block-library/src/social-link/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/social-link/index.php b/packages/block-library/src/social-link/index.php index 99fea8c46d114f..6951e3f442da8c 100644 --- a/packages/block-library/src/social-link/index.php +++ b/packages/block-library/src/social-link/index.php @@ -33,7 +33,7 @@ function render_block_core_social_link( $attributes, $content, $block ) { } $icon = block_core_social_link_get_icon( $service ); - $wrapper_attributes = get_block_wrapper_attributes_without_global( + $wrapper_attributes = get_block_wrapper_attributes( $block->name, $attributes, array( 'class' => 'wp-social-link wp-social-link-' . $service . $class_name ) From 3f36a0238d396ab10d34ad869ad86a8d0e3da0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:19:54 +0200 Subject: [PATCH 04/37] Archives: update get_block_wrapper_attributes --- packages/block-library/src/archives/index.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/archives/index.php b/packages/block-library/src/archives/index.php index 04e7e4957cb3a8..fc2aeff75cdac5 100644 --- a/packages/block-library/src/archives/index.php +++ b/packages/block-library/src/archives/index.php @@ -14,7 +14,7 @@ * * @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 +97,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( '
      %2$s
    ', From cb00551a2737193214fba4e1e17ef7d2b687b183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:20:29 +0200 Subject: [PATCH 05/37] Calendar: update get_block_wrapper_attributes --- packages/block-library/src/calendar/index.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index 6e0c52886adda8..8ae37978c2d70a 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -12,7 +12,7 @@ * * @return string Returns the block content. */ -function render_block_core_calendar( $attributes ) { +function render_block_core_calendar( $attributes, $content, $block ) { global $monthnum, $year; $previous_monthnum = $monthnum; @@ -31,7 +31,10 @@ function render_block_core_calendar( $attributes ) { } } - $wrapper_attributes = get_block_wrapper_attributes(); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes + ); $output = sprintf( '
    %2$s
    ', $wrapper_attributes, From 5d4e745fc7a2f1b4d2f5d04e42fbc0603b619f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:21:11 +0200 Subject: [PATCH 06/37] Categories: update get_block_wrapper_attributes --- packages/block-library/src/categories/index.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/categories/index.php b/packages/block-library/src/categories/index.php index c820b7bd76b578..ca33148335f3f4 100644 --- a/packages/block-library/src/categories/index.php +++ b/packages/block-library/src/categories/index.php @@ -12,7 +12,7 @@ * * @return string Returns the categories list/dropdown markup. */ -function render_block_core_categories( $attributes ) { +function render_block_core_categories( $attributes, $content, $block ) { static $block_id = 0; $block_id++; @@ -47,7 +47,11 @@ function render_block_core_categories( $attributes ) { $type = 'list'; } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => "wp-block-categories-{$type}" ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => "wp-block-categories-{$type}" ) + ); return sprintf( $wrapper_markup, From 071c525290b0bafe6323e14b17063900cc2b8c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:22:26 +0200 Subject: [PATCH 07/37] Latest comments: update get_block_wrapper_attributes --- packages/block-library/src/latest-comments/index.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/latest-comments/index.php b/packages/block-library/src/latest-comments/index.php index 555a125c4aa2ba..3a80d254064a0a 100644 --- a/packages/block-library/src/latest-comments/index.php +++ b/packages/block-library/src/latest-comments/index.php @@ -36,11 +36,13 @@ function wp_latest_comments_draft_or_post_title( $post = 0 ) { /** * Renders the `core/latest-comments` block on server. * - * @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 latest comments added. */ -function render_block_core_latest_comments( $attributes = array() ) { +function render_block_core_latest_comments( $attributes = array(), $content, $block ) { // This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php. $comments = get_comments( apply_filters( @@ -129,7 +131,11 @@ function render_block_core_latest_comments( $attributes = array() ) { if ( empty( $comments ) ) { $classnames[] = 'no-comments'; } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => implode( ' ', $classnames ) ) + ); return ! empty( $comments ) ? sprintf( '
      %2$s
    ', From 822dfaeafebfa53e63eb901902d7683f36eb9bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:22:59 +0200 Subject: [PATCH 08/37] Archives: fix phpdoc --- packages/block-library/src/archives/index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/archives/index.php b/packages/block-library/src/archives/index.php index fc2aeff75cdac5..4f241b7cd7bd57 100644 --- a/packages/block-library/src/archives/index.php +++ b/packages/block-library/src/archives/index.php @@ -10,7 +10,9 @@ * * @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. */ From 304b71782ef46e0759238aad0027d3bce09d4aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:23:26 +0200 Subject: [PATCH 09/37] Calendar: fix phpdoc --- packages/block-library/src/calendar/index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index 8ae37978c2d70a..f32b0df6ffb732 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -8,7 +8,9 @@ /** * Renders the `core/calendar` block on server. * - * @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 block content. */ From 47a9c193361696e55603bfc418c23e285785e2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:23:54 +0200 Subject: [PATCH 10/37] Categories: fix phpdoc --- packages/block-library/src/categories/index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/categories/index.php b/packages/block-library/src/categories/index.php index ca33148335f3f4..d5e9316e562993 100644 --- a/packages/block-library/src/categories/index.php +++ b/packages/block-library/src/categories/index.php @@ -8,7 +8,9 @@ /** * Renders the `core/categories` block on server. * - * @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 categories list/dropdown markup. */ From ec4473708efd449d3e239f9b35a5f395be3e68d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:24:56 +0200 Subject: [PATCH 11/37] Latest Posts: update get_block_wrapper_attributes --- packages/block-library/src/latest-posts/index.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/latest-posts/index.php b/packages/block-library/src/latest-posts/index.php index a43646edd72ce2..66660bce1df892 100644 --- a/packages/block-library/src/latest-posts/index.php +++ b/packages/block-library/src/latest-posts/index.php @@ -28,11 +28,13 @@ function block_core_latest_posts_get_excerpt_length() { /** * Renders the `core/latest-posts` block on server. * - * @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 latest posts added. */ -function render_block_core_latest_posts( $attributes ) { +function render_block_core_latest_posts( $attributes, $content, $block ) { global $post, $block_core_latest_posts_excerpt_length; $args = array( @@ -171,7 +173,11 @@ function render_block_core_latest_posts( $attributes ) { $class .= ' has-author'; } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $class ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => $class ) + ); return sprintf( '
      %2$s
    ', From 9dd7e5afbea9e32fbce7eab5c05a30410b7306d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:26:30 +0200 Subject: [PATCH 12/37] Navigation: update get_block_wrapper_attributes --- packages/block-library/src/navigation/index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index b56ea6023be975..ae0c601cda66d1 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -99,7 +99,7 @@ function block_core_navigation_render_submenu_icon() { * * @param array $attributes The block attributes. * @param array $content The saved content. - * @param array $block The parsed block. + * @param WPBlock $block The parsed block. * * @return string Returns the post content with the legacy widget added. */ @@ -140,6 +140,8 @@ function render_block_core_navigation( $attributes, $content, $block ) { } $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, array( 'class' => implode( ' ', $classes ), 'style' => $colors['inline_styles'] . $font_sizes['inline_styles'], From c973dc17ef29d5f23c3762937f257232b47f4c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:27:22 +0200 Subject: [PATCH 13/37] NavigationLink: update get_block_wrapper_attributes --- packages/block-library/src/navigation-link/index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index 57c4b3354fc099..a996a8ff7c3d6b 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -99,7 +99,7 @@ function block_core_navigation_link_render_submenu_icon() { * * @param array $attributes The block attributes. * @param array $content The saved content. - * @param array $block The parsed block. + * @param WPBlock $block The parsed block. * * @return string Returns the post content with the legacy widget added. */ @@ -128,6 +128,8 @@ function render_block_core_navigation_link( $attributes, $content, $block ) { }; $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, array( 'class' => $css_classes . ( $has_submenu ? ' has-child' : '' ) . ( $is_active ? ' current-menu-item' : '' ), From 53811ab88ccdee9e6af7437c933d994c413aac67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:37:09 +0200 Subject: [PATCH 14/37] PostAuthor: update get_block_wrapper_attributes --- packages/block-library/src/post-author/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-author/index.php b/packages/block-library/src/post-author/index.php index e31be65f709942..75e8d5c990f280 100644 --- a/packages/block-library/src/post-author/index.php +++ b/packages/block-library/src/post-author/index.php @@ -35,7 +35,11 @@ function render_block_core_post_author( $attributes, $content, $block ) { isset( $attributes['textAlign'] ) ? array( 'has-text-align-' . $attributes['textAlign'] ) : array() ); - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => implode( ' ', $classes ) ) + ); return sprintf( '
    ', $wrapper_attributes ) . ( ! empty( $attributes['showAvatar'] ) ? '' : '' ) . From 150f570a58788fa0828c9af6640266882f2b265c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:37:44 +0200 Subject: [PATCH 15/37] PostCommentAuthor: update get_block_wrapper_attributes --- packages/block-library/src/post-comment-author/index.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comment-author/index.php b/packages/block-library/src/post-comment-author/index.php index 9cad587d3d447c..ccc63b60ad1f28 100644 --- a/packages/block-library/src/post-comment-author/index.php +++ b/packages/block-library/src/post-comment-author/index.php @@ -18,7 +18,10 @@ function render_block_core_post_comment_author( $attributes, $content, $block ) return ''; } - $wrapper_attributes = get_block_wrapper_attributes(); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes + ); return sprintf( '
    %2$s
    ', From b39488bef13d32d70e8d9a37bf0e5c6b5b82e799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:38:19 +0200 Subject: [PATCH 16/37] PostCommentContent: update get_block_wrapper_attributes --- packages/block-library/src/post-comment-content/index.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comment-content/index.php b/packages/block-library/src/post-comment-content/index.php index 0670fb0af15da3..e0f6f5d044ac7b 100644 --- a/packages/block-library/src/post-comment-content/index.php +++ b/packages/block-library/src/post-comment-content/index.php @@ -17,7 +17,10 @@ function render_block_core_post_comment_content( $attributes, $content, $block ) if ( ! isset( $block->context['commentId'] ) ) { return ''; } - $wrapper_attributes = get_block_wrapper_attributes(); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes + ); return sprintf( '
    %2$s
    ', $wrapper_attributes, From 24ec6be34a53500bb36995f1c955d70497290e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:39:21 +0200 Subject: [PATCH 17/37] PostCommentDate: update get_block_wrapper_attributes --- packages/block-library/src/post-comment-date/index.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comment-date/index.php b/packages/block-library/src/post-comment-date/index.php index f46529b55e295c..af80a86af1bc10 100644 --- a/packages/block-library/src/post-comment-date/index.php +++ b/packages/block-library/src/post-comment-date/index.php @@ -18,7 +18,10 @@ function render_block_core_post_comment_date( $attributes, $content, $block ) { return ''; } - $wrapper_attributes = get_block_wrapper_attributes(); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes + ); return sprintf( '
    ', $wrapper_attributes, From 2384492a0fe05e7543325385b6ada48be97081d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:39:49 +0200 Subject: [PATCH 18/37] PostComments: update get_block_wrapper_attributes --- packages/block-library/src/post-comments/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comments/index.php b/packages/block-library/src/post-comments/index.php index d9629c32f0e6f4..621fb741eb7160 100644 --- a/packages/block-library/src/post-comments/index.php +++ b/packages/block-library/src/post-comments/index.php @@ -36,7 +36,11 @@ function render_block_core_post_comments( $attributes, $content, $block ) { $classes .= 'has-text-align-' . $attributes['textAlign']; } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => $classes ) + ); $output = sprintf( '
    ', $wrapper_attributes ) . ob_get_clean() . '
    '; return $output; } From a85117dcfd89851f83a1ad76b591398adeaa3766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:41:54 +0200 Subject: [PATCH 19/37] PostCommentsCount: update get_block_wrapper_attributes --- packages/block-library/src/post-comments-count/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comments-count/index.php b/packages/block-library/src/post-comments-count/index.php index 86430a41d53493..1e04654bdef40d 100644 --- a/packages/block-library/src/post-comments-count/index.php +++ b/packages/block-library/src/post-comments-count/index.php @@ -23,7 +23,11 @@ function render_block_core_post_comments_count( $attributes, $content, $block ) $classes .= 'has-text-align-' . $attributes['textAlign']; } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => $classes ) + ); return sprintf( '
    %2$s
    ', $wrapper_attributes, From 7cab217e64755d2a8e5d84e142988587ab36289b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:42:25 +0200 Subject: [PATCH 20/37] PostCommentsForm: update get_block_wrapper_attributes --- packages/block-library/src/post-comments-form/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comments-form/index.php b/packages/block-library/src/post-comments-form/index.php index 0474bdce1b722c..f456821002eec8 100644 --- a/packages/block-library/src/post-comments-form/index.php +++ b/packages/block-library/src/post-comments-form/index.php @@ -26,7 +26,11 @@ function render_block_core_post_comments_form( $attributes, $content, $block ) { ob_start(); comment_form( array(), $block->context['postId'] ); $form = ob_get_clean(); - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => $classes ) + ); return sprintf( '
    %2$s
    ', $wrapper_attributes, $form ); } From 51661afd0fa4b27f321f0a4b967226b1a3932cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:42:49 +0200 Subject: [PATCH 21/37] PostContent: update get_block_wrapper_attributes --- packages/block-library/src/post-content/index.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-content/index.php b/packages/block-library/src/post-content/index.php index 7ee8b4dd1b7055..2b4c1f15d85d78 100644 --- a/packages/block-library/src/post-content/index.php +++ b/packages/block-library/src/post-content/index.php @@ -18,7 +18,10 @@ function render_block_core_post_content( $attributes, $content, $block ) { return ''; } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => 'entry-content' ) ); return ( '
    ' . From 3d3b33dd7637c99b07530a3aeab53b72d13e204e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:43:37 +0200 Subject: [PATCH 22/37] PostDate: update get_block_wrapper_attributes --- packages/block-library/src/post-date/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-date/index.php b/packages/block-library/src/post-date/index.php index 940820b504692f..fe7e7bb4fde3b4 100644 --- a/packages/block-library/src/post-date/index.php +++ b/packages/block-library/src/post-date/index.php @@ -19,7 +19,11 @@ function render_block_core_post_date( $attributes, $content, $block ) { } $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; - $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( '
    ', From 300acd5f5651283704d66a1e060e76b04adcbab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:44:06 +0200 Subject: [PATCH 23/37] PostExcerpt: update get_block_wrapper_attributes --- packages/block-library/src/post-excerpt/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-excerpt/index.php b/packages/block-library/src/post-excerpt/index.php index a6a4c641dc0103..bec5d2c0eb3433 100644 --- a/packages/block-library/src/post-excerpt/index.php +++ b/packages/block-library/src/post-excerpt/index.php @@ -32,7 +32,11 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) { if ( isset( $attributes['textAlign'] ) ) { $classes .= 'has-text-align-' . $attributes['textAlign']; } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => $classes ) + ); $output = sprintf( '
    ', esc_attr( $wrapper_attributes ) ) . '

    ' . get_the_excerpt( $block->context['postId'] ); if ( ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'] ) { From 263e81937fec90e570bef878ca0d4a5b864f5c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:44:33 +0200 Subject: [PATCH 24/37] PostFeaturedImage: update get_block_wrapper_attributes --- packages/block-library/src/post-featured-image/index.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 . '

    '; } From 859a883420a1d1275f4d2f64d9136a702163d3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:45:04 +0200 Subject: [PATCH 25/37] PostHierarchicalTerms: update get_block_wrapper_attributes --- .../block-library/src/post-hierarchical-terms/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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
    ', From b4b010c1f0303a522964399450bbfa8b4cd5b208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:45:31 +0200 Subject: [PATCH 26/37] PostTags: update get_block_wrapper_attributes --- packages/block-library/src/post-tags/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-tags/index.php b/packages/block-library/src/post-tags/index.php index dd703074088229..0b929a6f1d15c9 100644 --- a/packages/block-library/src/post-tags/index.php +++ b/packages/block-library/src/post-tags/index.php @@ -25,7 +25,11 @@ function render_block_core_post_tags( $attributes, $content, $block ) { $classes .= 'has-text-align-' . $attributes['textAlign']; } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => $classes ) + ); $output = sprintf( '
    ', $wrapper_attributes ); foreach ( $post_tags as $tag ) { From f57c461bff26809e30768ddfe84a6385271913e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:46:00 +0200 Subject: [PATCH 27/37] PostTitle: update get_block_wrapper_attributes --- packages/block-library/src/post-title/index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-title/index.php b/packages/block-library/src/post-title/index.php index 798278b5567af5..50851cf44e1037 100644 --- a/packages/block-library/src/post-title/index.php +++ b/packages/block-library/src/post-title/index.php @@ -31,7 +31,11 @@ function render_block_core_post_title( $attributes, $content, $block ) { if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) { $title = sprintf( '%4s', get_the_permalink( $post_ID ), $attributes['linkTarget'], $attributes['rel'], $title ); } - $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', From 7cb972ce6cac78c3ff42c26dc8f7c0c7923c1c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:47:14 +0200 Subject: [PATCH 28/37] RSS: update get_block_wrapper_attributes --- packages/block-library/src/rss/index.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/rss/index.php b/packages/block-library/src/rss/index.php index b0a31bf2bbd6d0..8f37b622215651 100644 --- a/packages/block-library/src/rss/index.php +++ b/packages/block-library/src/rss/index.php @@ -8,11 +8,13 @@ /** * Renders the `core/rss` block on 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 Returns the block content with received rss items. */ -function render_block_core_rss( $attributes ) { +function render_block_core_rss( $attributes, $content, $block ) { $rss = fetch_feed( $attributes['feedURL'] ); if ( is_wp_error( $rss ) ) { @@ -87,7 +89,11 @@ function render_block_core_rss( $attributes ) { if ( isset( $attributes['columns'] ) && 'grid' === $attributes['blockLayout'] ) { $classnames[] = 'columns-' . $attributes['columns']; } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => implode( ' ', $classnames ) ) + ); return sprintf( '
      %s
    ', $wrapper_attributes, $list_items ); } From 2a2723ac6edc20a89b55057988ff4584e23e8343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:48:02 +0200 Subject: [PATCH 29/37] Search: update get_block_wrapper_attributes --- packages/block-library/src/search/index.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index 36607188ff44a3..de3b810c86b28f 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -8,11 +8,13 @@ /** * Dynamically renders the `core/search` block. * - * @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 search block markup. */ -function render_block_core_search( $attributes ) { +function render_block_core_search( $attributes, $content, $block ) { static $instance_id = 0; // Older versions of the Search block defaulted the label and buttonText @@ -96,7 +98,11 @@ function render_block_core_search( $attributes ) { $width_styles, $input_markup . $button_markup ); - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => $classnames ) + ); return sprintf( '
    %s
    ', From c6bee5383a3d85239e032c807364693a7a5b684f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 12:48:41 +0200 Subject: [PATCH 30/37] SiteLogo: update get_block_wrapper_attributes --- packages/block-library/src/site-logo/index.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/site-logo/index.php b/packages/block-library/src/site-logo/index.php index efadd3ce16c61f..14570bda44a2ba 100644 --- a/packages/block-library/src/site-logo/index.php +++ b/packages/block-library/src/site-logo/index.php @@ -8,11 +8,13 @@ /** * Renders the `core/site-logo` 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_logo( $attributes ) { +function render_block_core_site_logo( $attributes, $content, $block ) { $adjust_width_height_filter = function ( $image ) use ( $attributes ) { if ( empty( $attributes['width'] ) ) { return $image; @@ -32,7 +34,11 @@ function render_block_core_site_logo( $attributes ) { $classnames[] = "align{$attributes['align']}"; } - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) ); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes, + array( 'class' => implode( ' ', $classnames ) ) + ); $html = sprintf( '', $wrapper_attributes, $custom_logo ); remove_filter( 'wp_get_attachment_image_src', $adjust_width_height_filter ); return $html; From ae31f08f0af0ae43f37ff3d6fd5a911a40abc6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 13:15:55 +0200 Subject: [PATCH 31/37] SiteTagline: update get_block_wrapper_attributes --- packages/block-library/src/site-tagline/index.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/site-tagline/index.php b/packages/block-library/src/site-tagline/index.php index e248d51011e761..4513c7d0461bac 100644 --- a/packages/block-library/src/site-tagline/index.php +++ b/packages/block-library/src/site-tagline/index.php @@ -8,13 +8,19 @@ /** * Renders the `core/site-tagline` 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_tagline( $attributes ) { +function render_block_core_site_tagline( $attributes, $content, $block ) { $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; - $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

    ', From 9fcea122316166bfd8d9c249027f828bfdf8722b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 13:16:39 +0200 Subject: [PATCH 32/37] SiteTitle: update get_block_wrapper_attributes --- packages/block-library/src/site-title/index.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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', From fe490b2867134dac0ff02a5a1ff5ee337b5fbe49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 13:17:22 +0200 Subject: [PATCH 33/37] TagClound: update get_block_wrapper_attributes --- packages/block-library/src/tag-cloud/index.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php index cdebc9227138a4..3c62f3722369f1 100644 --- a/packages/block-library/src/tag-cloud/index.php +++ b/packages/block-library/src/tag-cloud/index.php @@ -8,11 +8,13 @@ /** * Renders the `core/tag-cloud` block on 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 Returns the tag cloud for selected taxonomy. */ -function render_block_core_tag_cloud( $attributes ) { +function render_block_core_tag_cloud( $attributes, $content, $block ) { $args = array( 'echo' => false, 'taxonomy' => $attributes['taxonomy'], @@ -31,7 +33,10 @@ function render_block_core_tag_cloud( $attributes ) { ); } - $wrapper_attributes = get_block_wrapper_attributes(); + $wrapper_attributes = get_block_wrapper_attributes( + $block->name, + $attributes + ); return sprintf( '

    %2$s

    ', From d088f1bc9ea1524ecf2c81589df30c255743a0eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 13:17:59 +0200 Subject: [PATCH 34/37] TemplatePart: update get_block_wrapper_attributes --- packages/block-library/src/template-part/index.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 ) . ""; } From ae1e288cc62d1c1c968816ed89cf1c2c8c7e23fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 13:19:14 +0200 Subject: [PATCH 35/37] Update test --- phpunit/class-block-supported-styles-test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpunit/class-block-supported-styles-test.php b/phpunit/class-block-supported-styles-test.php index 19765f6a2b6611..2ffa9dff45783c 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( + $block->name, + $block->attributes, array( 'class' => 'foo-bar-class', 'style' => 'test: style;', From f11475b222068ca361d321082ab36e13cdbd8458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 13:22:50 +0200 Subject: [PATCH 36/37] Remove current_parsed_block global --- lib/class-wp-block.php | 12 +++--------- lib/compat.php | 10 ---------- 2 files changed, 3 insertions(+), 19 deletions(-) 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 */ From bc31f228c1e206c94934b8038580a8c345849603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 20 Oct 2020 13:50:18 +0200 Subject: [PATCH 37/37] Make linter happy --- packages/block-library/src/navigation-link/index.php | 4 ++-- packages/block-library/src/navigation/index.php | 4 ++-- packages/block-library/src/post-content/index.php | 3 ++- phpunit/class-block-supported-styles-test.php | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index a996a8ff7c3d6b..13a1b5ce152d0e 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -97,8 +97,8 @@ function block_core_navigation_link_render_submenu_icon() { /** * Renders the `core/navigation-link` block. * - * @param array $attributes The block attributes. - * @param array $content The saved content. + * @param array $attributes The block attributes. + * @param array $content The saved content. * @param WPBlock $block The parsed block. * * @return string Returns the post content with the legacy widget added. diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index ae0c601cda66d1..5eebde706a8624 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -97,8 +97,8 @@ function block_core_navigation_render_submenu_icon() { /** * Renders the `core/navigation` block on server. * - * @param array $attributes The block attributes. - * @param array $content The saved content. + * @param array $attributes The block attributes. + * @param array $content The saved content. * @param WPBlock $block The parsed block. * * @return string Returns the post content with the legacy widget added. diff --git a/packages/block-library/src/post-content/index.php b/packages/block-library/src/post-content/index.php index 2b4c1f15d85d78..1464ed25662dfe 100644 --- a/packages/block-library/src/post-content/index.php +++ b/packages/block-library/src/post-content/index.php @@ -21,7 +21,8 @@ function render_block_core_post_content( $attributes, $content, $block ) { $wrapper_attributes = get_block_wrapper_attributes( $block->name, $attributes, - array( 'class' => 'entry-content' ) ); + array( 'class' => 'entry-content' ) + ); return ( '
    ' . diff --git a/phpunit/class-block-supported-styles-test.php b/phpunit/class-block-supported-styles-test.php index 2ffa9dff45783c..7bca908b8ebd38 100644 --- a/phpunit/class-block-supported-styles-test.php +++ b/phpunit/class-block-supported-styles-test.php @@ -97,7 +97,7 @@ private function get_content_from_block( $block ) { * @param WPBlock $block Block to render. */ private function render_example_block( $block ) { - $wrapper_attributes = get_block_wrapper_attributes( + $wrapper_attributes = get_block_wrapper_attributes( $block->name, $block->attributes, array(