HEX
Server: Apache/2.4.66 (Debian)
System: Linux 6dfabc3b2241 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64
User: (1000)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //var/www/html/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.");