array( 'type' => 'integer', 'minimum' => 1, 'description' => __( 'The event ID.', 'acrossai-abilities-manager' ), ), 'term_ids' => array( 'type' => 'array', 'items' => array( 'type' => 'integer' ), 'description' => __( 'Event category term IDs.', 'acrossai-abilities-manager' ), ), 'mode' => array( 'type' => 'string', 'enum' => array( 'replace', 'add', 'remove' ), 'default' => 'replace', 'description' => __( 'replace sets exactly these, add appends, remove detaches.', 'acrossai-abilities-manager' ), ), ); } protected function required_input(): array { return array( 'id', 'term_ids' ); } protected function output_properties(): array { return array( 'categories' => array( 'type' => 'array' ), ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true, ); } protected function run( array $input ) { $id = (int) $input['id']; $event = Event_Repository::require_post( $id, 'event' ); if ( is_wp_error( $event ) ) { return $event; } $mode = isset( $input['mode'] ) ? (string) $input['mode'] : 'replace'; $terms = array_map( 'absint', (array) $input['term_ids'] ); $rows = Event_Repository::set_categories( $id, $terms, $mode ); if ( is_wp_error( $rows ) ) { return $rows; } return array( 'categories' => $rows, 'message' => sprintf( /* translators: 1: event ID, 2: resulting category count */ __( 'Event %1$d now has %2$d categor(ies).', 'acrossai-abilities-manager' ), $id, count( $rows ) ), ); } }