lzb/add_collection
Registers a block collection from PHP, so a theme or a plugin can ship its own slug namespace instead of asking the site owner to create one in the block builder.
lazyblocks()->add_collection() fires this action and does nothing else. The free plugin has no collections, and the listener that stores the data lives in Lazy Blocks Pro, which is why the call is safe to make on a site running either version.
Attributes
| Name | Type | Description |
|---|---|---|
$data | Array | collection data |
Lazy Blocks Pro reads these keys:
| Name | Type | Description |
|---|---|---|
namespace | String | slug prefix, the part before the slash in acme/pricing-card |
label | String | name shown in the block builder slug field |
register | Boolean | call registerBlockCollection() so the inserter groups these blocks under the label, false by default |
namespace and label are read without a fallback, so an array missing either one throws an undefined-index warning while the block builder loads its collections.
Usage
function my_lzb_add_collection() {
lazyblocks()->add_collection(
array(
'namespace' => 'acme',
'label' => 'Acme Blocks',
'register' => true,
)
);
}
add_action( 'init', 'my_lzb_add_collection' );A namespace that already exists is ignored rather than overwritten, and the built-in lazyblock collection is processed first, so a collection cannot take that namespace over.
A collection added this way carries isEditable as false: it appears in the slug field of the block builder and can be selected, but the rename and delete buttons stay hidden, unlike a collection created on that screen and stored in the lazy_blocks_pro_block_collections option. Removing it means removing the add_collection() call, which leaves any block already saved under that namespace with a slug nothing registers.
The screen this shows up on is Collections.