Skip to content
PHP Filters

lzb/import_json

Filters the decoded contents of an export file before Lazy Blocks creates any posts from it.

An export file produced on a staging site carries that site's category slugs and post types. Rewrite them here, or drop the items you do not want to land, without editing the JSON by hand before every import.

Attributes

NameTypeDescription
$jsonArraydecoded export file, a list of block and template items

Each item needs an id key or the import loop skips it. Lazy Blocks decides what an item is by its other keys:

ItemRecognised byHandled by
blockany of icon, category, supports, controlsimport_block(), which then fires lzb/import/block
templatepost_typesimport_template(), which then fires lzb/import/template

The filter runs after the nonce, file size, upload error, .json extension and non-empty-array checks have all passed, so a handler never sees a rejected upload.

Usage

PHP
function my_lzb_import_json( $json ) {
  foreach ( $json as $k => $data ) {
    // Blocks exported from staging carry its category. Put them in ours.
    if ( isset( $data['controls'] ) && isset( $data['category'] ) ) {
      $json[ $k ]['category']       = 'theme-blocks';
      $json[ $k ]['category_label'] = 'Theme Blocks';
    }
  }
 
  return $json;
}
 
add_filter( 'lzb/import_json', 'my_lzb_import_json' );

Returning anything but an array raises a TypeError at the foreach that follows. Returning an empty array imports nothing and shows no notice, because the success notices are built from the list of created post IDs. Lazy Blocks keeps its own callback here at priority 10, converting any pre-2.5.0 template item that still has a data sub-array.

The screen this runs behind is Export / Import.

Was this article helpful?

Copyright © 2026 Lazy Blocks.