allowed_block_types_all
and backwards compatibility
#45760
Replies: 2 comments
-
We also build our themes with a block whitelist and ran into this exact issue with
The best way I've found to access this is using Just the JS: wp.domReady(function () {
console.log(wp.blocks.getBlockTypes());
}); As an inline script that doesn't do anything else: wp_register_script( 'editor-blocks-active', '', ["wp-blocks", "wp-dom-ready"]);
wp_enqueue_script( 'editor-blocks-active' );
wp_add_inline_script( 'editor-blocks-active', "wp.domReady(function () { console.log(wp.blocks.getBlockTypes()); });"); |
Beta Was this translation helpful? Give feedback.
-
You can get the list of all registered blocks via this method: $allowed_block_types = ( true === $allowed_block_types ) ? array_values(
array_map(
function ( $block ) {
return $block->name;
},
WP_Block_Type_Registry::get_instance()->get_all_registered()
)
) : $allowed_block_types; EDIT: $allowed_block_types = ( true === $allowed_block_types ) ? array_keys(
WP_Block_Type_Registry::get_instance()->get_all_registered()
) : $allowed_block_types; |
Beta Was this translation helpful? Give feedback.
-
Hello,
I use
allowed_block_types_all
on all of my projects in order to limit my users to just the block types that make sense for their site. This is very important, otherwise the vast amount of irrelevant block types are confusing.I am finding that when updating WordPress core, I sometimes get breakage due to, for example, needing to add support for
core/list-item
in order to supportcore/list
.I think perhaps block types should be registered with dependencies, similar to enqueueing a script and declaring that it depends on some JS library. In this example, sure, core could add
core/list-item
, but in doing so it could declarecore/list
as a dependency, so that this would have been a backwards compatible change.If back compat is not compelling, then can
allowed_block_types_all
be changed such that the first arg is an array of all registered block types, rather than just simply a booleantrue
? This would be a convenient way for me to inspect the list of core block types. As it stands now, it's not clear to me how I'm supposed to discover that list programmatically.Beta Was this translation helpful? Give feedback.
All reactions