Skip to content
PHP Filters

lzb/add_user_block

Filters the array handed to lazyblocks()->add_block(), before Lazy Blocks stores it.

A theme that registers a dozen blocks from PHP repeats the same category and supports in every array. Use this filter to set them in one place, or to change a block another plugin registers without touching its source.

Attributes

NameTypeDescription
$dataArrayblock data, as passed to add_block()

The returned array is merged over the block defaults inside get_blocks(), so any key you leave out keeps its default value. These are the keys Lazy Blocks reads:

NameTypeDescription
idInt | nullpost ID, always null for a block registered from PHP
titleStringblock name shown 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
categoryStringblock category slug
category_labelStringcategory name shown in the inserter
supportsArraycustomClassName, anchor, html, multiple, inserter, reusable, color, layout, shadow, spacing, dimensions, typography, lock, align, ghostkit
controlsArraycontrols, keyed by control ID
codeArrayblock output, see below
styleArrayblock and editor CSS strings
scriptArrayview JavaScript string
stylesArrayblock style variations
conditionArraypost types the block is restricted to
edit_urlStringblock builder link, empty for a block registered from PHP

code takes these keys:

NameTypeDescription
output_methodStringhtml, php or template
editor_htmlStringmarkup used in the editor preview
editor_callbackCallablefunction printing the editor preview
frontend_htmlStringmarkup used on the front end
frontend_callbackCallablefunction printing the front end output
show_previewBooleanrender the preview in the editor instead of the controls
single_outputBooleanuse frontend_html in the editor as well

Usage

PHP
function my_lzb_add_user_block( $data ) {
  // Put every block registered from PHP in one category and give it the
  // same alignments, without repeating this in each add_block() call.
  $data['category']       = 'theme-blocks';
  $data['category_label'] = 'Theme Blocks';
 
  if ( ! isset( $data['supports']['align'] ) ) {
    $data['supports']['align'] = array( 'wide', 'full' );
  }
 
  return $data;
}
 
add_filter( 'lzb/add_user_block', 'my_lzb_add_user_block' );

The filter runs inside add_block(), so blocks created in the block builder never reach it. Those go through lzb/block_data instead. Returning anything but an array raises a TypeError at the array_merge() in get_blocks(). Lazy Blocks keeps its own callback here at priority 10, converting the pre-2.1.0 code.use_php boolean into code.output_method, so a handler registered at a lower priority still sees use_php.

Registering blocks from PHP is covered in Include Lazy Blocks within theme or plugin.

Was this article helpful?

Copyright © 2026 Lazy Blocks.