Foundation - Source Excerpt 01
Summary
This source excerpt preserves a bounded section of Anti-Christ.org/wp-content/plugins/fftac-foundation-core/inc/foundation.php so readers can inspect the evidence without opening the full source file.
**Source path:** Anti-Christ.org/wp-content/plugins/fftac-foundation-core/inc/foundation.php
<?php
/**
* Foundation page provisioning, navigation, and AI helpers.
*
* @package Antichrist_Engine
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* Returns a stable hash for provisioned page content.
*
* @param string $content Page content.
* @return string
*/
function antichrist_engine_foundation_content_hash($content)
{
return md5((string) $content);
}
/**
* Legacy content hashes that are safe to refresh during a version bump.
*
* @return array<string, string[]>
*/
function antichrist_engine_foundation_legacy_page_content_hashes()
{
return array(
'manifesto' => array('22dd65e3abdb47db15ddd3f7aff7eb4a'),
'charter' => array('0ba41f5bbf01662af262d3e69d8c1235'),
'philosophy' => array('cf63fda258219c9bb94936cc5165155e'),
'research' => array('d6a0ff060a9a3f038b28315a3646f6c8'),
'standards' => array('5398fc582dc7ad02e39e1c1c5c96fc9d'),
'ai_engine' => array('4285e4e550e8881f4e5d610d71445263'),
'texts' => array('8e10e2437f8f4f115cdd7e67771d1d2a', 'ebb3d72e017fe54bddfd8ab3dcb57272'),
'symbols' => array('dd5a0af83a91e439d54e62dd073effdd', 'c5358307e3881f2a807fe38db54b778d'),
'about' => array('ec6f6e6b76b8d0b8cf49846af2527226'),
'join' => array('298157def231a53b8884ed26b3a65987'),
'journal' => array('bfc3f9634c8377c499a24584b8233cb5'),
'pillar_dogma' => array('5388e601d72e0951f56fbb4429c7e024'),
'pillar_sovereignty' => array('762d9813083a29650cad5d2442c9ae1d'),
'pillar_adversary' => array('fea7fc96d2e7fce367181050ab737293'),
'pillar_material' => array('46692c28c79e6116d281f6124e73df25'),
'pillar_evolution' => array('f05125c6719a391785cb1bf95ade5997'),
);
}
/**
* Stores the latest synced content hash for a provisioned page.
*
* @param int $page_id Page ID.
* @param string $content Page content.
* @return void
*/
function antichrist_engine_foundation_store_synced_content_hash($page_id, $content)
{
update_post_meta((int) $page_id, '_antichrist_engine_synced_content_hash', antichrist_engine_foundation_content_hash($content));
}
/**
* Determines whether a provisioned page body may be refreshed safely.
*
* @param int $page_id Page ID.
* @param string $page_key Page key.
* @param array<string, mixed> $definition Page definition.
* @return bool
*/
function antichrist_engine_foundation_should_refresh_page_content($page_id, $page_key, $definition)
{
if (empty($definition['content'])) {
return false;
}
$current_content = (string) get_post_field('post_content', (int) $page_id);
if ('' === trim($current_content)) {
return true;
}
$current_hash = antichrist_engine_foundation_content_hash($current_content);
$synced_hash = (string) get_post_meta((int) $page_id, '_antichrist_engine_synced_content_hash', true);
if ('' !== $synced_hash && $current_hash === $synced_hash) {
return true;
}
$legacy_hashes = antichrist_engine_foundation_legacy_page_content_hashes();
return in_array($current_hash, $legacy_hashes[(string) $page_key] ?? array(), true);
}
/**
* Ensures the Foundation pages exist.
*
* @return void
*/
function antichrist_engine_foundation_ensure_pages()
{
if (wp_installing() || !post_type_exists('page')) {
return;
}
$version = '1.24.0';
$definitions = antichrist_engine_foundation_page_definitions();
$needs_refresh = get_option('antichrist_engine_foundation_pages_version') !== $version;
if (!$needs_refresh) {
foreach ($definitions as $key => $definition) {
$stored_id = absint(get_option('antichrist_engine_foundation_' . $key . '_page_id'));
if (!$stored_id || 'trash' === get_post_status($stored_id)) {
$needs_refresh = true;
break;
}
if (!empty($definition['template']) && get_page_template_slug($stored_id) !== $definition['template']) {
$needs_refresh = true;
break;
}
}
}
if (!$needs_refresh) {
return;
}
$resolved_ids = array();
foreach ($definitions as $key => $definition) {
$stored_id = absint(get_option('antichrist_engine_foundation_' . $key . '_page_id'));
if ($stored_id && 'trash' !== get_post_status($stored_id)) {
$resolved_ids[$key] = $stored_id;
}
}
$pending_keys = array_keys($definitions);
$pass_count = 0;
while ($pending_keys && $pass_count < 4) {
$pass_count++;
$remaining = array();
foreach ($pending_keys as $key) {
$definition = $definitions[$key];
$parent_id = 0;
$default_content = (string) ($definition['content'] ?? '');
if (!empty($definition['parent'])) {
$parent_key = (string) $definition['parent'];
$parent_id = $resolved_ids[$parent_key] ?? absint(get_option('antichrist_engine_foundation_' . $parent_key . '_page_id'));
if (!$parent_id) {
$remaining[] = $key;
continue;
}
}
$option_name = 'antichrist_engine_foundation_' . $key . '_page_id';
$page_id = $resolved_ids[$key] ?? absint(get_option($option_name));
if (!$page_id || 'trash' === get_post_status($page_id)) {
$path = $definition['slug'];
if (!empty($definition['parent'])) {
$parent_definition = $definitions[$definition['parent']];
$path = trailingslashit($parent_definition['slug']) . $definition['slug'];
}
$existing_page = get_page_by_path($path, OBJECT, 'page');
if ($existing_page instanceof WP_Post && 'trash' !== $existing_page->post_status) {
$page_id = (int) $existing_page->ID;
}
}
if (!$page_id) {
$postarr = array(
'post_type' => 'page',
'post_status' => 'publish',
'post_title' => $definition['title'],
'post_name' => $definition['slug'],
'post_parent' => $parent_id,
'menu_order' => (int) ($definition['menu_order'] ?? 0),
'post_content' => wp_slash($default_content),
);
$page_id = wp_insert_post($postarr, true);
if (is_wp_error($page_id)) {
$remaining[] = $key;
continue;
}
} else {
$postarr = array(
'ID' => $page_id,
'post_parent'=> $parent_id,
'menu_order' => (int) ($definition['menu_order'] ?? 0),
'post_status'=> 'publish',
);
if (antichrist_engine_foundation_should_refresh_page_content($page_id, $key, $definition)) {
$postarr['post_content'] = wp_slash($default_content);
}
wp_update_post($postarr);
}
if (!empty($definition['template'])) {
update_post_meta($page_id, '_wp_page_template', $definition['template']);
}
if ('' !== $default_content) {
$current_content = (string) get_post_field('post_content', (int) $page_id);
if (antichrist_engine_foundation_content_hash($current_content) === antichrist_engine_foundation_content_hash($default_content)) {
antichrist_engine_foundation_store_synced_content_hash($page_id, $default_content);
}
}
update_option($option_name, (int) $page_id);
$resolved_ids[$key] = (int) $page_id;
}
if (count($remaining) === count($pending_keys)) {
break;
}
$pending_keys = $remaining;
}
update_option('antichrist_engine_foundation_pages_version', $version);
}
add_action('init', 'antichrist_engine_foundation_ensure_pages', 15);
/**
* Gets a provisioned foundation page ID.
*
* @param string $page_key Foundation page key.
* @return int
*/
function antichrist_engine_foundation_get_page_id($page_key)
{
return absint(get_option('antichrist_engine_foundation_' . $page_key . '_page_id'));
}
/**
* Gets a provisioned foundation page URL.
*
* @param string $page_key Foundation page key.
* @return string
*/