,organizer:list} $entities */ public function replace(int $eventId, array $entities): void { global $wpdb; foreach ($entities as $type => $ids) { foreach ($ids as $id) { if (get_post_type($id) !== 'pcwp_' . $type || ! current_user_can('read_post', $id)) { throw new \InvalidArgumentException(__('The selected venue or organizer is unavailable.', 'proeventswp')); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception messages are data; REST encodes them and admin callers escape output. } } } $table = $wpdb->prefix . 'pcwp_event_entities'; if ($wpdb->delete($table, ['event_id' => $eventId], ['%d']) === false) { throw new \RuntimeException(__('Event relationships could not be saved.', 'proeventswp')); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception messages are data; REST encodes them and admin callers escape output. } foreach ($entities as $type => $ids) { foreach (array_values(array_unique($ids)) as $order => $id) { if ($wpdb->insert($table, ['event_id' => $eventId, 'entity_id' => $id, 'entity_type' => $type, 'sort_order' => $order], ['%d', '%d', '%s', '%d']) === false) { throw new \RuntimeException(__('Event relationships could not be saved.', 'proeventswp')); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception messages are data; REST encodes them and admin callers escape output. } } } WpEventRepository::clearEntityCache($eventId); } }