settings = $settings; } /** * Submit definitions to AO; only the shared registry calls the native API. * * @param Abilities_Registry $registry Shared request-local registry. * @return array Queue results by ability name. */ public function register( Abilities_Registry $registry ): array { $results = []; foreach ( $this->get_abilities() as $name => $definition ) { $results[ $name ] = $registry->register( $name, $definition ); } return $results; } /** @return array Native definitions owned by this module. */ protected function get_abilities(): array { return [ 'admin-optimizer/get-seo-health' => [ 'label' => __( 'Get SEO Health', 'admin-optimizer' ), 'description' => __( 'Return the cached site-level SEO Health checks, score, status counts, and generation time.', 'admin-optimizer' ), 'category' => 'admin-optimizer', 'input_schema' => [ 'type' => 'object', 'additionalProperties' => false, 'default' => new \stdClass(), ], 'output_schema' => [ 'type' => 'object', 'required' => [ 'checks', 'status_count', 'score', 'generated_at' ], 'properties' => [ 'checks' => [ 'type' => 'array', 'items' => [ 'type' => 'object', 'properties' => [ 'id' => [ 'type' => 'string' ], 'label' => [ 'type' => 'string' ], 'status' => [ 'type' => 'string' ], 'message' => [ 'type' => 'string' ], ], // Preserve fields supplied by the existing health filter. 'additionalProperties' => true, ], ], 'status_count' => [ 'type' => 'object', 'properties' => [ 'pass' => [ 'type' => 'integer', 'minimum' => 0, ], 'warning' => [ 'type' => 'integer', 'minimum' => 0, ], 'critical' => [ 'type' => 'integer', 'minimum' => 0, ], 'info' => [ 'type' => 'integer', 'minimum' => 0, ], ], ], 'score' => [ 'type' => 'integer', 'minimum' => 0, 'maximum' => 100, ], 'generated_at' => [ 'type' => 'integer', 'minimum' => 0, ], ], ], 'execute_callback' => [ $this, 'execute_get_seo_health' ], 'permission_callback' => [ $this, 'can_get_seo_health' ], 'meta' => [ 'show_in_rest' => true, 'mcp' => [ 'public' => true, ], 'annotations' => [ 'readonly' => true, 'destructive' => false, 'idempotent' => true, ], // Admin Optimizer presentation only (AI Access tab). 'adminoptimizer' => [ 'module' => 'seo_manager', 'summary' => __( 'Reads SEO health checks, status counts and the overall score.', 'admin-optimizer' ), ], ], ], ]; } /** * @param mixed $input Optional empty object; no parameters are accepted. * @return array|\WP_Error Existing dashboard result or a permission error. */ public function execute_get_seo_health( $input = null ) { // Also protect direct PHP callers; native execution checks this first. if ( ! $this->can_get_seo_health( $input ) ) { return new \WP_Error( 'ao_seo_health_forbidden', __( 'You are not allowed to view SEO Health.', 'admin-optimizer' ) ); } return $this->settings->get_seo_health_results(); } /** * @param mixed $input Unused; matches the native permission callback contract. * @return bool Whether the user may view site-level SEO Health information. */ public function can_get_seo_health( $input = null ): bool { return current_user_can( 'manage_options' ); } }