-
Notifications
You must be signed in to change notification settings - Fork 3.4k
get_block_wrapper_attributes: Ensures that user-provided attributes override the attributes generated by block supports #10877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
226ab84
cd33856
cfe7049
02ce25d
62ba405
b9f45ff
af7ac0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,8 +181,9 @@ function get_block_wrapper_attributes( $extra_attributes = array() ) { | |
|
|
||
| // This is hardcoded on purpose. | ||
| // We only support a fixed list of attributes. | ||
| $attributes_to_merge = array( 'style', 'class', 'id', 'aria-label' ); | ||
| $attributes = array(); | ||
| $attributes_to_merge = array( 'style', 'class', 'id', 'aria-label' ); | ||
| $attributes_to_override = array( 'id', 'aria-label' ); | ||
| $attributes = array(); | ||
| foreach ( $attributes_to_merge as $attribute_name ) { | ||
| if ( empty( $new_attributes[ $attribute_name ] ) && empty( $extra_attributes[ $attribute_name ] ) ) { | ||
| continue; | ||
|
|
@@ -198,6 +199,11 @@ function get_block_wrapper_attributes( $extra_attributes = array() ) { | |
| continue; | ||
| } | ||
|
|
||
| if ( in_array( $attribute_name, $attributes_to_override, true ) ) { | ||
| $attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ]; | ||
| continue; | ||
| } | ||
|
|
||
| $attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ] . ' ' . $new_attributes[ $attribute_name ]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of merging
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the entire way this function works needs to be completely rethought.
However, I'm not sure if all of these fixes should be included in the 7.0 release. The original scope of this PR was to fix the unintended merging of ID attributes. WordPress/gutenberg#75251 (comment)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. I guess if there isn't a problem right now then it doesn't have to be fixed. The hardening you identified would be a nice-to-have. |
||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.