lzb/register_blocks
Changes the block list the editor registers from, which is where a key has to be added for a JavaScript handler to read it back.
The result is localised as window.lazyblocksGutenberg.blocks and the editor loops over it calling registerBlockType(). It is the browser-side twin of lzb/register_block_type_data, which shapes the same blocks for PHP. Only some keys are read directly. title, description, icon, category, keywords, supports, condition and slug build the registration arguments, and the whole item is handed to the block's edit component, so a key nothing in the editor knows about is still readable from the block data there.
Attributes
| Name | Type | Description |
|---|---|---|
$blocks | Array | list of blocks, each one shaped like lzb/block_data returns |
slug is the full block name including the namespace and is what registerBlockType() is called with. id is the post ID, an integer, so match on slug rather than on id when picking one block out of the list. Lazy Blocks Pro adds provides_context, uses_context, allowed_blocks and ancestor here through its Relationships feature, and the JavaScript filter lzb.registerBlockType.args copies them onto the registration arguments.
Usage
function my_lzb_register_blocks( $blocks ) {
// Let one block sit only inside a Group, and only take paragraphs.
foreach ( $blocks as $key => $block ) {
if ( 'lazyblock/faq-item' !== $block['slug'] ) {
continue;
}
$blocks[ $key ]['ancestor'] = array( 'core/group' );
$blocks[ $key ]['allowed_blocks'] = array( 'core/paragraph', 'core/heading' );
}
return $blocks;
}
add_filter( 'lzb/register_blocks', 'my_lzb_register_blocks' );ancestor and allowed_blocks are read by the Pro Relationships script, so they do nothing without Pro. The list is JSON encoded for the browser, which turns a gapped array into an object and leaves the editor with no blocks at all, so reindex with array_values() after removing an item. Removing a block here hides it from the inserter but leaves it registered in PHP, so existing posts still render it.
The JavaScript side of the same registration is lzb.registerBlockType.args.