Functions - Source Excerpt 06
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
/**
* Replace a theme-owned menu with page links in a known order.
*
* @param int $menu_id Menu term ID.
* @param array $order Page slugs.
* @param array $page_ids Page ID map.
*/
function actv_replace_menu_items( $menu_id, $order, $page_ids ) {
$items = wp_get_nav_menu_items( $menu_id );
if ( ! empty( $items ) ) {
foreach ( $items as $item ) {
wp_delete_post( $item->ID, true );
}
}
foreach ( $order as $slug ) {
if ( empty( $page_ids[ $slug ] ) ) {
continue;
}
$title = get_the_title( $page_ids[ $slug ] );
if ( 'religion-and-the-machine' === $slug ) {
$title = __( 'Religion & The Machine', 'anti-christ-thin-veil' );
} elseif ( 'submit-dispatch' === $slug ) {
$title = __( 'Submit', 'anti-christ-thin-veil' );
}
wp_update_nav_menu_item(
$menu_id,
0,
array(
'menu-item-title' => sanitize_text_field( $title ),
'menu-item-object' => 'page',
'menu-item-object-id' => (int) $page_ids[ $slug ],
'menu-item-type' => 'post_type',
'menu-item-status' => 'publish',
)
);
}
}
/**
* Add a theme setup page under Appearance.
*/
function actv_add_setup_page() {
add_theme_page(
esc_html__( 'Anti-Christ Setup', 'anti-christ-thin-veil' ),
esc_html__( 'Anti-Christ Setup', 'anti-christ-thin-veil' ),
'edit_theme_options',
'actv-setup',
'actv_render_setup_page'
);
}
add_action( 'admin_menu', 'actv_add_setup_page' );
/**
* Render the starter setup page.
*/
function actv_render_setup_page() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
return;
}
$created = array();
if ( isset( $_POST['actv_create_pages'] ) ) {
check_admin_referer( 'actv_create_starter_pages' );
$created = actv_create_starter_pages();
?>
<div class="notice notice-success is-dismissible"><p><?php esc_html_e( 'Starter pages, categories, and navigation are ready.', 'anti-christ-thin-veil' ); ?></p></div>
<?php
}
?>
<div class="wrap">
<h1><?php esc_html_e( 'Anti-Christ Thin Veil Setup', 'anti-christ-thin-veil' ); ?></h1>
<p><?php esc_html_e( 'This optional tool creates the required archive pages, launch categories, tags, dispatches, front-page settings, member utilities, and civic navigation. It does not create trackers or external calls; member dispatches save as pending posts for editorial review.', 'anti-christ-thin-veil' ); ?></p>
<form method="post">
<?php wp_nonce_field( 'actv_create_starter_pages' ); ?>
<?php submit_button( esc_html__( 'Create starter pages and menu', 'anti-christ-thin-veil' ), 'primary', 'actv_create_pages' ); ?>
</form>
<?php if ( ! empty( $created ) ) : ?>
<h2><?php esc_html_e( 'Pages prepared', 'anti-christ-thin-veil' ); ?></h2>
<ul>
<?php foreach ( $created as $slug => $page_id ) : ?>
<li><a href="<?php echo esc_url( get_edit_post_link( $page_id ) ); ?>"><?php echo esc_html( get_the_title( $page_id ) ); ?></a> <code><?php echo esc_html( $slug ); ?></code></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<?php
}
/**
* Gentle setup notice after activation.
*/
function actv_setup_notice() {
if ( ! current_user_can( 'edit_theme_options' ) || get_option( 'actv_starter_pages_created' ) ) {
return;
}
$screen = get_current_screen();
if ( ! $screen || 'themes' !== $screen->base ) {
return;
}
?>
<div class="notice notice-info is-dismissible">
<p><?php esc_html_e( 'Anti-Christ Thin Veil is active. Use the setup tool to create the civic archive pages, Religion & The Machine, Standards, Corrections, Privacy, launch dispatches, and member utilities.', 'anti-christ-thin-veil' ); ?></p>
<p><a class="button button-primary" href="<?php echo esc_url( admin_url( 'themes.php?page=actv-setup' ) ); ?>"><?php esc_html_e( 'Open setup tool', 'anti-christ-thin-veil' ); ?></a></p>
</div>
<?php
}
add_action( 'admin_notices', 'actv_setup_notice' );