Skip to content
PHP Filters

lzb/block_data

Adds a key to a block after Lazy Blocks has assembled it from post meta, which is how a custom setting saved on the block builder screen reaches the rest of the plugin.

It fires once per block inside marshal_block_data_with_controls(), for blocks created in the builder and for blocks registered from PHP alike. Everything downstream reads the array this filter returns, so a key added here is visible to the render callback, to register_block_type() and to the editor. Lazy Blocks Pro uses it for exactly this. The Relationships feature adds provide_context_to_blocks, custom_context_slug, allowed_blocks and ancestor at priority 12, and the custom slug namespace feature rewrites slug at priority 10.

Attributes

NameTypeDescription
$block_dataArrayassembled block, see the keys below
$get_meta_valueCallablereads one raw meta value for this block by name
KeyTypeDescription
idInt | nullpost ID, null for a block registered from PHP
titleStringblock name in the inserter
iconStringSVG markup or a Dashicons name
keywordsArrayextra inserter search terms
slugStringfull block name, for example lazyblock/alert-block
descriptionStringtext under the block name in the inspector
categoryStringsanitised category slug
category_labelStringcategory name as typed in the builder
supportsArraycustomClassName, anchor, html, multiple, inserter, reusable, color, layout, shadow, spacing, dimensions, typography, lock, align, ghostkit
controlsArraycontrols keyed by control ID, already merged with their type defaults
codeArrayoutput_method, editor_html, editor_callback, frontend_html, frontend_callback, show_preview, single_output
styleArrayblock and editor CSS strings
scriptArrayview JavaScript string
stylesArrayblock style variations
conditionArraypost types the block is limited to
edit_urlStringblock builder link for this block

$get_meta_value takes one raw meta name and returns its value with the block defaults already applied, so $get_meta_value( 'lazyblocks_slug' ) gives the slug without the namespace.

Usage

PHP
function my_lzb_block_data( $block_data, $get_meta_value ) {
  // Surface a meta field added by a custom block builder panel, so the
  // render callback and register_block_type() can both see it.
  $block_data['my_wrapper_tag'] = $get_meta_value( 'lazyblocks_my_wrapper_tag' );
 
  if ( ! $block_data['my_wrapper_tag'] ) {
    $block_data['my_wrapper_tag'] = 'div';
  }
 
  return $block_data;
}
 
add_filter( 'lzb/block_data', 'my_lzb_block_data', 10, 2 );

get_blocks() caches its result in a transient for a day. The cache key is a hash that counts the priorities registered on this filter, so adding a handler at a priority nothing else uses invalidates the cache on its own, while a second handler at priority 10 lands in an existing bucket and keeps serving stale data until lzb/cache_expiration runs out or a block is saved. Dropping the slug key removes the block from the editor entirely, because register_block() filters out blocks whose slug has no name after the namespace.

The neighbouring stages are lzb/block_defaults for the fallback values, lzb/prepare_block_attribute for one control's attribute, and lzb/register_block_type_data for the registration array.

Was this article helpful?

Copyright © 2026 Lazy Blocks.