Functions - Source Excerpt 05
Summary
This source excerpt preserves a bounded section of Anti-Christ.net/wp-content/themes/anti-christ-thin-veil/functions.php so readers can inspect the evidence without opening the full source file.
**Source path:** Anti-Christ.net/wp-content/themes/anti-christ-thin-veil/functions.php
/**
* Starter tag definitions.
*
* @return array
*/
function actv_starter_tags_data() {
return array(
'eo-14202' => array( 'EO 14202', 'Executive Order 14202 and the federal anti-Christian-bias apparatus.' ),
'religious-liberty' => array( 'Religious Liberty', 'Equal liberty, accommodation, conscience, and pluralist constitutional questions.' ),
'state-co-optation' => array( 'State Co-optation', 'State capture, patronage, registration, surveillance, and favored religious power.' ),
'surveillance' => array( 'Surveillance', 'Public and private watching systems, data trails, and observation culture.' ),
'courts' => array( 'Courts', 'Court access, due process, filings, hearings, and legal system opacity.' ),
'debt' => array( 'Debt', 'Debt pressure, fees, arrears, and economic discipline.' ),
'public-records' => array( 'Public Records', 'Records requests, source trails, retention, denials, fees, and appeals.' ),
'privacy' => array( 'Privacy', 'Data minimization, submission hygiene, no unsupported anonymity promises, and source protection.' ),
'due-process' => array( 'Due Process', 'Notice, hearings, fair procedures, appeals, and the right to be heard.' ),
'claim-discipline' => array( 'Claim Discipline', 'Confidence labels, correction paths, harm review, and evidence boundaries.' ),
);
}
/**
* Find a starter page by slug, including draft/private/trashed copies.
*
* @param string $slug Page slug.
* @return WP_Post|null
*/
function actv_find_starter_page( $slug ) {
$pages = get_posts(
array(
'name' => sanitize_title( $slug ),
'post_type' => 'page',
'post_status' => array( 'publish', 'future', 'draft', 'pending', 'private', 'trash' ),
'posts_per_page' => 1,
'orderby' => 'ID',
'order' => 'ASC',
)
);
if ( empty( $pages ) ) {
return null;
}
return $pages[0];
}
/**
* Determine whether an existing starter page needs content/template repair.
*
* @param WP_Post $page Page object.
* @param array $data Starter page definition.
* @return bool
*/
function actv_starter_page_needs_repair( $page, $data ) {
if ( 'publish' !== $page->post_status ) {
return true;
}
if ( ! empty( $data['template'] ) && 'default' !== $data['template'] ) {
$template = get_post_meta( $page->ID, '_wp_page_template', true );
if ( $template !== $data['template'] ) {
return true;
}
}
$text = wp_strip_all_tags( $page->post_content );
if ( ! empty( $data['required_text'] ) ) {
foreach ( $data['required_text'] as $required_text ) {
if ( false === stripos( $text, $required_text ) ) {
return true;
}
}
}
return false;
}
/**
* Check whether any public starter page is missing or no longer published.
*
* @return bool
*/
function actv_starter_pages_need_repair() {
foreach ( actv_starter_pages_data() as $slug => $data ) {
$page = actv_find_starter_page( $slug );
if ( ! $page instanceof WP_Post || actv_starter_page_needs_repair( $page, $data ) ) {
return true;
}
}
return false;
}
/**
* Create starter pages, categories, menu, and reading settings.
*
* @return array Created or found page IDs.
*/
function actv_create_starter_pages() {
$pages = actv_starter_pages_data();
$page_ids = array();
foreach ( $pages as $slug => $data ) {
$existing = actv_find_starter_page( $slug );
if ( $existing instanceof WP_Post ) {
if ( 'trash' === $existing->post_status ) {
wp_untrash_post( $existing->ID );
$existing = get_post( $existing->ID );
}
if ( ! $existing instanceof WP_Post ) {
continue;
}
$page_id = $existing->ID;
if ( actv_starter_page_needs_repair( $existing, $data ) ) {
$result = wp_update_post(
array(
'ID' => $page_id,
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => sanitize_title( $slug ),
'post_title' => sanitize_text_field( $data['title'] ),
'post_content' => wp_kses_post( $data['content'] ),
),
true
);
if ( is_wp_error( $result ) ) {
continue;
}
}
} else {
$page_id = wp_insert_post(
array(
'post_type' => 'page',
'post_status' => 'publish',
'post_name' => sanitize_title( $slug ),
'post_title' => sanitize_text_field( $data['title'] ),
'post_content' => wp_kses_post( $data['content'] ),
),
true
);
}
if ( is_wp_error( $page_id ) || ! $page_id ) {
continue;
}
if ( ! empty( $data['template'] ) && 'default' !== $data['template'] ) {
update_post_meta( $page_id, '_wp_page_template', sanitize_text_field( $data['template'] ) );
}
$page_ids[ $slug ] = (int) $page_id;
}
foreach ( actv_starter_categories_data() as $slug => $category ) {
if ( ! term_exists( $slug, 'category' ) ) {
wp_insert_term(
sanitize_text_field( $category[0] ),
'category',
array(
'slug' => sanitize_title( $slug ),
'description' => sanitize_text_field( $category[1] ),
)
);
}
}
foreach ( actv_starter_tags_data() as $slug => $tag ) {
if ( ! term_exists( $slug, 'post_tag' ) ) {
wp_insert_term(
sanitize_text_field( $tag[0] ),
'post_tag',
array(
'slug' => sanitize_title( $slug ),
'description' => sanitize_text_field( $tag[1] ),
)
);
}
}
actv_repair_default_category();
actv_seed_launch_posts();
if ( isset( $page_ids['home'] ) ) {
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $page_ids['home'] );
}
if ( isset( $page_ids['journal'] ) ) {
update_option( 'page_for_posts', $page_ids['journal'] );
}
actv_create_starter_menu( $page_ids );
actv_configure_participants_database_member_pages( $page_ids );
update_option( 'actv_starter_pages_created', current_time( 'mysql' ) );
flush_rewrite_rules();
return $page_ids;
}
/**
* Automatically prepare starter content when the theme is activated.
*/
function actv_after_switch_theme() {
actv_create_starter_pages();
}
add_action( 'after_switch_theme', 'actv_after_switch_theme' );
/**
* Repair missing starter pages for admins if they disappear after setup.
*/
function actv_maybe_repair_starter_pages() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
return;
}
if ( actv_starter_pages_need_repair() ) {
actv_create_starter_pages();
}
}
add_action( 'admin_init', 'actv_maybe_repair_starter_pages' );
/**
* Repair a required public page when its front-end route is requested.
*/
function actv_maybe_repair_requested_starter_page() {
$path = isset( $_SERVER['REQUEST_URI'] ) ? (string) wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
$path = trim( (string) wp_parse_url( $path, PHP_URL_PATH ), '/' );
if ( '' === $path || ! array_key_exists( $path, actv_starter_pages_data() ) ) {
return;
}
$data = actv_starter_pages_data()[ $path ];
$page = actv_find_starter_page( $path );
if ( ! $page instanceof WP_Post || actv_starter_page_needs_repair( $page, $data ) ) {
actv_create_starter_pages();
}
}
add_action( 'init', 'actv_maybe_repair_requested_starter_page', 20 );
/**
* Create and assign the primary menu if it does not already have items.
*
* @param array $page_ids Page ID map.
*/
function actv_create_starter_menu( $page_ids ) {
$menu_name = 'Primary Veil';
$menu = wp_get_nav_menu_object( $menu_name );
$menu_id = $menu ? (int) $menu->term_id : (int) wp_create_nav_menu( $menu_name );
if ( ! $menu_id ) {
return;
}
actv_replace_menu_items(
$menu_id,
array( 'start-here', 'journal', 'religion-and-the-machine', 'the-machine', 'civil-liberties', 'socioeconomic-decay', 'field-guide', 'submit-dispatch', 'members' ),
$page_ids
);
$footer_menu_name = 'Footer Civic Links';
$footer_menu = wp_get_nav_menu_object( $footer_menu_name );
$footer_menu_id = $footer_menu ? (int) $footer_menu->term_id : (int) wp_create_nav_menu( $footer_menu_name );
if ( $footer_menu_id ) {
actv_replace_menu_items(
$footer_menu_id,
array( 'standards', 'corrections', 'privacy', 'contact', 'submit-dispatch', 'members' ),
$page_ids
);
$has_fftac = false;
$items = wp_get_nav_menu_items( $footer_menu_id );
if ( ! empty( $items ) ) {
foreach ( $items as $item ) {
if ( isset( $item->url ) && 'https://fftac.org/' === $item->url ) {
$has_fftac = true;
break;
}
}
}
if ( ! $has_fftac ) {
wp_update_nav_menu_item(
$footer_menu_id,
0,
array(
'menu-item-title' => 'FFTAC.org',
'menu-item-url' => 'https://fftac.org/',
'menu-item-type' => 'custom',
'menu-item-status' => 'publish',
)
);
}
}
$locations = get_theme_mod( 'nav_menu_locations', array() );
$locations['primary'] = $menu_id;
$locations['footer'] = $footer_menu_id ? $footer_menu_id : $menu_id;
set_theme_mod( 'nav_menu_locations', $locations );
}