---
title: "lzb/add_user_block"
description: "PHP filter `lzb/add_user_block` of the Lazy Blocks WordPress plugin."
url: "https://www.lazyblocks.com/docs/php-filters/lzb-add_user_block/"
source: "php-filters/lzb-add_user_block.mdx"
---
# 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

| Name    | Type      | Description                            |
| ------- | --------- | -------------------------------------- |
| `$data` | **Array** | block 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:

| Name             | Type            | Description                                                                                                                                                              |
| ---------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `id`             | **Int \| null** | post ID, always `null` for a block registered from PHP                                                                                                                   |
| `title`          | **String**      | block name shown in the inserter                                                                                                                                         |
| `icon`           | **String**      | SVG markup or a Dashicons name                                                                                                                                           |
| `keywords`       | **Array**       | extra inserter search terms                                                                                                                                              |
| `slug`           | **String**      | full block name, for example `lazyblock/alert-block`                                                                                                                     |
| `description`    | **String**      | text under the block name in the inspector                                                                                                                               |
| `category`       | **String**      | block category slug                                                                                                                                                      |
| `category_label` | **String**      | category name shown in the inserter                                                                                                                                      |
| `supports`       | **Array**       | `customClassName`, `anchor`, `html`, `multiple`, `inserter`, `reusable`, `color`, `layout`, `shadow`, `spacing`, `dimensions`, `typography`, `lock`, `align`, `ghostkit` |
| `controls`       | **Array**       | controls, keyed by control ID                                                                                                                                            |
| `code`           | **Array**       | block output, see below                                                                                                                                                  |
| `style`          | **Array**       | `block` and `editor` CSS strings                                                                                                                                         |
| `script`         | **Array**       | `view` JavaScript string                                                                                                                                                 |
| `styles`         | **Array**       | block style variations                                                                                                                                                   |
| `condition`      | **Array**       | post types the block is restricted to                                                                                                                                    |
| `edit_url`       | **String**      | block builder link, empty for a block registered from PHP                                                                                                                |

`code` takes these keys:

| Name                | Type         | Description                                              |
| ------------------- | ------------ | -------------------------------------------------------- |
| `output_method`     | **String**   | `html`, `php` or `template`                              |
| `editor_html`       | **String**   | markup used in the editor preview                        |
| `editor_callback`   | **Callable** | function printing the editor preview                     |
| `frontend_html`     | **String**   | markup used on the front end                             |
| `frontend_callback` | **Callable** | function printing the front end output                   |
| `show_preview`      | **Boolean**  | render the preview in the editor instead of the controls |
| `single_output`     | **Boolean**  | use `frontend_html` in the editor as well                |

## Usage

```php title="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](https://www.lazyblocks.com/docs/php-filters/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](https://www.lazyblocks.com/docs/examples/include-lazy-blocks-within-theme-or-plugin/).

## Documentation Index
> Fetch the complete documentation index at: https://www.lazyblocks.com/llms.txt
> Fetch every page in a single file at: https://www.lazyblocks.com/llms-full.txt
