From 489ecbd9763c6c96be94e652cfb1ae13a2d6756d Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 18 Sep 2025 15:51:48 +0200 Subject: [PATCH 1/4] Block Bindings: Support image caption attribute --- src/wp-includes/class-wp-block.php | 2 +- tests/phpunit/tests/block-bindings/render.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-block.php b/src/wp-includes/class-wp-block.php index 732e0e347052f..57db98d2ee6cd 100644 --- a/src/wp-includes/class-wp-block.php +++ b/src/wp-includes/class-wp-block.php @@ -109,7 +109,7 @@ class WP_Block { private const BLOCK_BINDINGS_SUPPORTED_ATTRIBUTES = array( 'core/paragraph' => array( 'content' ), 'core/heading' => array( 'content' ), - 'core/image' => array( 'id', 'url', 'title', 'alt' ), + 'core/image' => array( 'id', 'url', 'title', 'alt', 'caption' ), 'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ), 'core/post-date' => array( 'datetime' ), ); diff --git a/tests/phpunit/tests/block-bindings/render.php b/tests/phpunit/tests/block-bindings/render.php index d640e7d5207e4..5e1684c024d92 100644 --- a/tests/phpunit/tests/block-bindings/render.php +++ b/tests/phpunit/tests/block-bindings/render.php @@ -102,6 +102,16 @@ public function data_update_block_with_value_from_source() { , '
test source value
', ), + 'image block' => array( + 'caption', + << +
Breakfast at a café in Wrocław.
+ +HTML + , + '
test source value
' + ), 'test block' => array( 'myAttribute', << Date: Thu, 18 Sep 2025 16:02:30 +0200 Subject: [PATCH 2/4] Carry over test coverage from GB --- tests/phpunit/tests/block-bindings/render.php | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/block-bindings/render.php b/tests/phpunit/tests/block-bindings/render.php index 5e1684c024d92..e701d01a26507 100644 --- a/tests/phpunit/tests/block-bindings/render.php +++ b/tests/phpunit/tests/block-bindings/render.php @@ -292,13 +292,21 @@ public function test_passing_uses_context_to_source() { * Tests if the block content is updated with the value returned by the source * for the Image block in the placeholder state. * + * Furthermore tests if the caption attribute is correctly processed. + * * @ticket 60282 + * @ticket XXXXX * * @covers ::register_block_bindings_source */ public function test_update_block_with_value_from_source_image_placeholder() { - $get_value_callback = function () { - return 'https://example.com/image.jpg'; + $get_value_callback = function ( $source_args, $block_instance, $attribute_name ) { + if ( 'url' === $attribute_name ) { + return 'https://example.com/image.jpg'; + } + if ( 'caption' === $attribute_name ) { + return 'Example Image'; + } }; register_block_bindings_source( @@ -310,8 +318,8 @@ public function test_update_block_with_value_from_source_image_placeholder() { ); $block_content = << -
+ +
HTML; $parsed_blocks = parse_blocks( $block_content ); @@ -324,7 +332,12 @@ public function test_update_block_with_value_from_source_image_placeholder() { "The 'url' attribute should be updated with the value returned by the source." ); $this->assertSame( - '
', + 'Example Image', + $block->attributes['caption'], + "The 'caption' attribute should be updated with the value returned by the source." + ); + $this->assertSame( + '
Example Image
', trim( $result ), 'The block content should be updated with the value returned by the source.' ); From 913de7602c3a6661536da477a6655a21c513fd2f Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 18 Sep 2025 16:02:55 +0200 Subject: [PATCH 3/4] WPCS --- tests/phpunit/tests/block-bindings/render.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/block-bindings/render.php b/tests/phpunit/tests/block-bindings/render.php index e701d01a26507..3e1dbf831b86b 100644 --- a/tests/phpunit/tests/block-bindings/render.php +++ b/tests/phpunit/tests/block-bindings/render.php @@ -102,7 +102,7 @@ public function data_update_block_with_value_from_source() { , '', ), - 'image block' => array( + 'image block' => array( 'caption', << @@ -110,7 +110,7 @@ public function data_update_block_with_value_from_source() { HTML , - '
test source value
' + '
test source value
', ), 'test block' => array( 'myAttribute', From f1d361fe5ffdf7c9a508d1a220c3ac66effdd51d Mon Sep 17 00:00:00 2001 From: Bernie Reiter <96308+ockham@users.noreply.github.com> Date: Tue, 23 Sep 2025 17:40:15 +0200 Subject: [PATCH 4/4] Fix ticket reference in tests Co-authored-by: Mukesh Panchal --- tests/phpunit/tests/block-bindings/render.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/block-bindings/render.php b/tests/phpunit/tests/block-bindings/render.php index 3e1dbf831b86b..fa8178cbd39b2 100644 --- a/tests/phpunit/tests/block-bindings/render.php +++ b/tests/phpunit/tests/block-bindings/render.php @@ -295,7 +295,7 @@ public function test_passing_uses_context_to_source() { * Furthermore tests if the caption attribute is correctly processed. * * @ticket 60282 - * @ticket XXXXX + * @ticket 64031 * * @covers ::register_block_bindings_source */