Skip to content
PHP Filters

lzb/control_value

Converts what a control stored into what a template should see, which is how the Posts control turns saved IDs into post objects and how a custom control expands its own stored shape.

Three places call it, so a handler covers all of them at once. The block render callback runs it over every top-level control, get_lzb_meta() runs it over the control behind a meta name, and the Repeater control runs it over each inner control of each row. Every built-in control already hooks it at priority 5 through the base control class, matching on its own type, which means a handler at the default priority 10 sees the converted value rather than the raw stored one.

Attributes

NameTypeDescription
$valueMixedcontrol value, already converted by the control's own handler
$control_dataArraythis control, with type, name, label, default, child_of, placement, group, width, required, translate, save_in_meta and save_in_meta_name
$block_dataArrayblock data, the same array lzb/block_data returns
$contextStringeditor or frontend

The whole chain is skipped when $control_data is empty, which happens in get_lzb_meta() for a meta name no control saves.

Additional Filters

NameDescription
lzb/control_value/control_type=CONTROL_TYPEfilter value of specific control type
lzb/control_value/control_name=CONTROL_NAMEfilter value of specific control name
lzb/control_value/block_slug=BLOCK_SLUGfilter value of all controls of specific block

CONTROL_TYPE is the type slug, so lzb/control_value/control_type=image. CONTROL_NAME is the control's name, the same string the template reads. BLOCK_SLUG is the full slug including the namespace, so lzb/control_value/block_slug=lazyblock/recipe. All three take the same four arguments as the main filter and run after it, in the order listed.

Usage

PHP
function my_lzb_control_value( $value, $control_data, $block_data, $context ) {
  // Show a placeholder image in the editor when the image control is empty,
  // so the preview does not collapse.
  if ( 'editor' !== $context || ! empty( $value ) ) {
    return $value;
  }
 
  return array(
    'id'  => 0,
    'url' => get_stylesheet_directory_uri() . '/img/placeholder.png',
    'alt' => '',
  );
}
 
add_filter( 'lzb/control_value/control_type=image', 'my_lzb_control_value', 10, 4 );

Return the shape the template expects. An Image control's value is an array with id, url and alt, and a template doing {{image.url}} prints nothing when it receives a bare string. Because the filter also runs inside get_lzb_meta(), a change made here shows up in every theme file that reads the meta, not only in the block.

To change the attribute's registered type rather than its value, use lzb/prepare_block_attribute. To change the output of get_lzb_meta() after this filter has run, use lzb/get_meta.

Was this article helpful?

Copyright © 2026 Lazy Blocks.