Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
57b548b
get_block_wrapper_attributes: Ensures that user-provided attributes o…
t-hamano Feb 6, 2026
dd6a4a5
Remove double blank lines
t-hamano Feb 9, 2026
68fab57
Update PHPDoc
t-hamano Feb 9, 2026
bd3be96
Update PHPDoc
t-hamano Feb 9, 2026
d5dcbb8
Remove space
t-hamano Feb 9, 2026
5cbc4b5
Simplify logic
t-hamano Feb 12, 2026
ba375fe
Merge branch 'trunk' into 64564-get-block-wrapper-attributes
t-hamano Mar 10, 2026
46877b9
Add more safeguards
t-hamano Mar 10, 2026
517f69c
Fix PHPCS error
t-hamano Mar 10, 2026
acf25f6
Fix PHPCS error
t-hamano Mar 10, 2026
11e1150
unnecessary
t-hamano Mar 10, 2026
9445bd3
Remove unnecessary test
t-hamano Mar 10, 2026
beb3a42
Merge branch 'trunk' into 64564-get-block-wrapper-attributes
t-hamano Mar 11, 2026
40caa8e
Add static modifier for style callback function
t-hamano Mar 12, 2026
0ea5ebf
Add static modifier for class callback function
t-hamano Mar 12, 2026
d68e980
Add static modifier for id callback function
t-hamano Mar 12, 2026
810d5ac
Add static modifier for aria-label callback function
t-hamano Mar 12, 2026
eff534e
Use null coalescing operator
t-hamano Mar 12, 2026
2030226
Merge branch 'trunk' into 64564-get-block-wrapper-attributes
t-hamano Mar 12, 2026
66a9169
Don't split on commas
t-hamano Mar 13, 2026
1deffb5
Merge branch 'trunk' into 64564-get-block-wrapper-attributes
t-hamano Mar 19, 2026
d7878da
Add type for data_get_block_wrapper_attributes_merge_or_override
t-hamano Mar 19, 2026
4c9fe19
Remove unnecessary indent
t-hamano Mar 19, 2026
06bae0c
Improve type for data_get_block_wrapper_attributes_merge_or_override
t-hamano Mar 19, 2026
a5955f0
Use PHPStan array shape syntax
t-hamano Mar 19, 2026
54740cf
Priorize extra attributes
t-hamano Mar 19, 2026
8bc645f
Merge branch 'trunk' into 64564-get-block-wrapper-attributes
t-hamano Mar 19, 2026
fd1f9b3
use PHPStan array shape syntax
t-hamano Mar 19, 2026
2aeb26d
Explicitly convert to array
t-hamano Mar 19, 2026
21f404f
Remove extra array wrapper from data provider
t-hamano Mar 19, 2026
0e8d485
Remove extra indentation after 21f404f
westonruter Mar 19, 2026
1ea701e
Use assertSame to catch additional expected attributes
westonruter Mar 19, 2026
da5ac94
Merge branch 'trunk' into 64564-get-block-wrapper-attributes
t-hamano Mar 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions src/wp-includes/class-wp-block-supports.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,50 @@ function get_block_wrapper_attributes( $extra_attributes = array() ) {
return '';
}

// This is hardcoded on purpose.
// We only support a fixed list of attributes.
$attributes_to_merge = array( 'style', 'class', 'id', 'aria-label' );
$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 ];
// Attribute values are concatenated or overridden depending on the attribute type.
// This is hardcoded on purpose, as we only support a fixed list of attributes.
$attribute_merge_callbacks = array(
'style' => function ( $new_attribute, $extra_attribute ) {
Comment thread
t-hamano marked this conversation as resolved.
Outdated
$styles = array_filter(
array(
rtrim( trim( $extra_attribute ), ';' ),
rtrim( trim( $new_attribute ), ';' ),
)
);
return safecss_filter_attr( implode( ';', array_filter( $styles ) ) );
},
Comment thread
t-hamano marked this conversation as resolved.
'class' => function ( $new_attribute, $extra_attribute ) {
Comment thread
t-hamano marked this conversation as resolved.
Outdated
$classes = array_merge(
wp_parse_list( $extra_attribute ),
wp_parse_list( $new_attribute )
Comment thread
t-hamano marked this conversation as resolved.
Outdated
);
$classes = array_unique( array_filter( array_map( 'sanitize_html_class', $classes ) ) );
return implode( ' ', $classes );
},
'id' => function ( $new_attribute, $extra_attribute ) {
Comment thread
t-hamano marked this conversation as resolved.
Outdated
return '' !== $extra_attribute ? $extra_attribute : $new_attribute;
},
'aria-label' => function ( $new_attribute, $extra_attribute ) {
Comment thread
t-hamano marked this conversation as resolved.
Outdated
return '' !== $extra_attribute ? $extra_attribute : $new_attribute;
},
);

$attributes = array();
Comment thread
t-hamano marked this conversation as resolved.
Outdated
Comment thread
t-hamano marked this conversation as resolved.
Outdated
foreach ( $attribute_merge_callbacks as $attribute_name => $merge_callback ) {
$new_attribute = isset( $new_attributes[ $attribute_name ] ) ? $new_attributes[ $attribute_name ] : '';
$extra_attribute = isset( $extra_attributes[ $attribute_name ] ) ? $extra_attributes[ $attribute_name ] : '';
Comment thread
t-hamano marked this conversation as resolved.
Outdated
$new_attribute = is_string( $new_attribute ) ? $new_attribute : '';
$extra_attribute = is_string( $extra_attribute ) ? $extra_attribute : '';
Comment on lines +214 to +215
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanitize non-string attribute values here.


if ( '' === $new_attribute && '' === $extra_attribute ) {
continue;
}

$attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ] . ' ' . $new_attributes[ $attribute_name ];
$attributes[ $attribute_name ] = $merge_callback( $new_attribute, $extra_attribute );
}

foreach ( $extra_attributes as $attribute_name => $value ) {
if ( ! in_array( $attribute_name, $attributes_to_merge, true ) ) {
if ( ! isset( $attribute_merge_callbacks[ $attribute_name ] ) ) {
$attributes[ $attribute_name ] = $value;
}
}
Expand Down
Loading
Loading