-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Create Block: consider not using 'create-block' for namespace #42854
Comments
@t-hamano, thank you for opening this issue. It's definitely something that we should document better, so it's easier to reason what is the best practice when picking the block name. @ryanwelcher, something to think about as we work towards the goal of having better support for multiple blocks in the single plugin. In particular, we need to make it clear that textdomain defaults to the plugin slug when not defined, so it's more likely to have it set to the same value. It contrasts with the namespace from the block name, which is a way to group several blocks under one brand or developer name. |
@mburridge and @jonathanbossenger, you are currently working on learning materials for block development. Any ideas on how to mitigate this issue? We could disallow using |
When a So even if they've provided a The same could be done for |
Hmmm, this is an interesting question. Personally, as an ex-plugin developer, I expect that any tool I use to create code is going to require me to make changes to things like namespaces. In fact, I specifically reference this in my video tutorial on Learn WordPress about using the code from create-block (https://videopress.com/v/jQnZe0t4?at=555). You will see I change both the namespace and the block name. Sadly, the truth of the matter is that developers can be lazy, hence the reason there are 146 instances of 'create-block/' in the WordPress plugin directory, and probably the reason why the plugin submission process now prevents that usage. I don't think disallowing The one option I thought of when I was recording the above tutorial was to change how the name is generated by create-block: Given a plugin slug of
The name property could then be generated as
This would keep the namespace unique to the plugin |
That sounds like an interesting idea to reuse the plugin slug as the namespace when using the quick mode. Although it would also impact function and class names that would repeat the same keywords, for example: |
Something to consider here as well is that now that create-block supports I think my vote here would be to have the tool go into interactive mode if there is no slug or namespace passed. As we move the tool forward, I can see how the importance of defining a namespace will become greater. |
As per the bug scrub, perhaps adding something about the namespace issues here would suffice |
What problem does this address?
In this issue, I would like to discuss plugins generated from
@wordpress/create-block
and whethercreate-block
should be used for the namespace of the block.For example, run create-block with the following command:
In this case, file names, plugin and block are defined as follows:
PHP File
guten-pride.php
create-block
block.json
create-block/guten-pride
SCSS Files
.wp-block-create-block-guten-pride
Javascript Files
guten-pride
My main concern is that the namespace of the block is fixed to 'create-block'.
If you search for the keyword
create-block/
in WordPress Directory Searcher, you will see that several plugins have already been registered.Furthermore, since create-block is not allowed as a registrable namespace in the block directory, plugin developers will be aware of this after the plugin is released.
What is your proposed solution?
This is not a perfect solution, but I want to suggest using other string (e.g. brand name) instead of
create-block
in the generated files:PHP File
block.json
SCSS Files
Javascript Files
I think the naming would be very reasonable if create-block could support plugins with multiple blocks, as discussed in this issue.
This command does not work now, but I expect the following results in the future:
The block names generated from this command are:
The text was updated successfully, but these errors were encountered: