Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pdewouters opened this issue Nov 15, 2021 · 6 comments
Closed
Labels
Needs Technical Feedback Needs testing from a developer perspective.

Comments

@pdewouters
Copy link

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

@annezazu annezazu added the Needs Technical Feedback Needs testing from a developer perspective. label Nov 18, 2021
@annezazu
Copy link
Contributor

@ryanwelcher not sure if you have some insights to share here?

@ryanwelcher
Copy link
Contributor

@pdewouters what are the contents of the block.json file you are using for this example? I'm going to see if I can reproduce this locally.

@ryanwelcher
Copy link
Contributor

Just wanted to follow up on this @pdewouters. I have been able to reproduce this error only when the path didn't exist - which based on your example is not the same steps to reproduce. There does seem to be a case where the validation fails to see that there is an issue with the path when using the register_block_type_from_metadata function - https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/blocks.php#L227

@pdewouters
Copy link
Author

Ok, it seems that the issue might've resolved itself for now. I can't reproduce it anymore.

@ryanwelcher
Copy link
Contributor

Thanks for the follow up!

@charlesdeb
Copy link

I had the same issue. I got this error message about upper case names (and my whole path did indeed include upper case names) when in actual fact as @ryanwelcher also experienced, I was trying to register a block to a path that didn't exist. Once I fixed that, then the error disappeared - even though my whole path still did include upper case characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective.
Projects
None yet
Development

No branches or pull requests

4 participants