Opened 5 weeks ago
Last modified 34 hours ago
#64603 new defect (bug)
get_block_wrapper_attributes: id and aria-label should not be merged
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Editor | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description (last modified by )
Originally reported in https://github.com/WordPress/gutenberg/issues/75251
props to @mamaduka, @adrock42.
If a dynamic block supports id or aria-label, those attributes are automatically injected into the block via the get_block_wrapper_attributes function. However, if the user explicitly passes them, they are merged, resulting in a space between them. This is not the correct format, especially for id.
Perhaps the id and aria-label attributes should respect explicit user-added values instead of being merged.
In particular, the anchor support (id) added to all dynamic blocks in the 6.9 release may affect many consumers, so let's fix that in the 7.0 release.
Change History (6)
This ticket was mentioned in PR #10877 on WordPress/wordpress-develop by @wildworks.
5 weeks ago
#2
- Keywords has-patch has-unit-tests added
This ticket was mentioned in PR #10922 on WordPress/wordpress-develop by @wildworks.
4 weeks ago
#3
Trac ticket: https://core.trac.wordpress.org/ticket/64603
@wildworks commented on PR #10877:
4 weeks ago
#4
Oh, I re-forked the wordpress-develop repo and it seems all my submitted open PRs were closed 😂 I submitted a new PR that is equivalent to this one. https://github.com/WordPress/wordpress-develop/pull/10922
@wildworks commented on PR #10922:
3 days ago
#5
Sorry for the late reply.
After some consideration, I decided to refactor the get_block_wrapper_attributes() function overall to make it more robust and secure.
- Define callback functions that define how to merge or override each attribute.
- Sanitize style and class attribute values
- More flexibly handle redundant semicolons in style attributes
- Added a unit test to directly assert the return value of
get_block_wrapper_attributes().
#6
@
44 hours ago
Patch Testing Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/10922
Environment
- WordPress: 7.0-beta4-61919-src
- PHP: 8.3.30
- Server: nginx/1.29.5
- Database: mysqli (Server: 8.4.8 / Client: mysqlnd 8.3.30)
- Browser: Chrome 145.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.4
- MU Plugins: None activated
- Plugins:
- Block Development Examples - Block Dynamic Rendering 64756b 0.1.0
- Test Reports 1.2.1
Steps taken
- Download this dynamic block plugin https://github.com/WordPress/block-development-examples/releases/download/latest/block-dynamic-rendering-64756b.zip from WordPress block-development-examples.
- Upload the plugin and activate it.
- Head over to the plugin files, and add this code to the
build/block.jsonunder the"example": {},"attributes": { "anchor": { "type": "string" } }, - In the same file, add
"anchor": trueinside the support object then save the file. - Edit the
build/render.phpfile and add this code just above the<p>tag<?php $block_wrapper_attributes = get_block_wrapper_attributes( [ 'id' => $attributes[ 'anchor' ], ] ); ?> - In the same file, remove
get_block_wrapper_attributes()in the<p>tag and add$block_wrapper_attributes. In the end it should look like this, then save the file.<p <?php echo wp_kses_data( $block_wrapper_attributes ); ?>> <?php esc_html_e( 'Block with Dynamic Rendering – hello!!!', 'block-development-examples' ); ?> </p> - Head over to your dashboard, and add a new post.
- In the editor, add the Block Dynamic Rendering block.
- Add
my-anchorin HTML anchor input field, save the post and view the post in the frontend. - Inspect the paragraph added by the block.
- ✅ Patch is solving the problem
Expected result
- The
idattribute now holds one value and not two (an original and a duplicate).
Additional Notes
- I wasn't able to get merged values when it came to
aria-label.


Trac ticket: https://core.trac.wordpress.org/ticket/64603