true, 'show_in_rest' => true, 'has_archive' => true, 'rewrite' => ['with_front' => false], 'supports' => ['title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'custom-fields'], ]; register_post_type('pcwp_event', array_replace($common, [ 'labels' => $this->labels(__('Event', 'proeventswp'), __('Events', 'proeventswp')), 'menu_icon' => 'dashicons-calendar-alt', 'rewrite' => ['slug' => (string) get_option('pcwp_event_slug', 'events'), 'with_front' => false], 'capability_type' => ['pcwp_event', 'pcwp_events'], 'map_meta_cap' => true, ])); register_post_type('pcwp_venue', array_replace($common, [ 'labels' => $this->labels(__('Venue', 'proeventswp'), __('Venues', 'proeventswp')), 'rewrite' => ['slug' => (string) get_option('pcwp_venue_slug', 'venues'), 'with_front' => false], ])); register_post_type('pcwp_organizer', array_replace($common, [ 'labels' => $this->labels(__('Organizer', 'proeventswp'), __('Organizers', 'proeventswp')), 'rewrite' => ['slug' => (string) get_option('pcwp_organizer_slug', 'organizers'), 'with_front' => false], ])); register_post_type('pcwp_series', array_replace($common, [ 'labels' => $this->labels(__('Series', 'proeventswp'), __('Series', 'proeventswp')), 'show_ui' => true, 'rewrite' => ['slug' => (string) get_option('pcwp_series_slug', 'event-series'), 'with_front' => false], 'capability_type' => ['pcwp_event', 'pcwp_events'], 'map_meta_cap' => true, ])); register_taxonomy('pcwp_event_category', ['pcwp_event', 'pcwp_series'], [ 'labels' => $this->labels(__('Event category', 'proeventswp'), __('Event categories', 'proeventswp')), 'public' => true, 'show_in_rest' => true, 'hierarchical' => true, 'rewrite' => ['slug' => 'event-category', 'with_front' => false], ]); register_taxonomy('pcwp_event_tag', ['pcwp_event', 'pcwp_series'], [ 'labels' => $this->labels(__('Event tag', 'proeventswp'), __('Event tags', 'proeventswp')), 'public' => true, 'show_in_rest' => true, 'hierarchical' => false, 'rewrite' => ['slug' => 'event-tag', 'with_front' => false], ]); foreach (EventMeta::definitions() as $key => $definition) { if (($definition['type'] ?? '') === 'array') { $definition['show_in_rest'] = [ 'schema' => [ 'type' => 'array', 'items' => ['type' => 'string'], ], ]; } register_post_meta('pcwp_event', $key, array_merge([ 'single' => true, 'show_in_rest' => true, 'auth_callback' => static fn (): bool => current_user_can('edit_pcwp_events'), ], $definition)); } } /** @return array */ private function labels(string $singular, string $plural): array { return [ 'name' => $plural, 'singular_name' => $singular, /* translators: %s is the singular post-type label. */ 'add_new_item' => sprintf(__('Add new %s', 'proeventswp'), $singular), /* translators: %s is the singular post-type label. */ 'edit_item' => sprintf(__('Edit %s', 'proeventswp'), $singular), /* translators: %s is the singular post-type label. */ 'view_item' => sprintf(__('View %s', 'proeventswp'), $singular), /* translators: %s is the plural post-type label. */ 'search_items' => sprintf(__('Search %s', 'proeventswp'), $plural), ]; } }