Schema - Source Excerpt 01
Summary
This source excerpt preserves a bounded section of 2IA.org/wp-content/themes/twoia-intelligence/inc/schema.php so readers can inspect the evidence without opening the full source file.
**Source path:** 2IA.org/wp-content/themes/twoia-intelligence/inc/schema.php
<?php
/**
* JSON-LD schema output.
*
* @package TwoIA
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Build the organization schema graph.
*
* @return array
*/
function twoia_get_organization_schema() {
return array(
'@type' => 'Organization',
'@id' => home_url( '/#organization' ),
'name' => function_exists( 'twoia_public_site_name' ) ? twoia_public_site_name() : '2IA – Two Identities Of Anonymous',
'alternateName' => array( '2IA', 'Two Identities Anonymous' ),
'url' => home_url( '/' ),
'logo' => get_template_directory_uri() . '/assets/images/2ia-mark.svg',
'description' => '2IA.org is an independent public-intelligence and civil-liberties research project focused on surveillance accountability, identity, metadata, public records, anonymity, AI governance, and lawful public understanding.',
);
}
/**
* Build Website schema.
*
* @return array
*/
function twoia_get_website_schema() {
return array(
'@type' => 'WebSite',
'@id' => home_url( '/#website' ),
'url' => home_url( '/' ),
'name' => function_exists( 'twoia_public_site_name' ) ? twoia_public_site_name() : get_bloginfo( 'name' ),
'description' => get_bloginfo( 'description' ),
'publisher' => array( '@id' => home_url( '/#organization' ) ),
'potentialAction' => array(
'@type' => 'SearchAction',
'target' => add_query_arg( 's', '{search_term_string}', home_url( '/' ) ),
'query-input' => 'required name=search_term_string',
),
);
}
/**
* Build Article schema for posts and editorial content types.
*
* @return array|null
*/
function twoia_get_article_schema() {
$article_post_types = function_exists( 'twoia_article_post_types' ) ? twoia_article_post_types() : array( 'post' );
if ( ! is_singular( $article_post_types ) ) {
return null;
}
$post_id = get_the_ID();
$image = twoia_get_og_image();
return array(
'@type' => 'Article',
'@id' => get_permalink( $post_id ) . '#article',
'headline' => get_the_title( $post_id ),
'description' => twoia_get_meta_description(),
'image' => $image,
'datePublished' => get_the_date( DATE_W3C, $post_id ),
'dateModified' => get_the_modified_date( DATE_W3C, $post_id ),
'mainEntityOfPage' => get_permalink( $post_id ),
'articleSection' => twoia_post_type_label( $post_id ),
'author' => array(
'@type' => 'Person',
'name' => get_the_author_meta( 'display_name', (int) get_post_field( 'post_author', $post_id ) ),
),
'publisher' => array( '@id' => home_url( '/#organization' ) ),
);
}
/**
* Build ProfilePage schema for organization directory profiles.
*
* @return array|null
*/
function twoia_get_organization_profile_schema() {
if ( ! is_singular( 'twoia_organization' ) ) {
return null;
}
$post_id = get_the_ID();
$official_url = get_post_meta( $post_id, 'official_url', true );
$reviewed = get_post_meta( $post_id, 'last_reviewed', true );
$risk_tier = get_post_meta( $post_id, 'risk_tier', true );
$organization = array(
'@type' => 'Organization',
'name' => get_the_title( $post_id ),
'description' => twoia_get_meta_description(),
);
if ( $official_url ) {
$organization['url'] = esc_url_raw( $official_url );
$organization['sameAs'] = array( esc_url_raw( $official_url ) );
}
$profile = array(
'@type' => 'ProfilePage',
'@id' => get_permalink( $post_id ) . '#profile',
'url' => get_permalink( $post_id ),
'name' => get_the_title( $post_id ),
'description' => twoia_get_meta_description(),
'isPartOf' => array( '@id' => home_url( '/organizations/#webpage' ) ),
'mainEntity' => $organization,
'mainEntityOfPage' => get_permalink( $post_id ),
);
$properties = array();
if ( $reviewed ) {
$properties[] = array(
'@type' => 'PropertyValue',
'name' => 'last_reviewed',
'value' => wp_strip_all_tags( $reviewed ),
);
}
if ( $risk_tier ) {
$properties[] = array(
'@type' => 'PropertyValue',
'name' => 'risk_tier',
'value' => wp_strip_all_tags( $risk_tier ),
);
}
$properties[] = array(
'@type' => 'PropertyValue',
'name' => 'correction_url',
'value' => home_url( '/corrections-and-right-of-reply/' ),
);
$profile['additionalProperty'] = $properties;
return $profile;
}
/**
* Build schema for source-controlled virtual pages.
*
* @return array|null
*/
function twoia_get_virtual_page_schema() {
if ( ! function_exists( 'twoia_get_requested_virtual_page' ) ) {
return null;
}
$page = twoia_get_requested_virtual_page();
if ( ! $page || ! twoia_should_render_virtual_page( $page['slug'] ) ) {
return null;
}
$type = in_array( $page['slug'], array( 'issues', 'research', 'research-archive', 'resources', 'open-source-intelligence', 'organizations', 'lexicon' ), true ) ? 'CollectionPage' : 'WebPage';
$url = function_exists( 'twoia_get_canonical_url' ) ? twoia_get_canonical_url() : home_url( '/' . $page['slug'] . '/' );
return array(
'@type' => $type,
'@id' => $url . '#webpage',
'url' => $url,
'name' => wp_strip_all_tags( $page['title'] ),
'description' => ! empty( $page['meta_description'] ) ? wp_strip_all_tags( $page['meta_description'] ) : wp_strip_all_tags( $page['summary'] ),
'isPartOf' => array( '@id' => home_url( '/#website' ) ),
'publisher' => array( '@id' => home_url( '/#organization' ) ),
'mainEntityOfPage' => $url,
'about' => array_map(
static function ( $section ) {
return array(
'@type' => 'Thing',
'name' => wp_strip_all_tags( $section['title'] ),
);
},
array_slice( $page['sections'], 0, 8 )
),
'inLanguage' => get_bloginfo( 'language' ),
);
}
/**
* Build BreadcrumbList schema for virtual, singular, archive, and search views.
*
* @return array|null
*/
function twoia_get_breadcrumb_schema() {
$items = array(
array(
'name' => function_exists( 'twoia_public_site_name' ) ? twoia_public_site_name() : get_bloginfo( 'name' ),
'url' => home_url( '/' ),
),
);
if ( function_exists( 'twoia_get_requested_virtual_page' ) ) {
$page = twoia_get_requested_virtual_page();
if ( $page && twoia_should_render_virtual_page( $page['slug'] ) ) {
if ( ! empty( $page['route_type'] ) && 'brief' === $page['route_type'] && ! empty( $page['parent_page'] ) ) {
$items[] = array(
'name' => wp_strip_all_tags( $page['parent_page']['title'] ),
'url' => home_url( '/' . trim( $page['parent_slug'], '/' ) . '/' ),
);
}
$items[] = array(
'name' => wp_strip_all_tags( $page['title'] ),
'url' => function_exists( 'twoia_get_canonical_url' ) ? twoia_get_canonical_url() : home_url( '/' . $page['slug'] . '/' ),
);
}
}
if ( 1 === count( $items ) && is_singular() ) {
$items[] = array(
'name' => wp_strip_all_tags( get_the_title() ),
'url' => get_permalink(),
);
}
if ( 1 === count( $items ) && is_search() ) {
$items[] = array(
'name' => sprintf(
/* translators: %s: Search query. */
__( 'Search results for %s', 'two-identities-anonymous' ),
get_search_query()
),
'url' => function_exists( 'twoia_get_canonical_url' ) ? twoia_get_canonical_url() : home_url( '/' ),
);
}
if ( 1 === count( $items ) && is_archive() ) {
$queried = get_queried_object();
$name = '';
if ( is_post_type_archive() ) {
$name = post_type_archive_title( '', false );
} elseif ( isset( $queried->name ) ) {
$name = $queried->name;
}
if ( $name ) {
$items[] = array(
'name' => wp_strip_all_tags( $name ),
'url' => function_exists( 'twoia_get_canonical_url' ) ? twoia_get_canonical_url() : home_url( '/' ),
);
}
}
if ( count( $items ) < 2 ) {
return null;
}
return array(
'@type' => 'BreadcrumbList',
'@id' => ( function_exists( 'twoia_get_canonical_url' ) ? twoia_get_canonical_url() : home_url( '/' ) ) . '#breadcrumb',
'itemListElement' => array_map(
static function ( $item, $index ) {
return array(
'@type' => 'ListItem',
'position' => $index + 1,
'name' => wp_strip_all_tags( $item['name'] ),
'item' => esc_url_raw( $item['url'] ),
);
},
$items,
array_keys( $items )
),
);
}
/**
* Output JSON-LD schema.
*/
function twoia_output_schema() {
$graph = array(
twoia_get_organization_schema(),
twoia_get_website_schema(),
);
$article = twoia_get_article_schema();
if ( $article ) {
$graph[] = $article;
}
$organization_profile = twoia_get_organization_profile_schema();
if ( $organization_profile ) {
$graph[] = $organization_profile;
}
$virtual_page = twoia_get_virtual_page_schema();
if ( $virtual_page ) {
$graph[] = $virtual_page;
}