diff --git a/includes/class-kgv-termine-plugin.php b/includes/class-kgv-termine-plugin.php index ce8a83f..0e3cdc8 100755 --- a/includes/class-kgv-termine-plugin.php +++ b/includes/class-kgv-termine-plugin.php @@ -25,6 +25,7 @@ class KGV_Termine_Plugin { add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_assets')); add_action('wp_enqueue_scripts', array($this, 'enqueue_front_assets')); add_action('init', array($this, 'register_shortcodes')); + add_action('init', array($this, 'maybe_upgrade_table')); add_action('admin_post_kgv_save_termin', array($this, 'handle_save_termin')); add_action('admin_post_kgv_delete_termin', array($this, 'handle_delete_termin')); add_filter('query_vars', array($this, 'register_query_vars')); @@ -51,6 +52,7 @@ class KGV_Termine_Plugin { is_published TINYINT(1) NOT NULL DEFAULT 1, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, + post_id BIGINT UNSIGNED NULL DEFAULT NULL, PRIMARY KEY (id), KEY event_date (event_date), KEY is_published (is_published) @@ -59,6 +61,40 @@ class KGV_Termine_Plugin { dbDelta($sql); } + public function maybe_upgrade_table() { + global $wpdb; + + $col = $wpdb->get_results( + $wpdb->prepare( + "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = 'post_id'", + DB_NAME, + $this->table_name + ) + ); + + if ( empty( $col ) ) { + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; + $charset_collate = $wpdb->get_charset_collate(); + $sql = "CREATE TABLE {$this->table_name} ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + title VARCHAR(255) NOT NULL, + event_date DATETIME NOT NULL, + owner VARCHAR(255) NULL, + location VARCHAR(255) NULL, + summary TEXT NULL, + description LONGTEXT NULL, + is_published TINYINT(1) NOT NULL DEFAULT 1, + created_at DATETIME NOT NULL, + updated_at DATETIME NOT NULL, + post_id BIGINT UNSIGNED NULL DEFAULT NULL, + PRIMARY KEY (id), + KEY event_date (event_date), + KEY is_published (is_published) + ) {$charset_collate};"; + dbDelta($sql); + } + } + public function enqueue_admin_assets($hook) { if (strpos((string) $hook, 'kgv-termine') === false) { return; @@ -161,6 +197,8 @@ class KGV_Termine_Plugin { $description = wp_kses_post(wp_unslash($_POST['description'] ?? '')); $is_published = isset($_POST['is_published']) ? (int) wp_unslash($_POST['is_published']) : 1; $is_published = $is_published === 1 ? 1 : 0; + $post_id = isset($_POST['post_id']) ? absint($_POST['post_id']) : 0; + $post_id = $post_id > 0 ? $post_id : null; if ($title === '' || $event_date === '' || strtotime($event_date) === false) { $target = $id ? admin_url('admin.php?page=kgv-termine-new&termin_id=' . $id . '&message=missing') : admin_url('admin.php?page=kgv-termine-new&message=missing'); @@ -179,10 +217,11 @@ class KGV_Termine_Plugin { 'summary' => $summary, 'description' => $description, 'is_published' => $is_published, + 'post_id' => $post_id, 'updated_at' => $now, ); - $formats = array('%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s'); + $formats = array('%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s'); if ($id) { $wpdb->update($this->table_name, $data, array('id' => $id), $formats, array('%d')); @@ -191,7 +230,7 @@ class KGV_Termine_Plugin { } $data['created_at'] = $now; - $wpdb->insert($this->table_name, $data, array('%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s')); + $wpdb->insert($this->table_name, $data, array('%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%s')); wp_safe_redirect(admin_url('admin.php?page=kgv-termine&message=created')); exit; @@ -269,6 +308,8 @@ class KGV_Termine_Plugin { $summary = $row ? $row->summary : ''; $description = $row ? $row->description : ''; $is_published = $row ? (int) $row->is_published : 1; + $post_id = $row && !empty($row->post_id) ? (int) $row->post_id : 0; + $posts = get_posts(array('post_type' => 'post', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC')); ?>
@@ -312,6 +353,16 @@ class KGV_Termine_Plugin {
+
+ + +
+
@@ -411,7 +462,14 @@ class KGV_Termine_Plugin { if (!empty($row->summary)) { echo '
' . esc_html($row->summary) . '
'; } - echo ''; + echo '
Details ansehen'; + if (!empty($row->post_id)) { + $post_url = get_permalink((int) $row->post_id); + if ($post_url) { + echo 'Mehr Infos'; + } + } + echo '
'; echo '
'; echo ''; } @@ -461,6 +519,12 @@ class KGV_Termine_Plugin { echo '

' . esc_html($row->summary) . '

'; } echo '
' . wpautop(wp_kses_post($row->description)) . '
'; + if (!empty($row->post_id)) { + $post_url = get_permalink((int) $row->post_id); + if ($post_url) { + echo '
Mehr Infos
'; + } + } echo '
'; echo ''; return ob_get_clean(); diff --git a/kgv-termine-plugin.php b/kgv-termine-plugin.php index 838c2eb..642789c 100755 --- a/kgv-termine-plugin.php +++ b/kgv-termine-plugin.php @@ -5,9 +5,11 @@ * 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.7 + * Version: 1.0.8 * Author: Ronny Grobel * Author URI: https://apex-project.de/ + * License: GPL v2 or later + * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Text Domain: kgv-termine-admin * Requires Plugins: KGV-Updater */ diff --git a/readme.txt b/readme.txt index aedc39d..63391e0 100755 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: ronnygrobel Tags: events, termine, kalender, verein, shortcode Requires at least: 6.0 Tested up to: 6.8 -Stable tag: 1.0.7 +Stable tag: 1.0.8 Requires PHP: 7.2 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -40,6 +40,9 @@ Ja, mit `[kgv_termine_sidebar]`. == Changelog == += 1.0.8 = +* Feature: Verknüpfung zu WordPress-Beiträgen. Im Termin kann ein Beitrag ausgewählt werden, der im Frontend als "Mehr Infos"-Button angezeigt wird. + = 1.0.7 = * Versionsabgleich zwischen Plugin-Header und Readme. * WordPress-Readme-Format weiter vereinheitlicht.