Skip to content
PHP Actions

lzb/init

Fires once Lazy Blocks has loaded its classes and its controls, which is the point where lazyblocks()->add_block() can be called.

Lazy Blocks hooks this to the WordPress init action at priority 5. Its own controls register themselves on lzb/init at priority 5, so a handler left at the default priority 10 sees every control type and can reference text, image or repeater by name. Register a block earlier than that and its controls are silently dropped, because prepare_block_controls() keeps only the controls whose type it recognises.

Attributes

This action receives no arguments.

Usage

PHP
function my_lzb_init() {
  lazyblocks()->add_block(
    array(
      'title'    => 'Notice',
      'slug'     => 'lazyblock/notice',
      'icon'     => 'dashicons dashicons-info',
      'category' => 'text',
      'controls' => array(
        'control_notice_text' => array(
          'type'    => 'text',
          'name'    => 'notice-text',
          'label'   => 'Notice text',
          'default' => 'Heads up.',
        ),
      ),
      'code'     => array(
        'output_method' => 'html',
        'frontend_html' => '<div useBlockProps class="notice">{{notice-text}}</div>',
      ),
    )
  );
}
 
add_action( 'lzb/init', 'my_lzb_init' );

The array is merged over the block defaults, so every key left out keeps its default value. Two keys have no usable default. slug must carry a namespace, and a block without one never reaches register_block_type(). The keys of controls are arbitrary IDs, while each control needs its own name, which is the attribute name the template reads.

Registering blocks from PHP is covered in Include Lazy Blocks within theme or plugin. To change the array before Lazy Blocks stores it, use lzb/add_user_block.

Was this article helpful?

Copyright © 2026 Lazy Blocks.