PHP Filters
lzb/register_blocks
Filters the list of all LazyBlock blocks data specifically when registering blocks in the editor JS using registerBlockType(). This filter is used to extend block registration data with additional properties like relationship configurations, context data, and block restrictions.
Attributes
| Name | Type | Description |
|---|---|---|
$blocks | Array | Array containing all LazyBlock blocks data used for editor registration |
Usage
function my_lzb_register_blocks( $blocks ) {
foreach ( $blocks as $key => $block ) {
// Add relationship data to blocks
if ( $block['id'] === 'my-block' ) {
// Add context that this block provides
$blocks[ $key ]['provides_context'] = array(
'my-block/custom-data' => 'customData'
);
// Add context that this block uses
$blocks[ $key ]['uses_context'] = array(
'postId',
'postType'
);
// Restrict allowed child blocks
$blocks[ $key ]['allowed_blocks'] = array(
'core/paragraph',
'core/heading'
);
// Set required ancestor blocks
$blocks[ $key ]['ancestor'] = array(
'core/group'
);
}
}
return $blocks;
}
add_filter( 'lzb/register_blocks', 'my_lzb_register_blocks', 10, 1 );