get_block_wrapper_attributes(): Preserve zero value#10663
get_block_wrapper_attributes(): Preserve zero value#10663t-hamano wants to merge 5 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
bd32e51 to
af0bdc5
Compare
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Co-authored-by: Weston Ruter <westonruter@gmail.com>
| if ( ! empty( $new_attributes ) ) { | ||
| foreach ( $new_attributes as $attribute_name => $attribute_value ) { | ||
| if ( empty( $output[ $attribute_name ] ) ) { | ||
| if ( ! array_key_exists( $attribute_name, $output ) || '' === (string) $output[ $attribute_name ] ) { |
There was a problem hiding this comment.
This is the meat of the fix, right? It looks right to me, and cover edge cases:
0(integer):(string) 0="0"≠""→ treated as valid"0"(string):(string) "0"="0"≠""→ treated as valid""(empty string):(string) ""=""=""→ treated as empty (correct)false:(string) false=""=""→ treated as empty (acceptable for HTML attributes)null:(string) null=""=""→ treated as empty (acceptable)
There was a problem hiding this comment.
That's right. The main reason for using a string cast is to allow zero as a number or a string, but to exclude false or null.
ramonjd
left a comment
There was a problem hiding this comment.
Thanks for the tests! LGTM
I tested manually with the calendar block and a block anchor of 0.
Without this patch the id wasn't rendered, with this patch:
<div class="wp-block-calendar" id="0">
src/wp-includes/blocks.php
Outdated
| * Generates a string of attributes by applying to the current block being | ||
| * rendered all of the features that the block supports. | ||
| * | ||
| * @since 5.6.0 |
There was a problem hiding this comment.
What are the changes here? the array_key_exists checks? It is worth adding a @since x.x.x with a note?
|
Thanks both for your reviews! I thought it was odd to have the |
|
Thanks to both of you for the reviews! Before making any changes to this PR, I'd like to double-check what values should be allowed for the attribute. My understanding is as follows, but what do you think?
|
|
Oh, I re-forked the |
Trac ticket: https://core.trac.wordpress.org/ticket/64452
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.