'ai.txt' ] ); add_action( 'acid_aeo_settings_updated', [ $this, 'on_settings_updated' ] ); } /** * Renders `/ai.txt`. * * @return string File body. */ public function render(): string { if ( ! (bool) Options::get( 'policy.enabled', true ) ) { return self::DISABLED_BODY; } return ( new AiTxtGenerator() )->generate( $this->data() ); } /** * Audit checks contributed by this module. * * @return array Checks. */ public function checks(): array { return [ Checks::reachable( 'ai_txt_reachable', $this->slug(), __( 'ai.txt is reachable', 'acid-aeo' ), Router::url( 'ai_txt' ), [ 'type' => 'text/plain', 'weight' => Check::WEIGHT_IMPORTANT, 'fix' => 'flush_rewrite', ] ), Checks::physical_conflict( 'ai_txt_physical_conflict', $this->slug(), 'ai.txt', 'ai.txt' ), ]; } /** * The policy the file is rendered from. * * @return array Input for `Generators\AiTxtGenerator`. */ public function data(): array { $policy = SiteData::policy(); $identity = SiteData::identity(); $files = SiteData::file_urls(); $data = array_merge( $policy, [ 'owner' => (string) ( $identity['name'] ?? '' ), 'contact' => (string) ( $policy['permissions_contact'] ?? '' ), 'links' => [ 'context' => $this->published_url( 'ai_context', $files ), 'summary' => $this->published_url( 'llms', $files ), 'humans' => $this->published_url( 'humans', $files ), 'security' => $this->published_url( 'security', $files ), ], ] ); /** * Filters the policy `ai.txt` is built from. * * @param array $data Policy, as described by `Modules\AiTxt::data()`. */ $data = apply_filters( 'acid_aeo_ai_txt_data', $data ); return is_array( $data ) ? $data : []; } /** * The URL of a file this plugin publishes, while it is published. * * A module that is switched off leaves no dead link behind. * * @param string $slug Router slug, e.g. `humans`. * @param array $files URLs from `Data\SiteData::file_urls()`. * @return string Absolute URL, or an empty string when the file is not registered. */ private function published_url( string $slug, array $files ): string { return null !== Router::file( $slug ) ? (string) ( $files[ $slug ] ?? '' ) : ''; } }