Skip to content
wiki.fftac.org

Functions - Source Excerpt 01

Back to Functions

Summary

This source excerpt preserves a bounded section of Wiki.FFTAC.org/wp-content/themes/wiki-fftac-authority/functions.php so readers can inspect the evidence without opening the full source file.

**Source path:** Wiki.FFTAC.org/wp-content/themes/wiki-fftac-authority/functions.php

<?php
/**
 * wiki.fftac.org authority theme setup.
 *
 * @package WikiFftacAuthority
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

define( 'AIWIKIS_AUTHORITY_VERSION', '3.29.0' );
define( 'AIWIKIS_PUBLIC_ORIGIN', 'http://wiki.fftac.org' );
define( 'AIWIKIS_PUBLIC_SITE_NAME', 'wiki.fftac.org' );
define( 'AIWIKIS_PUBLIC_TAGLINE', 'WP-FFTAC long-term memory and archive' );
define( 'AIWIKIS_GA4_MEASUREMENT_ID', 'G-FZLNP9J7FW' );

function aiwikis_authority_public_site_name(): string {
	return AIWIKIS_PUBLIC_SITE_NAME;
}

function aiwikis_authority_public_tagline(): string {
	return AIWIKIS_PUBLIC_TAGLINE;
}

function aiwikis_authority_filter_blogname( $value = null ): string {
	unset( $value );

	return aiwikis_authority_public_site_name();
}
add_filter( 'pre_option_blogname', 'aiwikis_authority_filter_blogname' );
add_filter( 'option_blogname', 'aiwikis_authority_filter_blogname' );

function aiwikis_authority_filter_blogdescription( $value = null ): string {
	unset( $value );

	return aiwikis_authority_public_tagline();
}
add_filter( 'pre_option_blogdescription', 'aiwikis_authority_filter_blogdescription' );
add_filter( 'option_blogdescription', 'aiwikis_authority_filter_blogdescription' );

function aiwikis_authority_force_admin_bar_site_name( WP_Admin_Bar $wp_admin_bar ): void {
	$node = $wp_admin_bar->get_node( 'site-name' );

	if ( ! $node ) {
		return;
	}

	$args = array(
		'id'    => 'site-name',
		'title' => aiwikis_authority_public_site_name(),
	);

	if ( isset( $node->href ) ) {
		$args['href'] = $node->href;
	}

	if ( isset( $node->meta ) && is_array( $node->meta ) ) {
		$args['meta'] = $node->meta;
	}

	$wp_admin_bar->add_node( $args );
}
add_action( 'admin_bar_menu', 'aiwikis_authority_force_admin_bar_site_name', 1000 );

function aiwikis_authority_setup(): void {
	add_theme_support( 'wp-block-styles' );
	add_theme_support( 'editor-styles' );
	add_theme_support( 'responsive-embeds' );
	add_theme_support( 'title-tag' );
	add_editor_style( 'assets/css/wiki.fftac.org.css' );

	register_nav_menus(
		array(
			'primary' => __( 'Primary', 'aiwikis-authority' ),
			'footer'  => __( 'Footer', 'aiwikis-authority' ),
		)
	);
}
add_action( 'after_setup_theme', 'aiwikis_authority_setup' );

function aiwikis_authority_enqueue_assets(): void {
	wp_enqueue_style(
		'aiwikis-authority',
		get_theme_file_uri( 'assets/css/wiki.fftac.org.css' ),
		array(),
		AIWIKIS_AUTHORITY_VERSION
	);

	$script_path = get_theme_file_path( 'assets/js/wiki.fftac.org.js' );
	if ( file_exists( $script_path ) ) {
		wp_enqueue_script(
			'aiwikis-authority',
			get_theme_file_uri( 'assets/js/wiki.fftac.org.js' ),
			array(),
			AIWIKIS_AUTHORITY_VERSION,
			true
		);
	}
}
add_action( 'wp_enqueue_scripts', 'aiwikis_authority_enqueue_assets' );

function aiwikis_authority_remove_legacy_antichrist_footer_surface(): void {
	remove_action( 'wp_footer', 'aiwikis_antichrist_net_footer_link', 20 );
	remove_action( 'wp_head', 'aiwikis_antichrist_net_footer_styles', 20 );
}
add_action( 'after_setup_theme', 'aiwikis_authority_remove_legacy_antichrist_footer_surface', 20 );

add_filter( 'pre_get_document_title', 'aiwikis_authority_filter_document_title', 20 );
add_action( 'template_redirect', 'aiwikis_authority_serve_root_icon_request', 0 );
add_action( 'do_faviconico', 'aiwikis_authority_serve_faviconico', 0 );

function aiwikis_authority_print_analytics_fallback_tag(): void {
	if ( is_admin() || is_feed() || wp_script_is( 'google_gtagjs', 'enqueued' ) || wp_script_is( 'google_gtagjs', 'done' ) ) {
		return;
	}

	$script_src = add_query_arg(
		'id',
		AIWIKIS_GA4_MEASUREMENT_ID,
		'https://www.googletagmanager.com/gtag/js'
	);

	echo "\n" . '<!-- Google tag fallback added by wiki.fftac.org authority theme -->' . "\n";
	echo '<script async src="' . esc_url( $script_src ) . '"></script>' . "\n";
	echo '<script>' . "\n";
	echo 'window.dataLayer = window.dataLayer || [];' . "\n";
	echo 'function gtag(){dataLayer.push(arguments);}' . "\n";
	echo 'gtag("js", new Date());' . "\n";
	echo 'gtag("config", ' . wp_json_encode( AIWIKIS_GA4_MEASUREMENT_ID ) . ');' . "\n";
	echo '</script>' . "\n";
}
add_action( 'wp_head', 'aiwikis_authority_print_analytics_fallback_tag', 8 );

function aiwikis_authority_public_url( string $path = '/' ): string {
	if ( '' === $path ) {
		$path = '/';
	}

	if ( preg_match( '#^https?://#i', $path ) ) {
		return $path;
	}

	if ( '/' !== $path[0] ) {
		$path = '/' . $path;
	}

	return AIWIKIS_PUBLIC_ORIGIN . $path;
}

/**
 * Primary task routes for fallback navigation.
 *
 * @return array<string,string>
 */
function aiwikis_authority_primary_routes(): array {
	return array(
		'Start'          => '/start-here/',
		'Search'         => '/search/',
		'Crawl Map'      => '/memory/crawl-map/',
		'Sources'        => '/memory/sources/',
		'Structure'      => '/wp-fftac-memory-and-site-structure/',
		'Agents'         => '/for-ai-agents/',
		'Runtime State'  => '/workspace-current-state/',
		'Transfer Log'   => '/transfer-log/',
	);
}

/**
 * Render a compact public-memory search form.
 */
function aiwikis_authority_render_search_form( string $location = 'header' ): void {
	$query = isset( $_GET['q'] ) ? sanitize_text_field( wp_unslash( $_GET['q'] ) ) : '';
	?>
	<form class="aiwikis-search-form aiwikis-search-form-<?php echo esc_attr( sanitize_html_class( $location ) ); ?>" action="<?php echo esc_url( home_url( '/search/' ) ); ?>" method="get">
		<label class="screen-reader-text" for="aiwikis-search-<?php echo esc_attr( sanitize_html_class( $location ) ); ?>"><?php esc_html_e( 'Search wiki.fftac.org memory', 'aiwikis-authority' ); ?></label>
		<input id="aiwikis-search-<?php echo esc_attr( sanitize_html_class( $location ) ); ?>" type="search" name="q" value="<?php echo esc_attr( $query ); ?>" placeholder="<?php echo esc_attr__( 'Search memory', 'aiwikis-authority' ); ?>">
		<button type="submit"><?php esc_html_e( 'Search', 'aiwikis-authority' ); ?></button>
	</form>
	<?php
}

function aiwikis_authority_current_public_path(): string {
	global $wp;

	$request = isset( $wp->request ) ? trim( (string) $wp->request, '/' ) : '';
	return $request ? '/' . $request . '/' : '/';
}

function aiwikis_authority_is_placeholder_text( string $text ): bool {
	$normalized = strtolower( trim( preg_replace( '/\s+/', ' ', $text ) ) );

	return '' === $normalized || in_array( $normalized, array( 'my wordpress blog', 'just another wordpress site' ), true );
}