Skip to content
PHP Filters

lzb/sanitize_block_data

Lists the block-level keys Lazy Blocks runs through wp_kses_post() before anything reads the block list.

A block field you add through lzb/block_data is stored and printed as it was typed. Add its key here and it gets the same escaping the built-in fields get.

Attributes

NameTypeDescription
$sanitize_block_dataArrayblock keys to sanitize, title, description, category and category_label by default

The list is a flat array of top-level block keys. sanitize_block_configs() walks every block and replaces $block[ $key ] with wp_kses_post( $block[ $key ] ) for each key in the list, skipping the ones that are empty. Control-level keys are handled by the separate lzb/sanitize_block_control_data list.

Usage

PHP
function my_lzb_sanitize_block_data( $names ) {
  // A field added to every block through lzb/block_data, printed in the
  // inspector as markup, so it needs the same escaping the label gets.
  $names[] = 'documentation_note';
 
  return $names;
}
 
add_filter( 'lzb/sanitize_block_data', 'my_lzb_sanitize_block_data' );

sanitize_block_configs() is attached to lzb/get_blocks at priority 100, so it runs after every other handler on that filter and there is no way to add a key back afterwards. Removing a key from the list turns the escaping off for that field on every block. Returning anything but an array raises a TypeError at the foreach that follows.

Was this article helpful?

Copyright © 2026 Lazy Blocks.