-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Introduce WP_Block
and WP_Block_Factory
PHP classes and remove globals
#1321
Comments
@felixarntz for prior discussion on this topic, see: |
@westonruter Thanks for pointing me there! Am I understanding correctly though that there is no PR for the classes yet? Btw I agree that |
Yes. Feel free to ping me for review on this one. |
There is no existing PR, no, other than some PHP functions for managing block type assets (#1217). And yes, There are a couple other patterns in WordPress that come to mind that do things differently than the above. In the Customizer, you can register a control type via Another existing pattern in WordPress is The |
Due to the legacy implications of The lack of a distinction between an "entity" and "entity type" which |
Closing as implemented. |
At the moment the functions
register_block_type()
andunregister_block_type()
simply store block arguments as an array of settings inside a global. This is an outdated practice and was recently improved in other similar areas of core. In particular, no new globals should be introduced.Instead I'm suggesting the following:
WP_Block
class that represents a block. It should contain properties for the settings and also handle its own validation. This class can be implemented after other model classes likeWP_Post_Type
andWP_Taxonomy
.WP_Block_Factory
class that contains methods for registering, unregistering and retrieving blocks. The existing functionsregister_block_type()
andunregister_block_type()
could then become wrappers. This class allows us to get rid of the$wp_registered_blocks
global and store the registered blocks in a class property. Since we at this point do not have a central service locator available in WordPress, let's store the canonical main instance ofWP_Block_Factory
in a static variable and make it available through a staticget_instance()
method.I'll gladly provide the necessary code through a PR.
Beside the technical benefits, the above changes will also make it easier to work with blocks because they would then have proper documentation about their properties and functionality.
The text was updated successfully, but these errors were encountered: