Skip to content

Blocks: Add asset file (.asset.php) support for styles in register_block_style_handle() - #14065

Open
robelsust wants to merge 3 commits into
WordPress:trunkfrom
robelsust:feature/gutenberg-56838-style-asset-php
Open

robelsust wants to merge 3 commits into
WordPress:trunkfrom
robelsust:feature/gutenberg-56838-style-asset-php

Conversation

@robelsust

Copy link
Copy Markdown

Description

In block.json, block metadata fields like style, editorStyle, and viewStyle accept file paths via the file: prefix (e.g. "style": "file:./style.css"). Build tools such as @wordpress/scripts and Webpack generate adjacent .asset.php files containing automated cache-busting hashes/versions and dependencies.

While register_block_script_handle() and register_block_script_module_id() detect and load adjacent .asset.php files to extract custom handle names, dependencies, and versions, register_block_style_handle() previously did not look for an .asset.php file, hardcoding dependencies to array() and ignoring asset versions or custom handles.

This PR adds asset file support to register_block_style_handle(), mirroring the implementation from register_block_script_handle():

  1. Detects and loads adjacent [style-file].asset.php files for stylesheets defined in block.json.
  2. Allows custom style handle names via the 'handle' key in the asset file.
  3. Automatically passes dependencies defined in the asset file via 'dependencies' to wp_register_style().
  4. Uses the asset file's 'version' (if provided) for cache-busting, falling back to SCRIPT_DEBUG filemtime or block metadata version when omitted.

Follows up on Gutenberg issue WordPress/gutenberg#56838.

Testing Instructions

  1. Run PHPCS across modified source, test, and fixture files:
    vendor/bin/phpcs src/wp-includes/blocks.php tests/phpunit/tests/blocks/register.php tests/phpunit/data/blocks/notice/shared-style.asset.php tests/phpunit/data/blocks/notice/shared-style.css
    Expected: 0 errors, 0 warnings.
  2. Run single site and multisite PHPUnit tests:
    vendor/bin/phpunit tests/phpunit/tests/blocks/register.php
    vendor/bin/phpunit -c tests/phpunit/multisite.xml tests/phpunit/tests/blocks/register.php
    Expected: All 74 tests (248 assertions) pass cleanly.
  3. Verify all block unit tests pass:
    vendor/bin/phpunit --group blocks
    Expected: All 666 tests pass cleanly.

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Analyzing register_block_style_handle vs register_block_script_handle, drafting unit test cases and fixtures. Implementation and test executions were reviewed and verified locally by robelsust.


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.


…ock_style_handle()

Adds support for reading .asset.php files for stylesheets defined in block.json via file: paths, mirroring the functionality in register_block_script_handle().

Supports custom handle names, dependencies, and versioning defined in style asset files, and falls back to existing auto-generated handles and versioning when no asset file is present.

Follows up on Gutenberg #56838.
Props therssoftware.
@github-actions

github-actions Bot commented Oct 7, 2026 •

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.

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

Props therssoftware.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

github-actions Bot commented Oct 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.

@github-actions

Copy link
Copy Markdown

Trac Ticket Missing

This pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac.

To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant