Opened 3 years ago
Last modified 3 years ago
#57797 new defect (bug)
WP_Block_Type_Registry::register issues incorrect error message when block.json folder doesn't exist
| Reported by: | Tonygirling | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | 6.1.1 |
| Severity: | normal | Keywords: | dev-feedback |
| Cc: | Focuses: |
Description
I called
<?php register_block_type( path_to_block.json );
but the path does not exist.
I get error message:
Notice: Function WP_Block_Type_Registry::register was called incorrectly.
Block type names must not contain uppercase characters.
This error message does not reflect the problem.
Stepping through the code in wp-includes/blocks.php:
<?php function register_block_type( $block_type, $args = array() ) { if ( is_string( $block_type ) && file_exists( $block_type ) ) { return register_block_type_from_metadata( $block_type, $args ); } return WP_Block_Type_Registry::get_instance()->register( $block_type, $args ); }
I see ->register is still called even though the call to file_exists() fails
Change History (3)
This ticket was mentioned in Slack in #core-test by ironprogrammer. View the logs.
3 years ago
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I agree. It is a bit misleading.
register_block_type()must not try to assume what$block_typeis (a path to a file or a block type name) and should fail with an error if the file doesn't exist.Is it possible to change this behaviour?
Yes, of course, but, unfortunately, that would break backward compatibility.