Repository navigation
Conversation
…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.
|
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: 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:
|
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. |
Trac Ticket MissingThis 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. |
Description
In
block.json, block metadata fields likestyle,editorStyle, andviewStyleaccept file paths via thefile:prefix (e.g."style": "file:./style.css"). Build tools such as@wordpress/scriptsand Webpack generate adjacent.asset.phpfiles containing automated cache-busting hashes/versions and dependencies.While
register_block_script_handle()andregister_block_script_module_id()detect and load adjacent.asset.phpfiles to extract custom handle names, dependencies, and versions,register_block_style_handle()previously did not look for an.asset.phpfile, hardcoding dependencies toarray()and ignoring asset versions or custom handles.This PR adds asset file support to
register_block_style_handle(), mirroring the implementation fromregister_block_script_handle():[style-file].asset.phpfiles for stylesheets defined inblock.json.'handle'key in the asset file.'dependencies'towp_register_style().'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
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.cssExpected: 0 errors, 0 warnings.
vendor/bin/phpunit tests/phpunit/tests/blocks/register.phpvendor/bin/phpunit -c tests/phpunit/multisite.xml tests/phpunit/tests/blocks/register.phpExpected: All 74 tests (248 assertions) pass cleanly.
vendor/bin/phpunit --group blocksExpected: All 666 tests pass cleanly.
Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Analyzing
register_block_style_handlevsregister_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.