array( 'type' => 'object', 'description' => __( 'Post id => score from 0 to 100.', 'acrossai-abilities-manager' ), 'additionalProperties' => true, ), 'source' => array( 'type' => 'string', 'enum' => Post_Meta_Repository::SCORE_SOURCES, 'default' => 'agent', 'description' => __( 'Where these scores came from. Use "agent" when you graded the post yourself against the rubric from rank-math/analyze-post-content — this is the normal case and the default. Use "rank-math-analyzer" only for numbers Rank Math\'s own browser analyzer produced, such as those read off its Update SEO Scores tool. Recording this honestly is the point: the two do not always agree.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'updated' => array( 'type' => 'array' ), 'skipped' => array( 'type' => 'array' ), 'scored_at' => array( 'type' => 'string', 'description' => __( 'GMT timestamp stamped on every score in this batch.', 'acrossai-abilities-manager' ), ), 'source' => array( 'type' => 'string' ), ); } protected function required_input(): array { return array( 'scores' ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { if ( ! isset( $input['scores'] ) || ! is_array( $input['scores'] ) ) { return new WP_Error( 'invalid_input', __( 'scores must be an object keyed by post id.', 'acrossai-abilities-manager' ) ); } $source = isset( $input['source'] ) ? (string) $input['source'] : 'agent'; $result = Post_Meta_Repository::update_seo_scores( $input['scores'], $source ); if ( is_wp_error( $result ) ) { return $result; } $result['message'] = sprintf( /* translators: 1: number of scores written, 2: number skipped, 3: score source */ __( 'Wrote %1$d SEO scores, skipped %2$d. Recorded source: %3$s.', 'acrossai-abilities-manager' ), count( $result['updated'] ), count( $result['skipped'] ), $result['source'] ); return $result; } }