Skip to content

Block Style Variations: Simplify block style variation selector regex - #12429

Closed
aaronrobertshaw wants to merge 1 commit into
WordPress:trunkfrom
aaronrobertshaw:fix/block-style-variation-selector-regex
Closed

aaronrobertshaw wants to merge 1 commit into
WordPress:trunkfrom
aaronrobertshaw:fix/block-style-variation-selector-regex

Conversation

@aaronrobertshaw

Copy link
Copy Markdown

What?

Backports Gutenberg PR WordPress/gutenberg#79924 to Core, tidying up the regex used to add a block style variation's class (e.g. .is-style-custom) to a block's selector in WP_Theme_JSON.

Trac ticket: https://core.trac.wordpress.org/ticket/65588

Why?

The regex is hard to follow and its first capture group is effectively dead. It only matches a literal :(...), which isn't valid selector syntax (functional pseudo-classes like :is() and :where() always have a name between the colon and the parenthesis), so $matches[1] is always empty. The second group does all the work, so dropping the dead group gives identical output and is much easier to follow.

How?

  • Simplifies the pattern from /((?::\([^)]+\))?\s*)([^\s:]+)/ to /[^\s:]+/ and adds a comment with worked examples.
  • Keeps the replacement callback rather than switching to backreferences, so the variation name is always treated as a literal (no chance of $/\ being interpreted).

The :is selector-list test case from the Gutenberg change already exists in Core's suite (tests/phpunit/tests/theme/wpThemeJson.php), so no test change was needed here.

Testing Instructions

This is a behaviour-preserving change, so the output should be identical to trunk.

  1. Confirm the test_get_block_style_variation_selector PHP tests pass

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@andrewserong andrewserong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This matches the GB PR and is already covered by tests, so this LGTM and I don't think it needs a ticket annotation since it's effectively a no-op. Good idea adding the extra comment to clarify the expected matches.

LGTM

@ramonjd ramonjd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Matches WordPress/gutenberg#79924, which I tested. Test pass.

@t-hamano

Copy link
Copy Markdown
Contributor

I would appreciate it if you could commit this PR in time for the 7.1 Beta1 release on July 15.

@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props aaronrobertshaw, andrewserong, ramonopoly, wildworks.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ramonjd
ramonjd force-pushed the fix/block-style-variation-selector-regex branch from 2874f59 to d317f6d Compare July 13, 2026 00:22
@ramonjd

ramonjd commented Jul 13, 2026

Copy link
Copy Markdown
Member

I would appreciate it if you could commit this PR in time for the 7.1 Beta1 release on July 15.

I'll get it in 👍🏻 Thanks @t-hamano

@ramonjd

ramonjd commented Jul 13, 2026

Copy link
Copy Markdown
Member

Committed in r62700 / 3f456ac

@ramonjd ramonjd closed this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants