Skip to content
PHP Filters

lzb/export_json/die

Keeps export_json() from calling die(), so a test can assert on the exported JSON instead of losing the PHPUnit process.

This exists for the plugin's own test suite. A test that reaches the die() takes the whole runner down and PHPUnit reports a crashed process rather than the failed assertion.

Attributes

NameTypeDescription
$dieBooleanwhether to terminate the request, true by default

Usage

PHP
// In a PHPUnit test case.
add_filter( 'lzb/export_json/die', '__return_false' );
 
ob_start();
lazyblocks()->tools()->export_json( array( $block_id ) );
$exported = json_decode( ob_get_clean(), true );
 
$this->assertSame( 'lazyblock/my-block', $exported[0]['slug'] );
 
remove_filter( 'lzb/export_json/die', '__return_false' );

The filter runs after the Content-disposition headers and the JSON body have already been written. Returning a falsy value on a live site therefore does not cancel the download, it lets the admin page continue rendering and appends its HTML to the end of the downloaded .json file. Leave the default true outside of tests.

Was this article helpful?

Copyright © 2026 Lazy Blocks.