Skip to content
wiki.fftac.org

Foundation - Source Excerpt 02

Back to Foundation

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

function antichrist_engine_foundation_get_page_url($page_key)
{
    $page_id = antichrist_engine_foundation_get_page_id($page_key);

    if ($page_id) {
        $page_url = get_permalink($page_id);

        if ($page_url) {
            return $page_url;
        }
    }

    $definitions = antichrist_engine_foundation_page_definitions();

    if (!isset($definitions[$page_key])) {
        return home_url('/');
    }

    $definition = $definitions[$page_key];
    $path       = $definition['slug'];

    if (!empty($definition['parent'])) {
        $parent_definition = $definitions[$definition['parent']] ?? null;

        if ($parent_definition) {
            $path = trailingslashit($parent_definition['slug']) . $definition['slug'];
        }
    }

    return home_url('/' . trim($path, '/') . '/');
}

/**
 * Resolves a contextual target into a usable URL.
 *
 * @param string $target Target key.
 * @return string
 */
function antichrist_engine_foundation_get_target_url($target)
{
    if ('membership_portal' === $target && function_exists('antichrist_engine_membership_get_page_url')) {
        return antichrist_engine_membership_get_page_url('portal');
    }

    if (!$target) {
        return home_url('/');
    }

    return antichrist_engine_foundation_get_page_url($target);
}

/**
 * Builds a contextual URL from a known target plus optional query args and anchor.
 *
 * @param string               $target Target key.
 * @param array<string,string> $args   Optional query args.
 * @param string               $anchor Optional anchor without #.
 * @return string
 */
function antichrist_engine_foundation_build_target_url($target, $args = array(), $anchor = '')
{
    $url = antichrist_engine_foundation_get_target_url($target);

    if ($args) {
        $url = add_query_arg($args, $url);
    }

    if ($anchor) {
        $url .= '#' . rawurlencode(ltrim($anchor, '#'));
    }

    return $url;
}

/**
 * Returns the current public support destination.
 *
 * @return array<string, mixed>
 */
function antichrist_engine_foundation_get_support_destination()
{
    $raw_url = get_option('antichrist_engine_support_url', '');
    $raw_url = apply_filters('antichrist_engine_support_url', $raw_url);
    $url     = is_scalar($raw_url) ? trim((string) $raw_url) : '';
    $is_live = '' !== $url
        && false !== filter_var($url, FILTER_VALIDATE_URL)
        && 1 === preg_match('#^https?://#i', $url);

    if ($is_live) {
        return array(
            'url'        => $url,
            'label'      => __('Give now', 'antichrist-engine'),
            'is_live'    => true,
            'is_external'=> true,
        );
    }

    return array(
        'url'         => antichrist_engine_foundation_build_target_url('contact', array('route' => 'media-partnerships'), 'contact-desk'),
        'label'       => __('Route support through the contact desk', 'antichrist-engine'),
        'is_live'     => false,
        'is_external' => false,
    );
}

/**
 * Ensures publication-track categories exist for the journal.
 *
 * @return void
 */
function antichrist_engine_foundation_ensure_publication_categories()
{
    if (wp_installing() || !taxonomy_exists('category')) {
        return;
    }

    $version = '1.0.0';

    if (get_option('antichrist_engine_publication_categories_version') === $version) {
        return;
    }

    foreach (antichrist_engine_foundation_publication_series() as $slug => $series) {
        $existing_term = term_exists($slug, 'category');

        if ($existing_term) {
            continue;
        }

        wp_insert_term(
            $series['name'],
            'category',
            array(
                'slug'        => $slug,
                'description' => $series['description'],
            )
        );
    }

    update_option('antichrist_engine_publication_categories_version', $version);
}
add_action('init', 'antichrist_engine_foundation_ensure_publication_categories', 16);

/**
 * Determines whether a post still matches the untouched WordPress starter post.
 *
 * @param WP_Post|null $post Post object to inspect.
 * @return bool
 */
function antichrist_engine_foundation_is_placeholder_publication($post)
{
    if (!$post instanceof WP_Post || 'post' !== $post->post_type || 'publish' !== $post->post_status) {
        return false;
    }

    $slug             = sanitize_title((string) ($post->post_name ?: $post->post_title));
    $title            = strtolower(trim((string) $post->post_title));
    $normalized_body  = antichrist_engine_foundation_normalize_search_text((string) $post->post_content);
    $has_default_name = in_array($title, array('hello world!', 'hello world'), true) || 'hello-world' === $slug;
    $has_default_body = str_contains($normalized_body, 'welcome to wordpress')
        || str_contains($normalized_body, 'this is your first post')
        || str_contains($normalized_body, 'edit or delete it');

    return $has_default_name && $has_default_body;
}

/**
 * Gets any placeholder publication IDs that should be hidden from public archive surfaces.
 *
 * @return int[]
 */
function antichrist_engine_foundation_get_placeholder_publication_ids()
{
    $ids          = array();
    $default_post = get_page_by_path('hello-world', OBJECT, 'post');

    if ($default_post instanceof WP_Post && antichrist_engine_foundation_is_placeholder_publication($default_post)) {
        $ids[] = (int) $default_post->ID;
    }

    $recent_posts = get_posts(array(
        'post_type'      => 'post',
        'post_status'    => 'publish',
        'posts_per_page' => 50,
    ));

    foreach ($recent_posts as $post) {
        if ($post instanceof WP_Post && antichrist_engine_foundation_is_placeholder_publication($post)) {
            $ids[] = (int) $post->ID;
        }
    }

    return array_values(array_unique(array_map('intval', $ids)));
}

/**
 * Applies placeholder exclusions to publication queries.
 *
 * @param array<string, mixed> $args Query arguments.
 * @return array<string, mixed>
 */
function antichrist_engine_foundation_get_publication_query_args($args = array())
{
    $query_args = array_merge(
        array(
            'post_type'   => 'post',
            'post_status' => 'publish',
        ),
        $args
    );
    $excluded_ids = antichrist_engine_foundation_get_placeholder_publication_ids();

    if ($excluded_ids) {
        $existing_ids             = array_map('intval', (array) ($query_args['post__not_in'] ?? array()));
        $query_args['post__not_in'] = array_values(array_unique(array_merge($existing_ids, $excluded_ids)));
    }

    return $query_args;
}

/**
 * Counts public archive files after placeholder starter posts are excluded.
 *
 * @return int
 */
function antichrist_engine_foundation_get_publication_count()
{
    $counts            = wp_count_posts('post');
    $published_count   = isset($counts->publish) ? (int) $counts->publish : 0;
    $placeholder_count = count(antichrist_engine_foundation_get_placeholder_publication_ids());

    return max(0, $published_count - $placeholder_count);
}

/**
 * Determines whether a public-facing social-proof metric is mature enough to show.
 *
 * @param int $count     Current stored count.
 * @param int $threshold Minimum count required for display.
 * @return bool
 */
function antichrist_engine_foundation_should_show_public_metric($count, $threshold = 25)
{
    return (int) $count >= max(1, (int) $threshold);
}

/**
 * Syncs the WordPress site title and tagline to the Foundation identity when placeholders remain.
 *
 * @return void
 */
function antichrist_engine_foundation_sync_site_identity_options()
{
    $identity                 = antichrist_engine_foundation_identity();
    $stored_site_name         = strtolower(trim((string) get_option('blogname', '')));
    $stored_site_description  = strtolower(trim((string) get_option('blogdescription', '')));
    $placeholder_site_names   = array(
        '',
        'anti-christ.org',
        'foundation for the anti-christ',
        'foundation for the anti-chirst',
        'foundation for the antichrist',
        'the foundation for the anti-christ',
        'the foundation for the anti-chirst',
        'my wordpress blog',
        'my wordpress site',
    );
    $placeholder_descriptions = array(
        '',
        'just another wordpress site',
        'just another wordpress blog',
        'my wordpress blog',
        'my wordpress site',
    );

    if (in_array($stored_site_name, $placeholder_site_names, true)) {
        update_option('blogname', $identity['name']);
    }

    if (in_array($stored_site_description, $placeholder_descriptions, true)) {
        update_option('blogdescription', $identity['hero_kicker']);
    }
}