Repository navigation
Sync gutenberg_get_block_style_variation_name_from_class() with core - #68396
justlevine wants to merge 3 commits into
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
…iation_name_from_class()
7520a43 to
a922df0
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rather than turning an empty result into `null`, drop the redundant `??` and return `$matches[1]`, which `preg_match_all()` always populates with an array. This syncs `gutenberg_get_block_style_variation_name_from_class()` with `wp_get_block_style_variation_name_from_class()` in WordPress core as of r63890, including its refined types: a `string|null` parameter, a native `?array` return type, and a conditional return type. Returning `null` for a string without a variation would contradict core, whose unit tests expect an empty array in that case. The only caller, in `gutenberg_render_block_style_variation_support_styles()`, checks `! $variations`, which treats both the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
$matches[1] in gutenberg_get_block_style_variation_name_from_class()gutenberg_get_block_style_variation_name_from_class() with core
|
🤖 Comment by Claude Opus 5.5
The docblock and signature now match core too: a |
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
|
Only difference between core and Gutenberg now is the function name itself: --- core.txt 2026-10-25 13:36:57
+++ gutenberg.txt 2026-10-25 13:36:35
@@ -7,7 +7,7 @@
* @return string[]|null The block style variation names (empty if none found), or null if a string was not supplied.
* @phpstan-return ( $class_string is string ? list<non-empty-string> : null )
*/
-function wp_get_block_style_variation_name_from_class( $class_string ): ?array {
+function gutenberg_get_block_style_variation_name_from_class( $class_string ): ?array {
if ( ! is_string( $class_string ) ) {
return null;
} |
What?
This PR fixes an issue in
gutenberg_get_block_style_variation_name_from_class()where anarraywould be returned even if the variation name was not matched in the CSS class string.This is due to the fact that
preg_match_all()will always set$matches[1], and instead uses an empty string if no match is found.Why?
While this issue was surfaced by PHPStan (via #66693) it can be remediated independently as part of #66598
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast