events()->find($event_id); } /** @return list */ function pcwp_get_occurrences(array $query = []): array { return ProCalendarWP\Plugin::instance()->events()->occurrences($query); } function pcwp_get_event_start(int $event_id, string $format = ''): string { $event = pcwp_get_event($event_id); if ($event === null) { return ''; } return $event->startLocal->format($format !== '' ? $format : get_option('date_format') . ' ' . get_option('time_format')); } function pcwp_get_event_end(int $event_id, string $format = ''): string { $event = pcwp_get_event($event_id); if ($event === null) { return ''; } return $event->endLocal->format($format !== '' ? $format : get_option('date_format') . ' ' . get_option('time_format')); } function pcwp_is_all_day(int $event_id): bool { return pcwp_get_event($event_id)?->allDay ?? false; } function pcwp_get_event_link(int $event_id): string { return (string) get_permalink($event_id); } /** @return list */ function pcwp_get_related_events(int $event_id, int $limit = 3): array { $category_ids = wp_get_post_terms($event_id, 'pcwp_event_category', ['fields' => 'ids']); if (is_wp_error($category_ids) || $category_ids === []) { return []; } $ids = get_posts([ 'post_type' => 'pcwp_event', 'post_status' => 'publish', 'post__not_in' => [$event_id], 'posts_per_page' => max(1, min(20, $limit)), 'fields' => 'ids', 'tax_query' => [[ 'taxonomy' => 'pcwp_event_category', 'field' => 'term_id', 'terms' => $category_ids, ]], ]); return array_values(array_filter(array_map(static fn (int $id) => pcwp_get_event($id), $ids))); }