Compare commits

..

No commits in common. "main" and "2.0" have entirely different histories.
main ... 2.0

2 changed files with 371 additions and 500 deletions

104
README.md
View File

@ -1,101 +1,23 @@
# WP Multi Team-Card
**Erstellt Teamkarten mit Name, Funktion, Zuständigkeit, Bild und Kategorie. Ausgabe per Shortcode `[teamcards]`.** ## Einstellungen im Backend
[![Letzte Version](https://img.shields.io/badge/Version-1.0-blue)](https://git.viper.ipv64.net/M_Viper/wp-multi-teamcard/releases) Im WordPress-Adminbereich kannst du Teammitglieder hinzufügen, bearbeiten und löschen. Jedes Teammitglied besteht aus den folgenden Feldern:
[Microsoft Teams Support](https://teams.live.com/l/community/FEAzokphpZTJ2u6OgI) • [Telegram Support](https://t.me/M_Viper04)
--- - **Name**
- **Funktion**
- **Zuständigkeit**
- **Bild**
- **Kategorie**
## Features ## Entwickeln
- Verwaltung von Teammitgliedern im WordPress-Backend Wenn du Änderungen am Plugin vornehmen möchtest, kannst du das Plugin nach Belieben anpassen. Achte darauf, dass du die richtigen Hooks und Filter verwendest, um deine Anpassungen mit zukünftigen Versionen kompatibel zu halten.
- Teamkarten mit Name, Funktion, Zuständigkeit, Bild und Kategorie
- Drag & Drop Sortierung und Inline-Bearbeitung im Backend
- Responsive Darstellung im Frontend
- Ausgabe per Shortcode `[teamcards]`
- Kategorien für Teammitglieder
- Bild-Upload und Vorschau
- Automatische Update-Benachrichtigung bei neuen Releases
--- ## Changelog
## Installation ### Version 1.0
- Erste Veröffentlichung des Plugins.
1. Lade das Plugin herunter oder klone das Repository: git clone https://git.viper.ipv64.net/M_Viper/wp-multi-teamcard.git
2. Kopiere den Ordner `wp-multi-teamcard` in dein WordPress-Plugin-Verzeichnis (`/wp-content/plugins/`).
3. Aktiviere das Plugin im WordPress-Backend unter „Plugins“.
**Mindestanforderungen:**
- WordPress 6.7.2 oder neuer
- PHP 7.2 oder neuer
---
## Nutzung
### Teammitglieder verwalten
Im WordPress-Backend erscheint ein Menüpunkt **Teamkarten**. Dort kannst du:
- Neue Teammitglieder hinzufügen (Name, Funktion, Zuständigkeit, Bild, Kategorie)
- Bestehende Teammitglieder bearbeiten (per Klick auf das jeweilige Feld)
- Reihenfolge per Drag & Drop ändern
- Teammitglieder löschen
- Bilder per Medienauswahl zuweisen oder ändern
### Shortcode
Gib den Shortcode überall im Editor ein, wo die Teamkarten angezeigt werden sollen: `[teamcards]`
**Optional:** Nach Kategorie filtern: `[teamcards kategorie="support"]`
Ersetze `"support"` durch den Slug der gewünschten Kategorie.
---
## Beispielausgabe (Frontend)
Die Teamkarten werden als responsive Grid angezeigt, z.B.:
+-------------------+----------------------------------+ </br>
| [Bild] | Name: Max Mustermann | </br>
| | Funktion: Support | </br>
| | Zuständigkeit: Kundenservice | </br>
+-------------------+----------------------------------+ </br>
---
## Entwickler-Infos
- **Custom Post Type:** `teamcard`
- **Taxonomie:** `teamcard_kategorie`
- **Shortcode:** `[teamcards]`
- **AJAX-Handler:** Hinzufügen, Bearbeiten, Löschen, Sortieren, Bild-Upload
- **Styles & Scripts:** Werden nur im Admin geladen
---
## Update-Hinweis
Das Plugin prüft automatisch, ob eine neue Version auf Gitea verfügbar ist, und zeigt einen Hinweis im Admin-Bereich an.
---
## Support
- [Microsoft Teams Community](https://teams.live.com/l/community/FEAzokphpZTJ2u6OgI)
- [Telegram Support](https://t.me/M_Viper04)
---
## Lizenz ## Lizenz
GPLv2 siehe [LICENSE](https://www.gnu.org/licenses/gpl-2.0.html) Dieses Plugin wird unter der GPL2-Lizenz veröffentlicht. Weitere Informationen findest du unter [GPL2 Lizenz](https://www.gnu.org/licenses/gpl-2.0.html).
---
## Autor
- **M_Viper**
- [m-viper.de](https://m-viper.de)

View File

@ -1,410 +1,359 @@
<?php <?php
/** /**
* Plugin Name: WP Multi Team-Card * Plugin Name: WP Multi Team-Card
* Plugin URI: https://git.viper.ipv64.net/M_Viper/wp-multi-teamcard * Plugin URI: https://git.viper.ipv64.net/M_Viper/wp-multi
* Description: Erstellt Teamkarten mit Name, Funktion, Zuständigkeit, Bild und Kategorie. Ausgabe per Shortcode [teamcards]. * Description: Erstellt Teamkarten mit Name, Funktion, Zuständigkeit, Bild und Kategorie. Ausgabe per Shortcode [teamcards].
* Version: 1.0 * Version: 1.0
* Author: M_Viper * Author: M_Viper
* Author URI: https://m-viper.de * Author URI: https://m-viper.de
* Requires at least: 6.7.2 * Requires at least: 6.7.2
* Tested up to: 6.7.2 * Tested up to: 6.7.2
* PHP Version: 7.2 * PHP Version: 7.2
* License: GPL2 * License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html * License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-multi-team-card * Text Domain: wp-multi-team-card
* Tags: team, card, shortcodes, team-management, customizable, responsive * Tags: team, card, shortcodes, team-management, customizable, responsive
* Support: [Microsoft Teams Support](https://teams.live.com/l/community/FEAzokphpZTJ2u6OgI) * Support: [Microsoft Teams Support](https://teams.live.com/l/community/FEAzokphpZTJ2u6OgI)
* Support: [Telegram Support](https://t.me/M_Viper04) * Support: [Telegram Support](https://t.me/M_Viper04)
*/ */
if (!defined('ABSPATH')) exit; if (!defined('ABSPATH')) exit;
// Check if the PHP version is sufficient // Check if the PHP version is sufficient
if (version_compare(PHP_VERSION, '7.2', '<')) { if (version_compare(PHP_VERSION, '7.2', '<')) {
die('This plugin requires PHP 7.2 or higher.'); die('This plugin requires PHP 7.2 or higher.');
} }
// Get the current version of the plugin from the plugin header dynamically // CPT registrieren
function get_current_plugin_version() { function teamcard_register_post_type() {
// Get the plugin data register_post_type('teamcard', [
$plugin_data = get_plugin_data(__FILE__); 'labels' => [
return $plugin_data['Version']; // Return the version from the plugin header 'name' => 'Teammitglieder',
} 'singular_name' => 'Teammitglied',
'add_new' => 'Neues Teammitglied',
$gitea_api_url = 'https://git.viper.ipv64.net/api/v1/repos/M_Viper/wp-multi-teamcard/releases/latest'; // Gitea API URL 'add_new_item' => 'Teammitglied hinzufügen',
'edit_item' => 'Teammitglied bearbeiten',
function check_for_new_release() { ],
global $gitea_api_url; 'public' => true,
'show_ui' => false, // Standard-UI ausblenden
// Get the current version dynamically from the plugin header 'show_in_menu' => false, // Nicht im Hauptmenü anzeigen
$current_version = get_current_plugin_version(); 'menu_icon' => 'dashicons-groups',
'supports' => ['title'],
// Fetch the latest release data from Gitea 'has_archive' => false,
$response = wp_remote_get($gitea_api_url); 'show_in_admin_bar' => false,
]);
// Check if there was an error with the API request
if (is_wp_error($response)) { register_taxonomy('teamcard_kategorie', 'teamcard', [
return; 'labels' => [
} 'name' => 'Kategorien',
'singular_name' => 'Kategorie',
$body = wp_remote_retrieve_body($response); ],
$release_data = json_decode($body); 'hierarchical' => true,
'public' => true,
// If release data is valid 'show_admin_column' => true,
if (isset($release_data->tag_name)) { ]);
$latest_version = $release_data->tag_name; }
add_action('init', 'teamcard_register_post_type');
// If the latest version differs from the current version, show the banner
if ($latest_version !== $current_version) { // Admin-Menü hinzufügen
// Display the banner in the admin area function teamcard_add_admin_menu() {
add_action('admin_notices', function() use ($latest_version) { add_menu_page(
echo '<div class="notice notice-info is-dismissible"> 'Teammitglieder verwalten',
<p><strong>⚠️ Neue Version von WP Multi Teamcard verfügbar:</strong> Version ' . esc_html($latest_version) . ' ist jetzt auf Gitea verfügbar. <a href="https://git.viper.ipv64.net/M_Viper/wp-multi-teamcard/releases" target="_blank">Hier klicken, um die neue Version herunterzuladen. ⚠️</a></p> 'Teamkarten',
</div>'; 'manage_options',
}); 'teamcard_management',
} 'teamcard_admin_page',
} 'dashicons-groups',
} 30
);
// Hook into the admin init to check for updates }
add_action('admin_init', 'check_for_new_release'); add_action('admin_menu', 'teamcard_add_admin_menu');
// Die Hauptverwaltungsseite
function teamcard_admin_page() {
?>
<div class="wrap teamcard-admin">
<h1>Teammitglieder verwalten</h1>
// CPT registrieren <!-- Formular zum Hinzufügen neuer Teammitglieder -->
function teamcard_register_post_type() { <div class="teamcard-add-new-form">
register_post_type('teamcard', [ <h2>Neues Teammitglied hinzufügen</h2>
'labels' => [ <div class="form-fields">
'name' => 'Teammitglieder', <div class="form-field">
'singular_name' => 'Teammitglied', <label for="new-teamcard-name">Name:</label>
'add_new' => 'Neues Teammitglied', <input type="text" id="new-teamcard-name" placeholder="Name eingeben">
'add_new_item' => 'Teammitglied hinzufügen', </div>
'edit_item' => 'Teammitglied bearbeiten', <div class="form-field">
], <label for="new-teamcard-funktion">Funktion:</label>
'public' => true, <input type="text" id="new-teamcard-funktion" placeholder="Funktion eingeben">
'show_ui' => false, // Standard-UI ausblenden </div>
'show_in_menu' => false, // Nicht im Hauptmenü anzeigen <div class="form-field">
'menu_icon' => 'dashicons-groups', <label for="new-teamcard-zustaendigkeit">Zuständigkeit:</label>
'supports' => ['title'], <input type="text" id="new-teamcard-zustaendigkeit" placeholder="Zuständigkeit eingeben">
'has_archive' => false, </div>
'show_in_admin_bar' => false, <div class="form-field">
]); <label>Bild:</label>
<div class="image-preview-container">
register_taxonomy('teamcard_kategorie', 'teamcard', [ <img id="new-teamcard-bild-vorschau" src="" style="display:none; max-width:100px;">
'labels' => [ </div>
'name' => 'Kategorien', <input type="hidden" id="new-teamcard-bild-id" value="">
'singular_name' => 'Kategorie', <button type="button" class="button" id="new-teamcard-bild-button">Bild auswählen</button>
], </div>
'hierarchical' => true, <div class="form-field">
'public' => true, <button type="button" id="add-teamcard-button" class="button button-primary">Teammitglied hinzufügen</button>
'show_admin_column' => true, </div>
]); </div>
} </div>
add_action('init', 'teamcard_register_post_type');
<h2>Vorhandene Teammitglieder</h2>
// Admin-Menü hinzufügen <p>Ziehe die Zeilen, um die Reihenfolge zu ändern. Klicke auf die Felder, um sie zu bearbeiten.</p>
function teamcard_add_admin_menu() {
add_menu_page( <!-- Liste der vorhandenen Teammitglieder -->
'Teammitglieder verwalten', <table class="wp-list-table widefat fixed striped">
'Teamkarten', <thead>
'manage_options', <tr>
'teamcard_management', <th width="10%">Bild</th>
'teamcard_admin_page', <th width="20%">Name</th>
'dashicons-groups', <th width="20%">Funktion</th>
30 <th width="30%">Zuständigkeit</th>
); <th width="20%">Aktionen</th>
} </tr>
add_action('admin_menu', 'teamcard_add_admin_menu'); </thead>
<tbody id="teamcard-list">
// Die Hauptverwaltungsseite <?php
function teamcard_admin_page() { $teamcards = get_posts([
?> 'post_type' => 'teamcard',
<div class="wrap teamcard-admin"> 'posts_per_page' => -1,
<h1>Teammitglieder verwalten</h1> 'orderby' => 'menu_order',
'order' => 'ASC'
<!-- Formular zum Hinzufügen neuer Teammitglieder --> ]);
<div class="teamcard-add-new-form">
<h2>Neues Teammitglied hinzufügen</h2> foreach ($teamcards as $teamcard) {
<div class="form-fields"> $funktion = get_post_meta($teamcard->ID, '_teamcard_funktion', true);
<div class="form-field"> $zustaendigkeit = get_post_meta($teamcard->ID, '_teamcard_zustaendigkeit', true);
<label for="new-teamcard-name">Name:</label> $bild_id = get_post_meta($teamcard->ID, '_teamcard_bild_id', true);
<input type="text" id="new-teamcard-name" placeholder="Name eingeben"> $bild_url = $bild_id ? wp_get_attachment_image_url($bild_id, 'thumbnail') : '';
</div> ?>
<div class="form-field"> <tr data-id="<?php echo $teamcard->ID; ?>" class="teamcard-item">
<label for="new-teamcard-funktion">Funktion:</label> <td class="teamcard-bild">
<input type="text" id="new-teamcard-funktion" placeholder="Funktion eingeben"> <div class="image-preview-container">
</div> <?php if ($bild_url): ?>
<div class="form-field"> <img src="<?php echo esc_url($bild_url); ?>" class="teamcard-bild-vorschau">
<label for="new-teamcard-zustaendigkeit">Zuständigkeit:</label> <?php endif; ?>
<input type="text" id="new-teamcard-zustaendigkeit" placeholder="Zuständigkeit eingeben"> </div>
</div> <button type="button" class="button teamcard-bild-button" data-id="<?php echo $teamcard->ID; ?>">Bild ändern</button>
<div class="form-field"> </td>
<label>Bild:</label> <td>
<div class="image-preview-container"> <div class="editable" data-field="title" data-id="<?php echo $teamcard->ID; ?>"><?php echo esc_html($teamcard->post_title); ?></div>
<img id="new-teamcard-bild-vorschau" src="" style="display:none; max-width:100px;"> </td>
</div> <td>
<input type="hidden" id="new-teamcard-bild-id" value=""> <div class="editable" data-field="funktion" data-id="<?php echo $teamcard->ID; ?>"><?php echo esc_html($funktion); ?></div>
<button type="button" class="button" id="new-teamcard-bild-button">Bild auswählen</button> </td>
</div> <td>
<div class="form-field"> <div class="editable" data-field="zustaendigkeit" data-id="<?php echo $teamcard->ID; ?>"><?php echo esc_html($zustaendigkeit); ?></div>
<button type="button" id="add-teamcard-button" class="button button-primary">Teammitglied hinzufügen</button> </td>
</div> <td>
</div> <button type="button" class="button button-small teamcard-delete" data-id="<?php echo $teamcard->ID; ?>">Löschen</button>
</div> </td>
</tr>
<h2>Vorhandene Teammitglieder</h2> <?php
<p>Ziehe die Zeilen, um die Reihenfolge zu ändern. Klicke auf die Felder, um sie zu bearbeiten.</p> }
?>
<!-- Liste der vorhandenen Teammitglieder --> </tbody>
<table class="wp-list-table widefat fixed striped"> </table>
<thead>
<tr> <div id="teamcard-message" class="notice" style="display:none;"></div>
<th width="10%">Bild</th> </div>
<th width="20%">Name</th> <?php
<th width="20%">Funktion</th> }
<th width="30%">Zuständigkeit</th>
<th width="20%">Aktionen</th> // AJAX-Handler zum Speichern der Teammitglieder
</tr> function teamcard_ajax_handlers() {
</thead> // Neues Teammitglied hinzufügen
<tbody id="teamcard-list"> add_action('wp_ajax_add_teamcard', function() {
<?php $name = sanitize_text_field($_POST['name']);
$teamcards = get_posts([ $funktion = sanitize_text_field($_POST['funktion']);
'post_type' => 'teamcard', $zustaendigkeit = sanitize_text_field($_POST['zustaendigkeit']);
'posts_per_page' => -1, $bild_id = intval($_POST['bild_id']);
'orderby' => 'menu_order',
'order' => 'ASC' // Höchste menu_order finden
]); $max_order = 0;
$posts = get_posts([
foreach ($teamcards as $teamcard) { 'post_type' => 'teamcard',
$funktion = get_post_meta($teamcard->ID, '_teamcard_funktion', true); 'posts_per_page' => 1,
$zustaendigkeit = get_post_meta($teamcard->ID, '_teamcard_zustaendigkeit', true); 'orderby' => 'menu_order',
$bild_id = get_post_meta($teamcard->ID, '_teamcard_bild_id', true); 'order' => 'DESC'
$bild_url = $bild_id ? wp_get_attachment_image_url($bild_id, 'thumbnail') : ''; ]);
?>
<tr data-id="<?php echo $teamcard->ID; ?>" class="teamcard-item"> if (!empty($posts)) {
<td class="teamcard-bild"> $max_order = $posts[0]->menu_order;
<div class="image-preview-container"> }
<?php if ($bild_url): ?>
<img src="<?php echo esc_url($bild_url); ?>" class="teamcard-bild-vorschau"> // Neuen Post erstellen
<?php endif; ?> $post_id = wp_insert_post([
</div> 'post_type' => 'teamcard',
<button type="button" class="button teamcard-bild-button" data-id="<?php echo $teamcard->ID; ?>">Bild ändern</button> 'post_title' => $name,
</td> 'post_status' => 'publish',
<td> 'menu_order' => $max_order + 1
<div class="editable" data-field="title" data-id="<?php echo $teamcard->ID; ?>"><?php echo esc_html($teamcard->post_title); ?></div> ]);
</td>
<td> if ($post_id) {
<div class="editable" data-field="funktion" data-id="<?php echo $teamcard->ID; ?>"><?php echo esc_html($funktion); ?></div> update_post_meta($post_id, '_teamcard_funktion', $funktion);
</td> update_post_meta($post_id, '_teamcard_zustaendigkeit', $zustaendigkeit);
<td>
<div class="editable" data-field="zustaendigkeit" data-id="<?php echo $teamcard->ID; ?>"><?php echo esc_html($zustaendigkeit); ?></div> if ($bild_id > 0) {
</td> update_post_meta($post_id, '_teamcard_bild_id', $bild_id);
<td> }
<button type="button" class="button button-small teamcard-delete" data-id="<?php echo $teamcard->ID; ?>">Löschen</button>
</td> $bild_url = $bild_id ? wp_get_attachment_image_url($bild_id, 'thumbnail') : '';
</tr>
<?php wp_send_json_success([
} 'id' => $post_id,
?> 'bild_url' => $bild_url
</tbody> ]);
</table> } else {
wp_send_json_error(['message' => 'Fehler beim Erstellen des Teammitglieds']);
<div id="teamcard-message" class="notice" style="display:none;"></div> }
</div> });
<?php
} // Teammitglied aktualisieren
add_action('wp_ajax_update_teamcard', function() {
// AJAX-Handler zum Speichern der Teammitglieder $post_id = intval($_POST['id']);
function teamcard_ajax_handlers() { $field = sanitize_text_field($_POST['field']);
// Neues Teammitglied hinzufügen $value = sanitize_text_field($_POST['value']);
add_action('wp_ajax_add_teamcard', function() {
$name = sanitize_text_field($_POST['name']); if ($field === 'title') {
$funktion = sanitize_text_field($_POST['funktion']); wp_update_post([
$zustaendigkeit = sanitize_text_field($_POST['zustaendigkeit']); 'ID' => $post_id,
$bild_id = intval($_POST['bild_id']); 'post_title' => $value
]);
// Höchste menu_order finden } else {
$max_order = 0; update_post_meta($post_id, '_teamcard_' . $field, $value);
$posts = get_posts([ }
'post_type' => 'teamcard',
'posts_per_page' => 1, wp_send_json_success();
'orderby' => 'menu_order', });
'order' => 'DESC'
]); // Teammitglied löschen
add_action('wp_ajax_delete_teamcard', function() {
if (!empty($posts)) { $post_id = intval($_POST['id']);
$max_order = $posts[0]->menu_order;
} if (wp_delete_post($post_id, true)) {
wp_send_json_success();
// Neuen Post erstellen } else {
$post_id = wp_insert_post([ wp_send_json_error(['message' => 'Fehler beim Löschen des Teammitglieds']);
'post_type' => 'teamcard', }
'post_title' => $name, });
'post_status' => 'publish',
'menu_order' => $max_order + 1 // Bild aktualisieren
]); add_action('wp_ajax_update_teamcard_image', function() {
$post_id = intval($_POST['id']);
if ($post_id) { $bild_id = intval($_POST['bild_id']);
update_post_meta($post_id, '_teamcard_funktion', $funktion);
update_post_meta($post_id, '_teamcard_zustaendigkeit', $zustaendigkeit); update_post_meta($post_id, '_teamcard_bild_id', $bild_id);
$bild_url = wp_get_attachment_image_url($bild_id, 'thumbnail');
if ($bild_id > 0) {
update_post_meta($post_id, '_teamcard_bild_id', $bild_id); wp_send_json_success(['bild_url' => $bild_url]);
} });
$bild_url = $bild_id ? wp_get_attachment_image_url($bild_id, 'thumbnail') : ''; // Reihenfolge aktualisieren
add_action('wp_ajax_update_teamcard_order', function() {
wp_send_json_success([ $order = $_POST['order'];
'id' => $post_id,
'bild_url' => $bild_url foreach ($order as $position => $post_id) {
]); wp_update_post([
} else { 'ID' => intval($post_id),
wp_send_json_error(['message' => 'Fehler beim Erstellen des Teammitglieds']); 'menu_order' => $position
} ]);
}); }
// Teammitglied aktualisieren wp_send_json_success();
add_action('wp_ajax_update_teamcard', function() { });
$post_id = intval($_POST['id']); }
$field = sanitize_text_field($_POST['field']); add_action('init', 'teamcard_ajax_handlers');
$value = sanitize_text_field($_POST['value']);
// Admin-Skripte und Styles laden
if ($field === 'title') { function teamcard_admin_scripts($hook) {
wp_update_post([ if ($hook !== 'toplevel_page_teamcard_management') return;
'ID' => $post_id,
'post_title' => $value wp_enqueue_media();
]); wp_enqueue_script('jquery-ui-sortable');
} else {
update_post_meta($post_id, '_teamcard_' . $field, $value); wp_enqueue_style(
} 'teamcard-admin-style',
plugin_dir_url(__FILE__) . 'teamcard-admin.css',
wp_send_json_success(); [],
}); '1.0'
);
// Teammitglied löschen
add_action('wp_ajax_delete_teamcard', function() { wp_enqueue_script(
$post_id = intval($_POST['id']); 'teamcard-admin-script',
plugin_dir_url(__FILE__) . 'teamcard-admin.js',
if (wp_delete_post($post_id, true)) { ['jquery', 'jquery-ui-sortable'],
wp_send_json_success(); '1.0',
} else { true
wp_send_json_error(['message' => 'Fehler beim Löschen des Teammitglieds']); );
}
}); wp_localize_script('teamcard-admin-script', 'teamcard_data', [
'ajax_url' => admin_url('admin-ajax.php'),
// Bild aktualisieren 'nonce' => wp_create_nonce('teamcard_nonce')
add_action('wp_ajax_update_teamcard_image', function() { ]);
$post_id = intval($_POST['id']); }
$bild_id = intval($_POST['bild_id']); add_action('admin_enqueue_scripts', 'teamcard_admin_scripts');
update_post_meta($post_id, '_teamcard_bild_id', $bild_id); // Shortcode für die Frontend-Anzeige
$bild_url = wp_get_attachment_image_url($bild_id, 'thumbnail'); function teamcard_shortcode($atts) {
$atts = shortcode_atts([
wp_send_json_success(['bild_url' => $bild_url]); 'kategorie' => '',
}); ], $atts);
// Reihenfolge aktualisieren $args = [
add_action('wp_ajax_update_teamcard_order', function() { 'post_type' => 'teamcard',
$order = $_POST['order']; 'posts_per_page' => -1,
'orderby' => 'menu_order',
foreach ($order as $position => $post_id) { 'order' => 'ASC',
wp_update_post([ ];
'ID' => intval($post_id),
'menu_order' => $position if ($atts['kategorie']) {
]); $args['tax_query'] = [[
} 'taxonomy' => 'teamcard_kategorie',
'field' => 'slug',
wp_send_json_success(); 'terms' => $atts['kategorie'],
}); ]];
} }
add_action('init', 'teamcard_ajax_handlers');
$query = new WP_Query($args);
// Admin-Skripte und Styles laden if (!$query->have_posts()) return '<p>Keine Teammitglieder gefunden.</p>';
function teamcard_admin_scripts($hook) {
if ($hook !== 'toplevel_page_teamcard_management') return; ob_start();
echo '<div class="teamcard-grid" style="display: flex; flex-wrap: wrap; gap: 20px;">';
wp_enqueue_media(); while ($query->have_posts()) {
wp_enqueue_script('jquery-ui-sortable'); $query->the_post();
$funktion = get_post_meta(get_the_ID(), '_teamcard_funktion', true);
wp_enqueue_style( $zustaendigkeit = get_post_meta(get_the_ID(), '_teamcard_zustaendigkeit', true);
'teamcard-admin-style', $bild_id = get_post_meta(get_the_ID(), '_teamcard_bild_id', true);
plugin_dir_url(__FILE__) . 'teamcard-admin.css', $bild_url = $bild_id ? wp_get_attachment_url($bild_id) : '';
[], echo '<div class="teamcard" style="display: flex; flex-wrap: wrap; border:1px solid #ccc; border-radius:10px; padding:15px; width:48%; align-items: center;">';
'1.0'
); // Bild links
if ($bild_url) {
wp_enqueue_script( echo '<div style="flex: 1; text-align: center; display: flex; justify-content: center; align-items: center; margin-right: 10px;">';
'teamcard-admin-script', echo '<img src="' . esc_url($bild_url) . '" style="max-width:100px; border-radius:50%; margin-bottom:0;">';
plugin_dir_url(__FILE__) . 'teamcard-admin.js', echo '</div>';
['jquery', 'jquery-ui-sortable'], }
'1.0',
true // Text rechts
); echo '<div style="flex: 2; padding-left: 10px;">';
echo '<h3>' . get_the_title() . '</h3>';
wp_localize_script('teamcard-admin-script', 'teamcard_data', [ echo '<p><strong>' . esc_html($funktion) . '</strong></p>';
'ajax_url' => admin_url('admin-ajax.php'), echo '<p>' . esc_html($zustaendigkeit) . '</p>';
'nonce' => wp_create_nonce('teamcard_nonce') echo '</div>';
]);
} echo '</div>'; // Schließt die Teamcard-Div
add_action('admin_enqueue_scripts', 'teamcard_admin_scripts'); }
echo '</div>'; // Schließt die Teamcard-Grid-Div
// Shortcode für die Frontend-Anzeige
function teamcard_shortcode($atts) { wp_reset_postdata();
$atts = shortcode_atts([ return ob_get_clean();
'kategorie' => '', }
], $atts);
$args = [
'post_type' => 'teamcard',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
];
if ($atts['kategorie']) {
$args['tax_query'] = [[
'taxonomy' => 'teamcard_kategorie',
'field' => 'slug',
'terms' => $atts['kategorie'],
]];
}
$query = new WP_Query($args);
if (!$query->have_posts()) return '<p>Keine Teammitglieder gefunden.</p>';
ob_start();
echo '<div class="teamcard-grid" style="display: flex; flex-wrap: wrap; gap: 20px;">';
while ($query->have_posts()) {
$query->the_post();
$funktion = get_post_meta(get_the_ID(), '_teamcard_funktion', true);
$zustaendigkeit = get_post_meta(get_the_ID(), '_teamcard_zustaendigkeit', true);
$bild_id = get_post_meta(get_the_ID(), '_teamcard_bild_id', true);
$bild_url = $bild_id ? wp_get_attachment_url($bild_id) : '';
echo '<div class="teamcard" style="display: flex; flex-wrap: wrap; border:1px solid #ccc; border-radius:10px; padding:15px; width:48%; align-items: center;">';
// Bild links
if ($bild_url) {
echo '<div style="flex: 1; text-align: center; display: flex; justify-content: center; align-items: center; margin-right: 10px;">';
echo '<img src="' . esc_url($bild_url) . '" style="max-width:100px; border-radius:50%; margin-bottom:0;">';
echo '</div>';
}
// Text rechts
echo '<div style="flex: 2; padding-left: 10px;">';
echo '<h3>' . get_the_title() . '</h3>';
echo '<p><strong>' . esc_html($funktion) . '</strong></p>';
echo '<p>' . esc_html($zustaendigkeit) . '</p>';
echo '</div>';
echo '</div>'; // Schließt die Teamcard-Div
}
echo '</div>'; // Schließt die Teamcard-Grid-Div
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode('teamcards', 'teamcard_shortcode'); add_shortcode('teamcards', 'teamcard_shortcode');