*/ private function content(): array { $header = '
'; $footer = '
'; $title = ''; $details = ''; $events = '[pcwp_entity_events]'; return [ 'archive-pcwp_event' => $header . '

' . esc_html__('Upcoming events', 'proeventswp') . '

' . $footer, 'single-pcwp_event' => $header . $title . '' . $details . '' . $footer, 'single-pcwp_venue' => $header . $title . '' . $events . $footer, 'single-pcwp_organizer' => $header . $title . '' . $events . $footer, 'single-pcwp_series' => $header . $title . '' . $events . $footer, ]; } public function templates(): void { if (function_exists('register_block_template')) { foreach ($this->content() as $slug => $content) { register_block_template('proeventswp//' . $slug, ['title' => ucwords(str_replace(['single-pcwp_', 'archive-pcwp_', '_'], ['', '', ' '], $slug)), 'description' => __('Editable ProEventsWP event layout.', 'proeventswp'), 'content' => $content, 'plugin' => 'proeventswp']); } } } private function object(string $slug, string $content): \WP_Block_Template { $template = new \WP_Block_Template(); $template->id = get_stylesheet() . '//' . $slug; $template->theme = get_stylesheet(); $template->slug = $slug; $template->type = 'wp_template'; $template->source = 'plugin'; $template->title = ucwords(str_replace(['single-pcwp_', 'archive-pcwp_'], '', $slug)); $template->content = $content; $template->status = 'publish'; return $template; } /** * @param list<\WP_Block_Template> $templates * @param array $query * @return list<\WP_Block_Template> */ public function fallbacks(array $templates, array $query, string $type): array { if (function_exists('register_block_template') || $type !== 'wp_template') { return $templates; } $existing = array_column($templates, 'slug'); foreach ($this->content() as $slug => $content) { if (! in_array($slug, $existing, true) && (empty($query['slug__in']) || in_array($slug, $query['slug__in'], true))) { $templates[] = $this->object($slug, $content); } } return $templates; } public function fallback(?\WP_Block_Template $template, string $id, string $type): ?\WP_Block_Template { if ($template !== null || $type !== 'wp_template') { return $template; } $slug = explode('//', $id)[1] ?? ''; $content = $this->content(); return isset($content[$slug]) ? $this->object($slug, $content[$slug]) : null; } public function classic(string $template): string { if (wp_is_block_theme()) { return $template; } if (is_post_type_archive('pcwp_event')) { return $template; } if (! is_singular(['pcwp_event', 'pcwp_venue', 'pcwp_organizer', 'pcwp_series'])) { return $template; } $specific = locate_template('single-' . get_post_type() . '.php'); return $specific !== '' ? $template : PCWP_PATH . 'templates/single-event.php'; } public function entityEvents(): string { $id = get_queried_object_id(); $type = get_post_type($id); $key = ['pcwp_venue' => 'venue', 'pcwp_organizer' => 'organizer', 'pcwp_series' => 'series'][$type] ?? ''; return $key === '' ? '' : (new ViewRenderer(\ProCalendarWP\Plugin::instance()->events()))->render([$key => $id, 'view' => 'list', 'past_events' => false, 'filter_bar' => false, 'instance' => 'entity-' . $id]); } }