File: //proc/thread-self/cwd/populate-support-cae-v3.php
<?php
/**
* Populate Support CAE page — v3
* Build block data array in PHP, let json_encode handle escaping,
* then fix the WordPress block comment format.
*/
$post_id = 25;
$support_data = [
'support_cae_intro_heading' => "SUPPORTING VERMONT'S FARMS, FOOD, AND COMMUNITIES",
'_support_cae_intro_heading' => 'field_support_cae_intro_heading',
'support_cae_intro_description' => 'The farms, food businesses, and communities that CAE works with are an integral part of what makes Vermont special. They are responsible for everything from the picturesque views to the delicious food on your dinner plate. CAE is committed to supporting them and can only do so with support from you.',
'_support_cae_intro_description' => 'field_support_cae_intro_description',
'support_cae_tabs' => 2,
'_support_cae_tabs' => 'field_support_cae_tabs',
'support_cae_tabs_0_tab_label' => 'Donate',
'_support_cae_tabs_0_tab_label' => 'field_support_cae_tab_label',
'support_cae_tabs_0_tab_active' => 0,
'_support_cae_tabs_0_tab_active' => 'field_support_cae_tab_active',
'support_cae_tabs_1_tab_label' => 'Ways to Give',
'_support_cae_tabs_1_tab_label' => 'field_support_cae_tab_label',
'support_cae_tabs_1_tab_active' => 1,
'_support_cae_tabs_1_tab_active' => 'field_support_cae_tab_active',
'support_cae_items' => 6,
'_support_cae_items' => 'field_support_cae_items',
];
$items_data = [
['Give a Gift of Cash', 'Make a tax-deductible donation to support CAE.', 'Cash gifts are the simplest way to support CAE. You can make a one-time gift or set up a recurring donation.'],
['Donor Advised Funds', 'Recommend a grant from your DAF to support Vermont agriculture.', 'If you have a Donor Advised Fund, you can recommend a grant to the Center for an Agricultural Economy.'],
['Give a Gift of Stock', 'Donating appreciated securities can provide significant tax benefits.', 'You may be able to take a tax deduction for full fair market value. CAE brokerage account is with Edward Jones.'],
['Planned Giving and Bequests', 'Include CAE in your estate plan for long-term sustainability.', 'Including CAE in your estate plan is a meaningful way to ensure long-term sustainability.'],
['Matching Gifts', 'Double your impact through employer matching gift programs.', 'Many employers match charitable contributions made by their employees.'],
['In-Kind Donations', 'Contribute goods and services that support CAE programs.', 'CAE accepts in-kind donations of goods and services that support our mission.'],
];
foreach ($items_data as $i => $item) {
$support_data["support_cae_items_{$i}_item_title"] = $item[0];
$support_data["_support_cae_items_{$i}_item_title"] = 'field_support_cae_item_title';
$support_data["support_cae_items_{$i}_item_description"] = $item[1];
$support_data["_support_cae_items_{$i}_item_description"] = 'field_support_cae_item_description';
$support_data["support_cae_items_{$i}_item_type"] = 'accordion';
$support_data["_support_cae_items_{$i}_item_type"] = 'field_support_cae_item_type';
$support_data["support_cae_items_{$i}_item_content"] = $item[2];
$support_data["_support_cae_items_{$i}_item_content"] = 'field_support_cae_item_content';
}
// Stock donation details (item 2)
$support_data['support_cae_items_2_item_details'] = 4;
$support_data['_support_cae_items_2_item_details'] = 'field_support_cae_item_details';
$details = [
['FBO', 'FBO'],
['Account #', '95126065'],
['DTC #', '0057'],
['Tax ID Number', '57-1201683'],
];
foreach ($details as $j => $d) {
$support_data["support_cae_items_2_item_details_{$j}_detail_label"] = $d[0];
$support_data["_support_cae_items_2_item_details_{$j}_detail_label"] = 'field_support_cae_detail_label';
$support_data["support_cae_items_2_item_details_{$j}_detail_value"] = $d[1];
$support_data["_support_cae_items_2_item_details_{$j}_detail_value"] = 'field_support_cae_detail_value';
}
$support_data['support_cae_items_2_item_callout_heading'] = 'AFTER YOU DONATE STOCK';
$support_data['_support_cae_items_2_item_callout_heading'] = 'field_support_cae_item_callout_heading';
$support_data['support_cae_items_2_item_callout_description'] = 'Let us know! Names are not included in the transfer of stock. Please contact Becca with any questions.';
$support_data['_support_cae_items_2_item_callout_description'] = 'field_support_cae_item_callout_description';
// CTA data
$cta_data = [
'cta_heading' => 'GET INVOLVED',
'_cta_heading' => 'field_cta_heading',
'cta_description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
'_cta_description' => 'field_cta_description',
];
// Build block JSON with PHP's json_encode (handles escaping correctly)
$support_block_attrs = json_encode([
'name' => 'acf/support-cae',
'data' => $support_data,
'mode' => 'preview',
], JSON_UNESCAPED_SLASHES);
$cta_block_attrs = json_encode([
'name' => 'acf/cta',
'data' => $cta_data,
'mode' => 'preview',
], JSON_UNESCAPED_SLASHES);
$post_content = "<!-- wp:acf/support-cae {$support_block_attrs} /-->\n\n<!-- wp:acf/cta {$cta_block_attrs} /-->";
// Verify the block parses before saving
$test_blocks = parse_blocks($post_content);
$has_data = isset($test_blocks[0]['attrs']['data']['support_cae_intro_heading']);
if (!$has_data) {
WP_CLI::error('Block parser failed to parse support-cae data. Aborting.');
exit(1);
}
WP_CLI::log('Block parser verified: data present.');
// Update
wp_update_post(['ID' => $post_id, 'post_content' => $post_content], true);
// Flush
wp_cache_flush();
// Verify rendering
$post = get_post($post_id);
$content = apply_filters('the_content', $post->post_content);
$has_block = strpos($content, 'support-cae-block') !== false;
$has_cta = strpos($content, 'cta-block') !== false;
WP_CLI::success("Page updated. Renders: support-cae=" . ($has_block ? 'YES' : 'NO') . ", cta=" . ($has_cta ? 'YES' : 'NO'));