Feature: Link Termine to WordPress posts with Mehr Infos button
This commit is contained in:
@@ -25,6 +25,7 @@ class KGV_Termine_Plugin {
|
|||||||
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_assets'));
|
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_assets'));
|
||||||
add_action('wp_enqueue_scripts', array($this, 'enqueue_front_assets'));
|
add_action('wp_enqueue_scripts', array($this, 'enqueue_front_assets'));
|
||||||
add_action('init', array($this, 'register_shortcodes'));
|
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_save_termin', array($this, 'handle_save_termin'));
|
||||||
add_action('admin_post_kgv_delete_termin', array($this, 'handle_delete_termin'));
|
add_action('admin_post_kgv_delete_termin', array($this, 'handle_delete_termin'));
|
||||||
add_filter('query_vars', array($this, 'register_query_vars'));
|
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,
|
is_published TINYINT(1) NOT NULL DEFAULT 1,
|
||||||
created_at DATETIME NOT NULL,
|
created_at DATETIME NOT NULL,
|
||||||
updated_at DATETIME NOT NULL,
|
updated_at DATETIME NOT NULL,
|
||||||
|
post_id BIGINT UNSIGNED NULL DEFAULT NULL,
|
||||||
PRIMARY KEY (id),
|
PRIMARY KEY (id),
|
||||||
KEY event_date (event_date),
|
KEY event_date (event_date),
|
||||||
KEY is_published (is_published)
|
KEY is_published (is_published)
|
||||||
@@ -59,6 +61,40 @@ class KGV_Termine_Plugin {
|
|||||||
dbDelta($sql);
|
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) {
|
public function enqueue_admin_assets($hook) {
|
||||||
if (strpos((string) $hook, 'kgv-termine') === false) {
|
if (strpos((string) $hook, 'kgv-termine') === false) {
|
||||||
return;
|
return;
|
||||||
@@ -161,6 +197,8 @@ class KGV_Termine_Plugin {
|
|||||||
$description = wp_kses_post(wp_unslash($_POST['description'] ?? ''));
|
$description = wp_kses_post(wp_unslash($_POST['description'] ?? ''));
|
||||||
$is_published = isset($_POST['is_published']) ? (int) wp_unslash($_POST['is_published']) : 1;
|
$is_published = isset($_POST['is_published']) ? (int) wp_unslash($_POST['is_published']) : 1;
|
||||||
$is_published = $is_published === 1 ? 1 : 0;
|
$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) {
|
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');
|
$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,
|
'summary' => $summary,
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'is_published' => $is_published,
|
'is_published' => $is_published,
|
||||||
|
'post_id' => $post_id,
|
||||||
'updated_at' => $now,
|
'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) {
|
if ($id) {
|
||||||
$wpdb->update($this->table_name, $data, array('id' => $id), $formats, array('%d'));
|
$wpdb->update($this->table_name, $data, array('id' => $id), $formats, array('%d'));
|
||||||
@@ -191,7 +230,7 @@ class KGV_Termine_Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data['created_at'] = $now;
|
$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'));
|
wp_safe_redirect(admin_url('admin.php?page=kgv-termine&message=created'));
|
||||||
exit;
|
exit;
|
||||||
@@ -269,6 +308,8 @@ class KGV_Termine_Plugin {
|
|||||||
$summary = $row ? $row->summary : '';
|
$summary = $row ? $row->summary : '';
|
||||||
$description = $row ? $row->description : '';
|
$description = $row ? $row->description : '';
|
||||||
$is_published = $row ? (int) $row->is_published : 1;
|
$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'));
|
||||||
?>
|
?>
|
||||||
<div class="wrap kgv-admin-wrap">
|
<div class="wrap kgv-admin-wrap">
|
||||||
<div class="kgv-admin-header">
|
<div class="kgv-admin-header">
|
||||||
@@ -312,6 +353,16 @@ class KGV_Termine_Plugin {
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="kgv-form-field">
|
||||||
|
<label for="kgv-post-id">Verknüpfter Beitrag</label>
|
||||||
|
<select id="kgv-post-id" name="post_id">
|
||||||
|
<option value="0">— kein Beitrag —</option>
|
||||||
|
<?php foreach ($posts as $p) : ?>
|
||||||
|
<option value="<?php echo esc_attr($p->ID); ?>" <?php selected($post_id, $p->ID); ?>><?php echo esc_html($p->post_title); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="kgv-form-field kgv-form-field-full">
|
<div class="kgv-form-field kgv-form-field-full">
|
||||||
<label for="kgv-summary">Kurzbeschreibung</label>
|
<label for="kgv-summary">Kurzbeschreibung</label>
|
||||||
<textarea id="kgv-summary" name="summary" rows="3"><?php echo esc_textarea($summary); ?></textarea>
|
<textarea id="kgv-summary" name="summary" rows="3"><?php echo esc_textarea($summary); ?></textarea>
|
||||||
@@ -411,7 +462,14 @@ class KGV_Termine_Plugin {
|
|||||||
if (!empty($row->summary)) {
|
if (!empty($row->summary)) {
|
||||||
echo '<div class="kgv-termin-excerpt">' . esc_html($row->summary) . '</div>';
|
echo '<div class="kgv-termin-excerpt">' . esc_html($row->summary) . '</div>';
|
||||||
}
|
}
|
||||||
echo '<div class="kgv-termin-actions"><a class="kgv-termin-btn" href="' . esc_url($link) . '">Details ansehen</a></div>';
|
echo '<div class="kgv-termin-actions"><a class="kgv-termin-btn" href="' . esc_url($link) . '">Details ansehen</a>';
|
||||||
|
if (!empty($row->post_id)) {
|
||||||
|
$post_url = get_permalink((int) $row->post_id);
|
||||||
|
if ($post_url) {
|
||||||
|
echo '<a class="kgv-termin-btn kgv-termin-btn-secondary" href="' . esc_url($post_url) . '">Mehr Infos</a>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo '</div>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo '</article>';
|
echo '</article>';
|
||||||
}
|
}
|
||||||
@@ -461,6 +519,12 @@ class KGV_Termine_Plugin {
|
|||||||
echo '<p class="kgv-termin-summary"><strong>' . esc_html($row->summary) . '</strong></p>';
|
echo '<p class="kgv-termin-summary"><strong>' . esc_html($row->summary) . '</strong></p>';
|
||||||
}
|
}
|
||||||
echo '<div class="kgv-termin-content">' . wpautop(wp_kses_post($row->description)) . '</div>';
|
echo '<div class="kgv-termin-content">' . wpautop(wp_kses_post($row->description)) . '</div>';
|
||||||
|
if (!empty($row->post_id)) {
|
||||||
|
$post_url = get_permalink((int) $row->post_id);
|
||||||
|
if ($post_url) {
|
||||||
|
echo '<div class="kgv-termin-more-info"><a class="kgv-termin-btn" href="' . esc_url($post_url) . '">Mehr Infos</a></div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo '</article>';
|
echo '</article>';
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
|
|||||||
@@ -5,9 +5,11 @@
|
|||||||
* Description: Eigene Terminverwaltung mit separatem Admin-Interface, Frontend-Liste und Detailansicht per Shortcode.
|
* 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
|
* 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
|
* 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: Ronny Grobel
|
||||||
* Author URI: https://apex-project.de/
|
* 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
|
* Text Domain: kgv-termine-admin
|
||||||
* Requires Plugins: KGV-Updater
|
* Requires Plugins: KGV-Updater
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ Contributors: ronnygrobel
|
|||||||
Tags: events, termine, kalender, verein, shortcode
|
Tags: events, termine, kalender, verein, shortcode
|
||||||
Requires at least: 6.0
|
Requires at least: 6.0
|
||||||
Tested up to: 6.8
|
Tested up to: 6.8
|
||||||
Stable tag: 1.0.7
|
Stable tag: 1.0.8
|
||||||
Requires PHP: 7.2
|
Requires PHP: 7.2
|
||||||
License: GPLv2 or later
|
License: GPLv2 or later
|
||||||
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
@@ -40,6 +40,9 @@ Ja, mit `[kgv_termine_sidebar]`.
|
|||||||
|
|
||||||
== Changelog ==
|
== 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 =
|
= 1.0.7 =
|
||||||
* Versionsabgleich zwischen Plugin-Header und Readme.
|
* Versionsabgleich zwischen Plugin-Header und Readme.
|
||||||
* WordPress-Readme-Format weiter vereinheitlicht.
|
* WordPress-Readme-Format weiter vereinheitlicht.
|
||||||
|
|||||||
Reference in New Issue
Block a user