Make WordPress Core

Opened 14 months ago

Last modified 13 months ago

#57797 new defect (bug)

WP_Block_Type_Registry::register issues incorrect error message when block.json folder doesn't exist

Reported by: tonygirling's profile Tonygirling Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.1.1
Component: General Keywords: dev-feedback
Focuses: Cc:

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)

#1 @antonvlasenko
14 months ago

I see ->register is still called even though the call to file_exists() fails

I agree. It is a bit misleading. register_block_type() must not try to assume what $block_type is (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.

This ticket was mentioned in Slack in #core-test by ironprogrammer. View the logs.


13 months ago

#3 @ironprogrammer
13 months ago

  • Keywords dev-feedback added

Welcome to Trac, and thank you for the report, @Tonygirling!

This ticket was reviewed during Test Team triage, and it looks like additional discussion is necessary. Marking with dev-feedback for additional core developer input.

Note: See TracTickets for help on using tickets.