post_type == 'lazyblocks') {
// Account for both contexts
$contexts = ['frontend', 'editor'];
// Get output method
$output_method = get_post_meta($post_ID, 'lazyblocks_code_output_method', true);
// Get block slug to create legible tmp file name
$block_slug = get_post_meta($post_ID, 'lazyblocks_slug', true);
// Cache folder name
$cache_folder = get_template_directory() . '/lzb-storage';
// Only save tmp file if php or handlebars
if($output_method == 'php' || $output_method == 'html') {
foreach($contexts as $context) {
$context_code = get_post_meta($post_ID, "lazyblocks_code_{$context}_html", true);
// Create the cache folder if it doesn't exist
if(!is_dir($cache_folder)) {
mkdir($cache_folder);
}
// Sometimes, editor side doesn't exist so we simply check if it's not empty before
if(!empty(trim($context_code))) {
file_put_contents(get_template_directory() . "/lzb-storage/{$block_slug}-{$context}.tmp", $context_code);
}
}
}
}
}, 10, 3);