$data Collected site data. */ if ( ! defined( 'ABSPATH' ) ) { exit; } // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template variables scoped to including method. $identity = $data['identity']; $permissions = $data['permissions']; $settings = $data['settings']; $technical = $data['technical']; $map = AIDF_Permissions_Mapper::get_map( $data ); $output = array( '$schema' => 'https://www.ai-visibility.org.uk/specifications/ai-json/ai-json.schema.json', ); if ( ! empty( $technical['language'] ) ) { $output['language'] = $technical['language']; } $output['name'] = $identity['name']; $output['url'] = $identity['url']; $output['permissions'] = $map['permissions']; $output['restrictions'] = $map['restrictions']; // Attribution. $attribution = array( 'required' => ( 'allow_with_attribution' === $permissions['ai_usage'] ), ); if ( ! empty( $permissions['citation_format'] ) ) { $attribution['format'] = $permissions['citation_format']; } $output['attribution'] = $attribution; // Contact. $contact = array(); if ( ! empty( $identity['email'] ) ) { $contact['email'] = $identity['email']; } if ( ! empty( $identity['contact_url'] ) ) { $contact['url'] = $identity['contact_url']; } if ( ! empty( $contact ) ) { $output['contact'] = $contact; } // Scope. $output['scope'] = array( 'appliesTo' => 'All publicly accessible content on ' . $identity['url'], ); // Licensing. $licensing = array( 'aiTrainingAllowed' => ( 'allow' === $permissions['ai_training'] ), ); $licence_label = AIDF_Generator::format_licence( $permissions['content_licence'] ); if ( ! empty( $licence_label ) ) { $licensing['contentLicense'] = $licence_label; } $output['licensing'] = $licensing; // Metadata. $output['metadata'] = array( 'lastUpdated' => wp_date( 'Y-m-d' ), 'generator' => 'AI Discovery Files for WordPress v' . AIDF_VERSION, ); // Cross-references (extension property; the canonical example uses relatedFiles). $active = isset( $settings['active_files'] ) ? (array) $settings['active_files'] : array(); $related_files = array(); if ( in_array( 'ai-txt', $active, true ) ) { $related_files['humanReadable'] = home_url( '/ai.txt' ); } if ( in_array( 'identity-json', $active, true ) ) { $related_files['identity'] = home_url( '/identity.json' ); } if ( in_array( 'brand-txt', $active, true ) ) { $related_files['brandGuidelines'] = home_url( '/brand.txt' ); } if ( in_array( 'robots-ai-txt', $active, true ) ) { $related_files['crawlerDirectives'] = home_url( '/robots-ai.txt' ); } if ( ! empty( $related_files ) ) { $output['relatedFiles'] = $related_files; } // Spec attribution. $spec_attribution = AIDF_Generator::get_json_attribution( 'ai-json' ); if ( ! empty( $spec_attribution ) ) { $output = array_merge( $output, $spec_attribution ); } echo wp_json_encode( $output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );