File: //proc/thread-self/cwd/add-hero-to-support-cae.php
<?php
/**
* Add hero block to Support CAE page, before the existing blocks.
*/
$post_id = 25;
$post = get_post($post_id);
$hero_data = [
'name' => 'acf/hero',
'data' => [
'hero_heading' => 'SUPPORT CAE',
'_hero_heading' => 'field_hero_heading',
'hero_description' => 'Your support helps strengthen Vermont farms, food businesses, and communities.',
'_hero_description' => 'field_hero_description',
'hero_button' => ['title' => 'Donate Now', 'url' => '/support-cae#donate', 'target' => ''],
'_hero_button' => 'field_hero_button',
],
'mode' => 'preview',
];
$hero_block = '<!-- wp:acf/hero ' . json_encode($hero_data, JSON_UNESCAPED_SLASHES) . ' /-->';
// Prepend hero to existing content
$new_content = $hero_block . "\n\n" . $post->post_content;
// Verify parse
$blocks = parse_blocks($new_content);
$block_names = array_filter(array_map(function($b) { return $b['blockName']; }, $blocks));
WP_CLI::log("Blocks: " . implode(', ', $block_names));
wp_update_post(['ID' => $post_id, 'post_content' => $new_content]);
wp_cache_flush();
WP_CLI::success("Hero block added to Support CAE page.");