__( 'AI-Ready WP', 'ai-ready-wp' ), 'description' => __( 'AI discovery abilities exposed by AI-Ready WP for AI agents and the WordPress MCP Adapter.', 'ai-ready-wp' ), ] ); } /** * Register AI-Ready abilities via the WP Abilities API. */ public function register_abilities(): void { $settings = AI_Ready_WP::get_settings(); // Business information ability wp_register_ability( 'airewp/get-business-info', [ 'label' => __( 'Get Business Information', 'ai-ready-wp' ), 'description' => sprintf( /* translators: %s: Company/site name */ __( 'Get contact, services, and location information for %s.', 'ai-ready-wp' ), $settings['company_name'] ?: get_bloginfo( 'name' ) ), 'category' => self::CATEGORY, 'input_schema' => [ 'type' => 'object', 'properties' => [], ], 'output_schema' => [ 'type' => 'object', 'properties' => [ 'name' => [ 'type' => 'string' ], 'description' => [ 'type' => 'string' ], 'contact' => [ 'type' => 'object' ], 'address' => [ 'type' => 'object' ], 'services' => [ 'type' => 'array' ], ], ], 'execute_callback' => function () use ( $settings ) { return [ 'name' => $settings['company_name'], 'description' => $settings['company_desc'], 'url' => home_url(), 'industry' => $settings['industry'], 'contact' => [ 'email' => $settings['company_email'], 'phone' => $settings['company_phone'], ], 'address' => [ 'street' => $settings['company_address'], 'city' => $settings['company_city'], 'zip' => $settings['company_zip'], 'country' => $settings['company_country'], ], 'services' => ! empty( $settings['services'] ) ? array_map( 'trim', explode( ',', $settings['services'] ) ) : [], ]; }, 'permission_callback' => '__return_true', ] ); // AI Readiness check ability wp_register_ability( 'airewp/get-readiness', [ 'label' => __( 'Get AI-Readiness Score', 'ai-ready-wp' ), 'description' => __( 'Check the AI-readiness score of this website.', 'ai-ready-wp' ), 'category' => self::CATEGORY, 'input_schema' => [ 'type' => 'object', 'properties' => [], ], 'output_schema' => [ 'type' => 'object', 'properties' => [ 'score' => [ 'type' => 'integer' ], 'max' => [ 'type' => 'integer' ], 'checks' => [ 'type' => 'array' ], ], ], 'execute_callback' => function () use ( $settings ) { $checks = AIREWP_Dashboard::get_checks( $settings ); $score = AIREWP_Dashboard::calculate_score( $settings ); return [ 'score' => $score, 'max' => 10, 'checks' => array_map( function ( $c ) { return [ 'check' => $c['label'], 'passed' => $c['pass'] ]; }, $checks ), ]; }, 'permission_callback' => '__return_true', ] ); // Content search ability wp_register_ability( 'airewp/search-content', [ 'label' => __( 'Search Website Content', 'ai-ready-wp' ), 'description' => __( 'Search pages and posts on this website.', 'ai-ready-wp' ), 'category' => self::CATEGORY, 'input_schema' => [ 'type' => 'object', 'properties' => [ 'query' => [ 'type' => 'string', 'description' => 'Search query', ], ], 'required' => [ 'query' ], ], 'output_schema' => [ 'type' => 'object', 'properties' => [ 'results' => [ 'type' => 'array' ], ], ], 'execute_callback' => function ( $params ) { $query = sanitize_text_field( $params['query'] ?? '' ); if ( empty( $query ) ) { return [ 'results' => [] ]; } $search = new WP_Query( [ 'post_type' => [ 'page', 'post' ], 'post_status' => 'publish', 's' => $query, 'posts_per_page' => 10, ] ); $results = []; foreach ( $search->posts as $post ) { $results[] = [ 'title' => $post->post_title, 'url' => get_permalink( $post ), 'type' => $post->post_type, 'excerpt' => wp_strip_all_tags( get_the_excerpt( $post ) ), ]; } wp_reset_postdata(); return [ 'results' => $results ]; }, 'permission_callback' => '__return_true', ] ); // Service listing ability (if services defined) if ( ! empty( $settings['services'] ) ) { wp_register_ability( 'airewp/get-services', [ 'label' => __( 'Get Service Listing', 'ai-ready-wp' ), 'description' => sprintf( /* translators: %s: Company/site name */ __( 'Get the list of services offered by %s.', 'ai-ready-wp' ), $settings['company_name'] ?: get_bloginfo( 'name' ) ), 'category' => self::CATEGORY, 'input_schema' => [ 'type' => 'object', 'properties' => [], ], 'output_schema' => [ 'type' => 'object', 'properties' => [ 'services' => [ 'type' => 'array' ], ], ], 'execute_callback' => function () use ( $settings ) { return [ 'company' => $settings['company_name'], 'services' => array_map( 'trim', explode( ',', $settings['services'] ) ), ]; }, 'permission_callback' => '__return_true', ] ); } do_action( 'airewp_register_abilities', $settings ); } }