-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Make block supports server-side explicit #26192
Conversation
Size Change: +3.51 kB (0%) Total Size: 1.19 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - thanks! 👍
lib/compat.php
Outdated
/** | ||
* Shim that hooks into `pre_render_block` so as to override `render_block` with | ||
* a function that assigns block context. | ||
* | ||
* This can be removed when plugin support requires WordPress 5.5.0+. | ||
* FIXME: THIS IS NO LONGER ACCURATE: This can be removed when plugin support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we keep $current_parsed_block
, then this needs to be updated to reflect that:
- It needs backporting to core
- Then, it needs to live in compat.php until 5.6 is required by the plugin
|
||
// This is hardcoded on purpose. | ||
// We only support a fixed list of attributes. | ||
$attributes_to_merge = array( 'style', 'class' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember off the top of my head how params that are objects/arrays are documented, but this seems worth adding in the PHPDoc. Even something as minimal as @param array $extra_attributes Optional. Extra classes or styles to render on the block wrapper. Use class or style as the array key, respectively.
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, good catch. Is this filtering out any elements in $extra_attributes
that aren't style
or class
? I think we should fix that. Even if keep that restriction for $new_attributes
(which makes sense) I think we should lift it for $extra_attributes
, otherwise it IMO goes against developer expectations.
(edit: I had added this comment in wrong place)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason it's limited to a set of known attributes is because merging attributes is different from one to another. For example the id
should overwrite while the style
should concat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm, I was thinking only about documentation expectations. Is there a need for this function to pass-through attributes other than style
and class
? My thinking is that it'd be ok if any other element attributes the block author needs is handled by its own mechanisms in the render_callback
function (so not in this function). As long as it's documented, I believe this is fine as it is.
$wrapper_attributes = get_block_wrapper_attributes( | ||
array( | ||
'class' => implode( ' ', $classes ), | ||
'style' => $colors['inline_styles'] . $font_sizes['inline_styles'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL that NULL . NULL
=> ''
. Nice simplification here!
$icon = block_core_social_link_get_icon( $service ); | ||
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'wp-social-link wp-social-link-' . $service . $class_name ) ); | ||
|
||
return '<li .' . $wrapper_attributes . '><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '" ' . $attribute . '> ' . $icon . '</a></li>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo here, note the dot within the string <li .
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix at #26282
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks for the PR
Builds on top of #26111
This PR introduces a new
get_block_wrapper_attributes
function you need to call explicitly in render_functions in order to make sure the block supports work in the dynamic blocks. More details on the reasoning here #26111