settings = $settings; $this->tools = $tools; $this->abilities = $abilities; } public function init() { add_action( 'init', array( $this, 'register_rewrite_rules' ) ); add_filter( 'query_vars', array( $this, 'register_query_vars' ) ); add_action( 'template_redirect', array( $this, 'maybe_render' ) ); } public function register_rewrite_rules() { add_rewrite_rule( '^ai\.json$', 'index.php?agizoai_ai_profile=1', 'top' ); } public function register_query_vars( $vars ) { $vars[] = 'agizoai_ai_profile'; return $vars; } public function is_enabled() { return (bool) $this->settings->get( 'ai_profile_enabled', 1 ); } public function get_url() { return home_url( '/ai.json' ); } public function maybe_render() { if ( ! get_query_var( 'agizoai_ai_profile' ) ) { return; } if ( ! $this->is_enabled() ) { status_header( 404 ); nocache_headers(); exit; } status_header( 200 ); header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset', 'UTF-8' ) ); header( 'X-Robots-Tag: noindex, follow', true ); nocache_headers(); echo wp_json_encode( $this->generate(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- JSON response. exit; } public function generate() { $options = $this->settings->get_options(); $tools = $this->tools->summarize_tools(); return array( 'schema' => 'https://agizoai.com/schemas/ai-site-profile/v1', 'version' => 1, 'generated_at' => current_time( 'c' ), 'site' => array( 'name' => get_bloginfo( 'name' ), 'description' => get_bloginfo( 'description' ), 'url' => home_url( '/' ), 'language' => get_bloginfo( 'language' ), 'site_type' => $options['site_type'], 'purpose' => $options['site_purpose'], ), 'discovery' => array( 'llms_txt' => ! empty( $options['enabled'] ) ? home_url( '/llms.txt' ) : null, 'llms_full_txt' => ! empty( $options['full_enabled'] ) ? home_url( '/llms-full.txt' ) : null, 'ai_profile' => $this->get_url(), 'rest_tool_registry'=> ! empty( $tools['enabled'] ) ? $tools['registry_url'] : null, 'abilities_api' => $this->abilities->is_available() && $this->abilities->is_enabled(), 'mcp_ready' => $this->abilities->is_available() && $this->abilities->is_enabled() && (bool) $options['abilities_public_enabled'], ), 'content' => array( 'post_types' => array_values( (array) $options['include_post_types'] ), 'taxonomies' => array_values( (array) $options['include_taxonomies'] ), 'respect_noindex' => (bool) $options['respect_noindex'], 'private_content_excluded' => ! (bool) $options['include_private'], ), 'capabilities' => array_values( array_map( static function( $tool ) { return isset( $tool['name'] ) ? $tool['name'] : ''; }, (array) $tools['tools'] ) ), 'safety' => array( 'mode' => 'read_only', 'safe_mode' => (bool) $options['safe_mode'], 'forms_submit' => false, 'content_write' => false, 'commerce_write'=> false, ), ); } }