Skip to content

Inaccurate PHP notice in WP_Block_Type_Registry::register when $name is a path #36487

@pdewouters

Description

@pdewouters

Description

When I use register_block_type( __DIR__, ...) to register a block, a PHP notice is thrown PHP Notice: WP_Block_Type_Registry::register was called <strong>incorrectly</strong>. Block type names must not contain uppercase characters. if the path calculated by __DIR__ contains uppercase letters. This doesn't seem right. A potential fix would be to make the check smarter ( detect if it's $name is a valid path?)

Step-by-step reproduction instructions

Register a block using snippet below, in an environment that will have an uppercase letter in the path, e.g. /Users/..., this happens on a local install on a mac

Screenshots, screen recording, code snippet

	register_block_type_from_metadata( __DIR__, [
		'render_callback' => function( array $attributes ) : string {
			ob_start();
			include __DIR__ . '/template.php';
			return ob_get_clean();
		},
	] );

Environment info

WP 5.8.1
Does not have standalone Gutenberg plugin

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions