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/create-donate-page-v2.php
<?php
/**
 * Create Donate page with trimmed inline data.
 */

// Delete any previous attempts
foreach (['donate'] as $slug) {
    $p = get_page_by_path($slug);
    if ($p) { wp_delete_post($p->ID, true); }
}

$post_id = wp_insert_post([
    'post_title'  => 'Donate',
    'post_name'   => 'donate',
    'post_type'   => 'page',
    'post_status' => 'publish',
    'post_parent' => 25,
]);

$hero = json_encode(['name'=>'acf/hero','data'=>[
    'hero_heading'=>'SUPPORT CAE','_hero_heading'=>'field_hero_heading',
    'hero_description'=>'Your generosity sustains Vermont farms and communities.','_hero_description'=>'field_hero_description',
],'mode'=>'preview'], JSON_UNESCAPED_SLASHES);

$donate = json_encode(['name'=>'acf/donate','data'=>[
    'donate_cta_heading'=>'WE NEED THE SUPPORT OF DONORS, LARGE AND SMALL','_donate_cta_heading'=>'field_donate_cta_heading',
    'donate_tax_notice'=>'All donations are tax deductible. Tax ID: 57-1201683.','_donate_tax_notice'=>'field_donate_tax_notice',
    'donate_thankyou_heading'=>'THANK YOU FOR YOUR SUPPORT AND ASSISTANCE','_donate_thankyou_heading'=>'field_donate_thankyou_heading',
    'donate_thankyou_cards'=>3,'_donate_thankyou_cards'=>'field_donate_thankyou_cards',
    'donate_thankyou_cards_0_card_title'=>'Support Local Farms','_donate_thankyou_cards_0_card_title'=>'field_donate_card_title',
    'donate_thankyou_cards_0_card_description'=>'Your donation directly supports Vermont farmers and food producers.','_donate_thankyou_cards_0_card_description'=>'field_donate_card_description',
    'donate_thankyou_cards_1_card_title'=>'Strengthen Communities','_donate_thankyou_cards_1_card_title'=>'field_donate_card_title',
    'donate_thankyou_cards_1_card_description'=>'Help build resilient rural communities through food system investment.','_donate_thankyou_cards_1_card_description'=>'field_donate_card_description',
    'donate_thankyou_cards_2_card_title'=>'Build Food Systems','_donate_thankyou_cards_2_card_title'=>'field_donate_card_title',
    'donate_thankyou_cards_2_card_description'=>'Fund the infrastructure that connects farms to communities.','_donate_thankyou_cards_2_card_description'=>'field_donate_card_description',
    'donate_form_heading'=>'SOWING OPPORTUNITY!','_donate_form_heading'=>'field_donate_form_heading',
    'donate_form_description'=>'Thank you for supporting the farms and communities that make up our agricultural economy.','_donate_form_description'=>'field_donate_form_description',
    'donate_form_amounts'=>'50,100,250,500,1000','_donate_form_amounts'=>'field_donate_form_amounts',
    'donate_form_button_text'=>'Donate Now','_donate_form_button_text'=>'field_donate_form_button_text',
],'mode'=>'preview'], JSON_UNESCAPED_SLASHES);

$cta = json_encode(['name'=>'acf/cta','data'=>[
    'cta_heading'=>'GET INVOLVED','_cta_heading'=>'field_cta_heading',
    'cta_description'=>'Learn more about ways you can support CAE.','_cta_description'=>'field_cta_description',
],'mode'=>'preview'], JSON_UNESCAPED_SLASHES);

$content = "<!-- wp:acf/hero {$hero} /-->\n\n<!-- wp:acf/donate {$donate} /-->\n\n<!-- wp:acf/cta {$cta} /-->";

// Verify
$blocks = parse_blocks($content);
$ok = true;
foreach ($blocks as $b) {
    if ($b['blockName'] && !isset($b['attrs']['data'])) {
        WP_CLI::warning($b['blockName'] . ' missing data');
        $ok = false;
    }
}

if (!$ok) {
    WP_CLI::error('Parse failed.');
    exit(1);
}

wp_update_post(['ID' => $post_id, 'post_content' => $content]);
wp_cache_flush();

$rendered = apply_filters('the_content', get_post($post_id)->post_content);
WP_CLI::success("Donate page (ID: {$post_id}). Hero: " . (strpos($rendered,'hero-block')!==false?'YES':'NO') . ", Donate: " . (strpos($rendered,'donate-block')!==false?'YES':'NO'));