Skip to content
PHP Filters

lzb/block_defaults

Changes the value a block setting falls back to when the block builder never saved one, which is how a site sets its own house style for every new block at once.

This is the earliest of the four filters that shape a block. It runs inside get_block_defaults(), before any meta is read, so its result is only consulted when the stored meta is an empty string. Turning on lazyblocks_supports_anchor here gives an anchor field to every block that has never had the setting touched, and stops affecting a block the moment somebody saves that setting in the builder.

Attributes

NameTypeDescription
$block_defaultsArrayfallback values, keyed by the raw lazyblocks_ meta name

The keys are meta names, not the block data keys. lazyblocks_slug, lazyblocks_icon, lazyblocks_description, lazyblocks_keywords, lazyblocks_category, lazyblocks_controls, lazyblocks_styles, lazyblocks_condition_post_types, the lazyblocks_code_* group (show_preview, single_output, output_method, editor_html, editor_callback, frontend_html, frontend_callback), the lazyblocks_style_* and lazyblocks_script_* pair, and one lazyblocks_supports_* entry per block support.

Booleans are stored as the strings 'true' and 'false', and get_meta_value() converts them afterwards. lazyblocks_supports_align is the exception, an array holding wide and full by default.

Usage

PHP
function my_lzb_block_defaults( $block_defaults ) {
  // Every block that has never had these settings saved gets an anchor
  // field and no wide alignments.
  $block_defaults['lazyblocks_supports_anchor'] = 'true';
  $block_defaults['lazyblocks_supports_align']  = array();
 
  return $block_defaults;
}
 
add_filter( 'lzb/block_defaults', 'my_lzb_block_defaults' );

A boolean default written as a real true rather than the string 'true' never survives the round trip, because get_meta_value() only maps the strings. Removing a key altogether means the setting has no default at all and stays an empty string.

The assembled block list is cached in a transient, and its key counts the priorities registered on this filter. A handler at a priority nothing else uses invalidates that cache by itself. A second handler at priority 10 does not, so clear the cache or wait out lzb/cache_expiration before the change shows up.

The three later stages are lzb/block_data, which sees the assembled block, lzb/prepare_block_attribute, which sees one control at a time, and lzb/register_block_type_data, which sees what goes to register_block_type().

Was this article helpful?

Copyright © 2026 Lazy Blocks.