From 222bdade2cb519dcb289a0629e89b402980ab2b8 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:14:41 +1000 Subject: [PATCH 1/6] Fix multiline comments --- lib/block-supports/elements.php | 6 ++---- phpunit/block-supports/elements-test.php | 10 ++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index eefab9ceffbafd..794e52530f1743 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -193,8 +193,8 @@ function gutenberg_render_elements_support_styles( $parsed_block ) { } /** - * Ensure the elements block support class name generated and added to - * block attributes in the `render_block_data` filter gets applied to the + * Ensure the elements block support class name generated, and added to + * block attributes, in the `render_block_data` filter gets applied to the * block's markup. * * @see gutenberg_render_elements_support_styles @@ -215,8 +215,6 @@ function gutenberg_render_elements_class_name( $block_content, $block ) { $tags = new WP_HTML_Tag_Processor( $block_content ); if ( $tags->next_tag() ) { - // Ensure the elements class name set in render_block_data filter is applied in markup. - // See `gutenberg_render_elements_support_styles`. $tags->add_class( $matches[0] ); } diff --git a/phpunit/block-supports/elements-test.php b/phpunit/block-supports/elements-test.php index 827b624dea2414..f7351c0eb26ab3 100644 --- a/phpunit/block-supports/elements-test.php +++ b/phpunit/block-supports/elements-test.php @@ -72,10 +72,12 @@ public function test_elements_block_support_class( $color_settings, $elements_st ), ); - // To ensure a consistent elements class name it is generated within a - // `render_block_data` filter and stored in the `className` attribute. - // As a result the block data needs to be passed through the same - // function for this test. + /* + * To ensure a consistent elements class name it is generated within a + * `render_block_data` filter and stored in the `className` attribute. + * As a result the block data needs to be passed through the same + * function for this test. + */ $filtered_block = gutenberg_render_elements_support_styles( $block ); $actual = gutenberg_render_elements_class_name( $block_markup, $filtered_block ); From 0f9fee1a5d4be18af1e859863f8895bdbe188509 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:51:51 +1000 Subject: [PATCH 2/6] Try adding deprecations to old filter callbacks --- lib/block-supports/elements.php | 41 +++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index 794e52530f1743..e24cd044b6853f 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -5,6 +5,19 @@ * @package gutenberg */ +/** + * Update the block content with elements class names. + * + * @deprecated 6.5.0 Use WP_Duotone_Gutenberg::register_duotone_support() instead. + * + * @param string $block_content Rendered block content. + * @return string Filtered block content. + */ +function gutenberg_render_elements_support( $block_content ) { + _deprecated_function( __FUNCTION__, '6.5.0', 'gutenberg_render_elements_class_name' ); + return $block_content; +} + /** * Determines whether an elements class name should be added to the block. * @@ -86,11 +99,31 @@ function gutenberg_should_add_elements_class_name( $block, $options ) { * This solves the issue of an element (e.g.: link color) being styled in both the parent and a descendant: * we want the descendant style to take priority, and this is done by loading it after, in DOM order. * + * @since 6.5.0 Element block support class and styles are generated via the `render_block_data` filter instead of `pre_render_block` + * * @param array $parsed_block The parsed block. * * @return array The same parsed block with elements classname added if appropriate. */ function gutenberg_render_elements_support_styles( $parsed_block ) { + /* + * The generation of element styles and classname were moved to the + * `render_block_data` filter in 6.5.0 to avoid filtered attributes + * breaking the application of the elements CSS class. + * + * @see https://github.com/WordPress/gutenberg/pull/59535. + * + * The change in filter means, the argument types for this function + * have changed and require deprecating. + */ + if ( is_string( $parsed_block ) ) { + _deprecated_argument( + __FUNCTION__, + '6.5.0', + __( 'Use as a `pre_render_block` filter is deprecated. Use with `render_block_data` instead.' ) + ); + } + $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $parsed_block['blockName'] ); $element_block_styles = $parsed_block['attrs']['style']['elements'] ?? null; @@ -221,9 +254,13 @@ function gutenberg_render_elements_class_name( $block_content, $block ) { return $tags->get_updated_html(); } -// Remove WordPress core filters to avoid rendering duplicate elements stylesheet & attaching classes twice. +// Remove deprecated WordPress core filters. remove_filter( 'render_block', 'wp_render_elements_support', 10, 2 ); remove_filter( 'pre_render_block', 'wp_render_elements_support_styles', 10, 2 ); + +// Remove WordPress core filters to avoid rendering duplicate elements stylesheet & attaching classes twice. remove_filter( 'render_block', 'wp_render_elements_class_name', 10, 2 ); +remove_filter( 'render_block_data', 'wp_render_elements_support_styles', 10, 1 ); + add_filter( 'render_block', 'gutenberg_render_elements_class_name', 10, 2 ); -add_filter( 'render_block_data', 'gutenberg_render_elements_support_styles', 10, 2 ); +add_filter( 'render_block_data', 'gutenberg_render_elements_support_styles', 10, 1 ); From b4cf5f141885aa04b2715ea802657a2d331fe825 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:38:09 +1000 Subject: [PATCH 3/6] Fix typo --- lib/block-supports/elements.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index e24cd044b6853f..48d9ba86ee951b 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -14,7 +14,7 @@ * @return string Filtered block content. */ function gutenberg_render_elements_support( $block_content ) { - _deprecated_function( __FUNCTION__, '6.5.0', 'gutenberg_render_elements_class_name' ); + _deprecated_function( __FUNCTION__, '6.5.0', 'gutenberg_render_elements_support' ); return $block_content; } From 426e09af816c254039ff540aa9fa1275bae363f5 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 14 Mar 2024 15:20:08 +1000 Subject: [PATCH 4/6] Add domain to satisfy linter --- lib/block-supports/elements.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index 48d9ba86ee951b..aa351f6797a0cd 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -120,7 +120,7 @@ function gutenberg_render_elements_support_styles( $parsed_block ) { _deprecated_argument( __FUNCTION__, '6.5.0', - __( 'Use as a `pre_render_block` filter is deprecated. Use with `render_block_data` instead.' ) + __( 'Use as a `pre_render_block` filter is deprecated. Use with `render_block_data` instead.', 'gutenberg' ) ); } From 821ca798f69c6e041d66e8d1992824a4532482cd Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 14 Mar 2024 15:27:33 +1000 Subject: [PATCH 5/6] Correct references to 6.5.0 --- lib/block-supports/elements.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index aa351f6797a0cd..cf1ae56f384446 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -8,13 +8,13 @@ /** * Update the block content with elements class names. * - * @deprecated 6.5.0 Use WP_Duotone_Gutenberg::register_duotone_support() instead. + * @deprecated 6.6.0 Use WP_Duotone_Gutenberg::register_duotone_support() instead. * * @param string $block_content Rendered block content. * @return string Filtered block content. */ function gutenberg_render_elements_support( $block_content ) { - _deprecated_function( __FUNCTION__, '6.5.0', 'gutenberg_render_elements_support' ); + _deprecated_function( __FUNCTION__, '6.6.0', 'gutenberg_render_elements_support' ); return $block_content; } @@ -99,7 +99,7 @@ function gutenberg_should_add_elements_class_name( $block, $options ) { * This solves the issue of an element (e.g.: link color) being styled in both the parent and a descendant: * we want the descendant style to take priority, and this is done by loading it after, in DOM order. * - * @since 6.5.0 Element block support class and styles are generated via the `render_block_data` filter instead of `pre_render_block` + * @since 6.6.0 Element block support class and styles are generated via the `render_block_data` filter instead of `pre_render_block` * * @param array $parsed_block The parsed block. * @@ -108,7 +108,7 @@ function gutenberg_should_add_elements_class_name( $block, $options ) { function gutenberg_render_elements_support_styles( $parsed_block ) { /* * The generation of element styles and classname were moved to the - * `render_block_data` filter in 6.5.0 to avoid filtered attributes + * `render_block_data` filter in 6.6.0 to avoid filtered attributes * breaking the application of the elements CSS class. * * @see https://github.com/WordPress/gutenberg/pull/59535. @@ -119,7 +119,7 @@ function gutenberg_render_elements_support_styles( $parsed_block ) { if ( is_string( $parsed_block ) ) { _deprecated_argument( __FUNCTION__, - '6.5.0', + '6.6.0', __( 'Use as a `pre_render_block` filter is deprecated. Use with `render_block_data` instead.', 'gutenberg' ) ); } From 92ebee547c73bb5f30087787f6e39f379f1a6603 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 22 Apr 2024 09:53:58 +1000 Subject: [PATCH 6/6] Fix deprecation replacement and docblock --- lib/block-supports/elements.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index cf1ae56f384446..35a41270a19800 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -8,13 +8,13 @@ /** * Update the block content with elements class names. * - * @deprecated 6.6.0 Use WP_Duotone_Gutenberg::register_duotone_support() instead. + * @deprecated 6.6.0 Use `gutenberg_render_elements_class_name` instead. * * @param string $block_content Rendered block content. * @return string Filtered block content. */ function gutenberg_render_elements_support( $block_content ) { - _deprecated_function( __FUNCTION__, '6.6.0', 'gutenberg_render_elements_support' ); + _deprecated_function( __FUNCTION__, '6.6.0', 'gutenberg_render_elements_class_name' ); return $block_content; }