From 56c88eb4b37ab8d06e8aaa8e43a2a7d5d1637cc6 Mon Sep 17 00:00:00 2001 From: Ronny Grobel Date: Wed, 15 Apr 2026 21:26:00 +0200 Subject: [PATCH] Fix detail links outside Termine page and bump version to 1.0.6 --- includes/class-kgv-termine-plugin.php | 58 ++++++++++++++++++++++++++- kgv-termine-plugin.php | 2 +- readme.txt | 2 +- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/includes/class-kgv-termine-plugin.php b/includes/class-kgv-termine-plugin.php index dbf202b..ce8a83f 100755 --- a/includes/class-kgv-termine-plugin.php +++ b/includes/class-kgv-termine-plugin.php @@ -372,6 +372,7 @@ class KGV_Termine_Plugin { $atts = shortcode_atts(array( 'limit' => 0, 'detail' => 1, + 'base_url' => '', ), $atts, 'kgv_termine'); $detail_id = absint(get_query_var('kgv_termin')); @@ -379,7 +380,7 @@ class KGV_Termine_Plugin { $detail_id = absint(wp_unslash($_GET['kgv_termin'])); } - $base_url = $this->get_current_page_url(false); + $base_url = $this->resolve_termine_base_url($atts['base_url']); if ($detail_id && (int) $atts['detail'] === 1) { return $this->render_detail_by_id($detail_id, $base_url); @@ -470,6 +471,7 @@ class KGV_Termine_Plugin { public function render_sidebar_shortcode($atts) { $atts = shortcode_atts(array( 'limit' => 5, + 'base_url' => '', ), $atts, 'kgv_termine_sidebar'); $rows = $this->get_frontend_rows(max(1, min(20, absint($atts['limit'])))); @@ -478,7 +480,7 @@ public function render_sidebar_shortcode($atts) { return '
Keine Termine
'; } - $base_url = $this->get_current_page_url(false); + $base_url = $this->resolve_termine_base_url($atts['base_url']); ob_start(); echo '
'; @@ -499,6 +501,58 @@ public function render_sidebar_shortcode($atts) { return ob_get_clean(); } + + private function resolve_termine_base_url($base_url = '') { + if (!empty($base_url)) { + $clean_url = esc_url_raw((string) $base_url); + if ($clean_url) { + return remove_query_arg(array_keys($_GET), $clean_url); + } + } + + $shortcode_page_url = $this->find_termine_shortcode_page_url(); + if ($shortcode_page_url) { + return $shortcode_page_url; + } + + return $this->get_current_page_url(false); + } + + private function find_termine_shortcode_page_url() { + static $cached_url = null; + + if (null !== $cached_url) { + return $cached_url; + } + + global $wpdb; + + $like = '%' . $wpdb->esc_like('[kgv_termine') . '%'; + $post_id = (int) $wpdb->get_var( + $wpdb->prepare( + "SELECT ID + FROM {$wpdb->posts} + WHERE post_status = 'publish' + AND post_type IN ('page', 'post') + AND post_content LIKE %s + ORDER BY CASE WHEN post_type = 'page' THEN 0 ELSE 1 END, ID ASC + LIMIT 1", + $like + ) + ); + + if ($post_id) { + $permalink = get_permalink($post_id); + if ($permalink) { + $cached_url = remove_query_arg(array_keys($_GET), $permalink); + return $cached_url; + } + } + + $cached_url = ''; + return $cached_url; + } + private function get_current_page_url($with_query = true) { $page_url = ''; diff --git a/kgv-termine-plugin.php b/kgv-termine-plugin.php index dd94e54..a2e1339 100755 --- a/kgv-termine-plugin.php +++ b/kgv-termine-plugin.php @@ -5,7 +5,7 @@ * Description: Eigene Terminverwaltung mit separatem Admin-Interface, Frontend-Liste und Detailansicht per Shortcode. * Update URI: https://git.apex-project.de/Wordpress_Plugins/KGV-Termine.git * Gitea Plugin URI: https://git.apex-project.de/Wordpress_Plugins/KGV-Termine.git - * Version: 1.0.5 + * Version: 1.0.6 * Author: Ronny Grobel * Author URI: https://apex-project.de/ * Text Domain: kgv-termine-admin diff --git a/readme.txt b/readme.txt index b28f565..f748c64 100755 --- a/readme.txt +++ b/readme.txt @@ -13,4 +13,4 @@ Funktionen: - Ausgabe der Termine im Frontend - einfache Pflege für Vereins- und Veranstaltungsseiten -Version: 1.0.2 +Version: 1.0.6