__( 'aeoora – Answer Engine Optimization', 'aeoora' ), 'description' => __( 'AI crawler analytics, AI referrals, AEO scores and AI access controls.', 'aeoora' ), ) ); } } /** * Read-only meta. * * @return array */ private static function ro() { return array( 'show_in_rest' => true, 'annotations' => array( 'readonly' => true, 'destructive' => false, 'idempotent' => true, ), ); } /** * Days schema. * * @return array */ private static function days_schema() { return array( 'type' => 'object', 'properties' => array( 'days' => array( 'type' => 'integer', 'minimum' => 1, 'maximum' => 365, 'default' => 30, ), ), ); } /** * Register abilities. */ public static function register() { if ( ! function_exists( 'wp_register_ability' ) ) { return; } $admin = static function () { return current_user_can( 'manage_options' ); }; $days = static function ( $input ) { return isset( $input['days'] ) ? (int) $input['days'] : 30; }; wp_register_ability( 'aeoora/get-ai-crawler-stats', array( 'label' => __( 'Get AI crawler statistics', 'aeoora' ), 'description' => __( 'Totals, top AI crawlers and most-crawled pages for the last N days.', 'aeoora' ), 'category' => self::CATEGORY, 'input_schema' => self::days_schema(), 'output_schema' => array( 'type' => 'object' ), 'permission_callback' => $admin, 'execute_callback' => static function ( $input = array() ) use ( $days ) { $o = Aeoora_Stats::overview( $days( (array) $input ), 'ai' ); return array( 'kpis' => $o['kpis'], 'top_bots' => $o['top_bots'], 'top_pages' => $o['top_pages'], ); }, 'meta' => self::ro(), ) ); wp_register_ability( 'aeoora/get-ai-referrals', array( 'label' => __( 'Get AI referrals', 'aeoora' ), 'description' => __( 'Visitors sent by AI assistants (ChatGPT, Perplexity, Claude, Gemini, Copilot…), by source and landing page.', 'aeoora' ), 'category' => self::CATEGORY, 'input_schema' => self::days_schema(), 'output_schema' => array( 'type' => 'object' ), 'permission_callback' => $admin, 'execute_callback' => static function ( $input = array() ) use ( $days ) { $d = $days( (array) $input ); return array( 'by_source' => Aeoora_Stats::referrers( $d ), 'pages' => Aeoora_Stats::referral_pages( $d, 20 ), ); }, 'meta' => self::ro(), ) ); wp_register_ability( 'aeoora/get-post-aeo-score', array( 'label' => __( 'Get a post’s AEO score', 'aeoora' ), 'description' => __( 'Scores a post for AI-answer readiness and returns each check with its fix.', 'aeoora' ), 'category' => self::CATEGORY, 'input_schema' => array( 'type' => 'object', 'properties' => array( 'post_id' => array( 'type' => 'integer' ) ), 'required' => array( 'post_id' ), ), 'output_schema' => array( 'type' => 'object' ), 'permission_callback' => static function ( $input = array() ) { return isset( $input['post_id'] ) && current_user_can( 'edit_post', (int) $input['post_id'] ); }, 'execute_callback' => static function ( $input = array() ) { // Read-only: scores the rendered content without storing the result. $post = get_post( (int) $input['post_id'] ); if ( ! $post ) { return new WP_Error( 'aeoora_no_post', __( 'Post not found.', 'aeoora' ) ); } $r = Aeoora_Audit::score_post( $post, null, Aeoora_Content::render_html( $post ) ); unset( $r['stats'] ); return $r; }, 'meta' => self::ro(), ) ); wp_register_ability( 'aeoora/get-site-audit', array( 'label' => __( 'Get the site AEO audit', 'aeoora' ), 'description' => __( 'Technical AI-visibility audit of the site (robots.txt, server rendering, sitemap, schema, llms.txt…).', 'aeoora' ), 'category' => self::CATEGORY, 'input_schema' => array( 'type' => 'object', 'properties' => array( 'refresh' => array( 'type' => 'boolean', 'default' => false ) ), ), 'output_schema' => array( 'type' => 'object' ), 'permission_callback' => $admin, 'execute_callback' => static function ( $input = array() ) { return Aeoora_Audit::site( ! empty( $input['refresh'] ) ); }, // Not read-only: an outdated audit is re-run (requests to the site) and stored. 'meta' => array( 'show_in_rest' => true, 'annotations' => array( 'readonly' => false, 'destructive' => false, 'idempotent' => true, ), ), ) ); wp_register_ability( 'aeoora/set-crawler-policy', array( 'label' => __( 'Set a crawler policy', 'aeoora' ), 'description' => __( 'Allow, disallow (robots.txt) or block (HTTP 403) a crawler by its aeoora id, e.g. gptbot.', 'aeoora' ), 'category' => self::CATEGORY, 'input_schema' => array( 'type' => 'object', 'properties' => array( 'bot' => array( 'type' => 'string' ), 'policy' => array( 'type' => 'string', 'enum' => array( 'allow', 'disallow', 'block' ), ), ), 'required' => array( 'bot', 'policy' ), ), 'output_schema' => array( 'type' => 'object' ), 'permission_callback' => $admin, 'execute_callback' => static function ( $input = array() ) { $bot = sanitize_key( $input['bot'] ); if ( ! Aeoora_Bots::get( $bot ) ) { return new WP_Error( 'aeoora_unknown_bot', __( 'Unknown crawler id.', 'aeoora' ) ); } $policies = (array) Aeoora_Settings::get( 'robots', 'policies', array() ); if ( 'allow' === $input['policy'] ) { unset( $policies[ $bot ] ); } else { $policies[ $bot ] = $input['policy']; } Aeoora_Settings::update( array( 'robots' => array( 'policies' => $policies ) ) ); return array( 'bot' => $bot, 'policy' => Aeoora_Bots::policy( $bot ), ); }, 'meta' => array( 'show_in_rest' => true, 'annotations' => array( 'readonly' => false, 'destructive' => false, 'idempotent' => true, ), ), ) ); wp_register_ability( 'aeoora/regenerate-llms-txt', array( 'label' => __( 'Regenerate llms.txt', 'aeoora' ), 'description' => __( 'Rebuild /llms.txt and /llms-full.txt now.', 'aeoora' ), 'category' => self::CATEGORY, 'input_schema' => array( 'type' => 'object' ), 'output_schema' => array( 'type' => 'object' ), 'permission_callback' => $admin, 'execute_callback' => static function () { return Aeoora_Llms::regenerate(); }, 'meta' => array( 'show_in_rest' => true, 'annotations' => array( 'readonly' => false, 'destructive' => false, 'idempotent' => true, ), ), ) ); } }