Blocks: Include block name context in WP_Block_Type_Registry::registe…#11478
Blocks: Include block name context in WP_Block_Type_Registry::registe…#11478manishdhorepatil-art wants to merge 6 commits into
Conversation
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @ManishDhorepatil. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
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. |
The plugin includes the following invalid cases:
Result: |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves _doing_it_wrong() notices emitted by WP_Block_Type_Registry::register() by adding more context about invalid block type inputs, making debugging easier.
Changes:
- Include the received type when a non-string block name is passed.
- Include the invalid block name in notices for uppercase characters and missing namespace prefix.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com>
Co-authored-by: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com>
|
@desrosj done changes |
|
@desrosj changes done can you please review once |
|
@westonruter can you check this pr please let me know if any changes required |
* trunk: (65 commits) Twenty Twelve: Add missing documentation for some global variables. Blocks: Preserve zero values in wrapper attributes. Abilities API: Normalize `required` schema shape for REST responses Plugins: Hide the search form on the Favorites tab. REST API: Allow-list ability schema response keywords Plugins: Fix plugin card width calculation on the Add Plugins screen. Build/Test Tools: Remove unused reusable workflow. Editor: add responsive global styles for blocks. Build/Test Tools: Configure Composer caching with input where possible. Twenty Eleven: Add missing documentation for some global variables. Abilities API: Add coverage for top-level `required` in input validation Abilities API: Add coverage for ignored schema `validate_callback`/`sanitize_callback` HTML API: Fixes for issues discovered while fuzzing. Twenty Ten: Add missing documentation for some global variables. Privacy: Correct type of `WP_User_Request::$user_id` from `int` to `string`/`numeric-string`. Charset: Add missing `return` statement to `_mb_ord()`. Docs: Add missing @SInCE tags to WP_REST_Icons_Controller. Docs: Add missing @SInCE tags to `WP_Icons_Registry`. KSES: Decode style attribute before sending to safecss_filter_attr(). Twenty Sixteen: Correct display of italics in citations. ...
The uppercase-characters `_doing_it_wrong()` message gained a `%s` placeholder but no accompanying `translators:` comment, unlike the two sibling messages changed alongside it. Add the comment to satisfy WordPress.WP.I18n.MissingTranslatorsComment and match the surrounding code. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Three of the four `_doing_it_wrong()` calls in `WP_Block_Type_Registry::register()` emitted a generic message that did not identify which block name triggered it, making it hard to locate the offending registration. The notices for non-string names, uppercase characters, and a missing namespace prefix now include the received value (the type via `gettype()` for non-strings, and the escaped name otherwise), matching the existing "already registered" notice that did already report the name. Developed in #11478. Follow-up to r44108. Props manishxdp, desrosj, benjgrolleau, westonruter. Fixes #65039. git-svn-id: https://develop.svn.wordpress.org/trunk@62452 602fd350-edb4-49c9-b593-d223f7449a82
Three of the four `_doing_it_wrong()` calls in `WP_Block_Type_Registry::register()` emitted a generic message that did not identify which block name triggered it, making it hard to locate the offending registration. The notices for non-string names, uppercase characters, and a missing namespace prefix now include the received value (the type via `gettype()` for non-strings, and the escaped name otherwise), matching the existing "already registered" notice that did already report the name. Developed in WordPress/wordpress-develop#11478. Follow-up to r44108. Props manishxdp, desrosj, benjgrolleau, westonruter. Fixes #65039. Built from https://develop.svn.wordpress.org/trunk@62452 git-svn-id: http://core.svn.wordpress.org/trunk@61733 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Tested the existing patch and it works as expected.
Testing Instructions:
Apply the patch from PR Include block name context in _doing_it_wrong messages in WP_Block_Type_Registry::register() #11475.
In a test plugin or theme, try registering a block with an invalid name (e.g., containing uppercase characters):
register_block_type( 'MyBlock' );
Observe the _doing_it_wrong() notice.
Results:
Before applying the patch:
The error message is generic and does not indicate which block caused the issue.
Example:
"Block type names must not contain uppercase characters."
After applying the patch:
The error message correctly includes the block name, making debugging easier.
Example:
"Block type "MyBlock" must not contain uppercase characters."
Ticket track - https://core.trac.wordpress.org/ticket/65039
Testing the patch
https://www.dropbox.com/scl/fi/yydrbuv2saaf8w7gmw4yy/test-invalid-block.zip?rlkey=f1u85jp0424lqczpvtltve6j1&st=h30rmcia&dl=0
The plugin includes the following invalid cases:
https://github.com/user-attachments/files/26590078/debug.log
Result:
The _doing_it_wrong() messages now correctly include the block name causing the issue, improving debugging clarity.