diff --git a/wp-multi-team-card.php b/wp-multi-team-card.php index 70f85d6..8f17d7c 100644 --- a/wp-multi-team-card.php +++ b/wp-multi-team-card.php @@ -1,359 +1,410 @@ - [ - 'name' => 'Teammitglieder', - 'singular_name' => 'Teammitglied', - 'add_new' => 'Neues Teammitglied', - 'add_new_item' => 'Teammitglied hinzufügen', - 'edit_item' => 'Teammitglied bearbeiten', - ], - 'public' => true, - 'show_ui' => false, // Standard-UI ausblenden - 'show_in_menu' => false, // Nicht im Hauptmenü anzeigen - 'menu_icon' => 'dashicons-groups', - 'supports' => ['title'], - 'has_archive' => false, - 'show_in_admin_bar' => false, - ]); - - register_taxonomy('teamcard_kategorie', 'teamcard', [ - 'labels' => [ - 'name' => 'Kategorien', - 'singular_name' => 'Kategorie', - ], - 'hierarchical' => true, - 'public' => true, - 'show_admin_column' => true, - ]); -} -add_action('init', 'teamcard_register_post_type'); - -// Admin-Menü hinzufügen -function teamcard_add_admin_menu() { - add_menu_page( - 'Teammitglieder verwalten', - 'Teamkarten', - 'manage_options', - 'teamcard_management', - 'teamcard_admin_page', - 'dashicons-groups', - 30 - ); -} -add_action('admin_menu', 'teamcard_add_admin_menu'); - -// Die Hauptverwaltungsseite -function teamcard_admin_page() { - ?> -
-

Teammitglieder verwalten

- - -
-

Neues Teammitglied hinzufügen

-
-
- - -
-
- - -
-
- - -
-
- -
- -
- - -
-
- -
-
-
- -

Vorhandene Teammitglieder

-

Ziehe die Zeilen, um die Reihenfolge zu ändern. Klicke auf die Felder, um sie zu bearbeiten.

- - - - - - - - - - - - - - 'teamcard', - 'posts_per_page' => -1, - 'orderby' => 'menu_order', - 'order' => 'ASC' - ]); - - foreach ($teamcards as $teamcard) { - $funktion = get_post_meta($teamcard->ID, '_teamcard_funktion', true); - $zustaendigkeit = get_post_meta($teamcard->ID, '_teamcard_zustaendigkeit', true); - $bild_id = get_post_meta($teamcard->ID, '_teamcard_bild_id', true); - $bild_url = $bild_id ? wp_get_attachment_image_url($bild_id, 'thumbnail') : ''; - ?> - - - - - - - - - -
BildNameFunktionZuständigkeitAktionen
-
- - - -
- -
-
post_title); ?>
-
-
-
-
-
- -
- - -
- 'teamcard', - 'posts_per_page' => 1, - 'orderby' => 'menu_order', - 'order' => 'DESC' - ]); - - if (!empty($posts)) { - $max_order = $posts[0]->menu_order; - } - - // Neuen Post erstellen - $post_id = wp_insert_post([ - 'post_type' => 'teamcard', - 'post_title' => $name, - 'post_status' => 'publish', - 'menu_order' => $max_order + 1 - ]); - - if ($post_id) { - update_post_meta($post_id, '_teamcard_funktion', $funktion); - update_post_meta($post_id, '_teamcard_zustaendigkeit', $zustaendigkeit); - - if ($bild_id > 0) { - update_post_meta($post_id, '_teamcard_bild_id', $bild_id); - } - - $bild_url = $bild_id ? wp_get_attachment_image_url($bild_id, 'thumbnail') : ''; - - wp_send_json_success([ - 'id' => $post_id, - 'bild_url' => $bild_url - ]); - } else { - wp_send_json_error(['message' => 'Fehler beim Erstellen des Teammitglieds']); - } - }); - - // Teammitglied aktualisieren - add_action('wp_ajax_update_teamcard', function() { - $post_id = intval($_POST['id']); - $field = sanitize_text_field($_POST['field']); - $value = sanitize_text_field($_POST['value']); - - if ($field === 'title') { - wp_update_post([ - 'ID' => $post_id, - 'post_title' => $value - ]); - } else { - update_post_meta($post_id, '_teamcard_' . $field, $value); - } - - wp_send_json_success(); - }); - - // Teammitglied löschen - add_action('wp_ajax_delete_teamcard', function() { - $post_id = intval($_POST['id']); - - if (wp_delete_post($post_id, true)) { - wp_send_json_success(); - } else { - wp_send_json_error(['message' => 'Fehler beim Löschen des Teammitglieds']); - } - }); - - // Bild aktualisieren - add_action('wp_ajax_update_teamcard_image', function() { - $post_id = intval($_POST['id']); - $bild_id = intval($_POST['bild_id']); - - update_post_meta($post_id, '_teamcard_bild_id', $bild_id); - $bild_url = wp_get_attachment_image_url($bild_id, 'thumbnail'); - - wp_send_json_success(['bild_url' => $bild_url]); - }); - - // Reihenfolge aktualisieren - add_action('wp_ajax_update_teamcard_order', function() { - $order = $_POST['order']; - - foreach ($order as $position => $post_id) { - wp_update_post([ - 'ID' => intval($post_id), - 'menu_order' => $position - ]); - } - - wp_send_json_success(); - }); -} -add_action('init', 'teamcard_ajax_handlers'); - -// Admin-Skripte und Styles laden -function teamcard_admin_scripts($hook) { - if ($hook !== 'toplevel_page_teamcard_management') return; - - wp_enqueue_media(); - wp_enqueue_script('jquery-ui-sortable'); - - wp_enqueue_style( - 'teamcard-admin-style', - plugin_dir_url(__FILE__) . 'teamcard-admin.css', - [], - '1.0' - ); - - wp_enqueue_script( - 'teamcard-admin-script', - plugin_dir_url(__FILE__) . 'teamcard-admin.js', - ['jquery', 'jquery-ui-sortable'], - '1.0', - true - ); - - wp_localize_script('teamcard-admin-script', 'teamcard_data', [ - 'ajax_url' => admin_url('admin-ajax.php'), - 'nonce' => wp_create_nonce('teamcard_nonce') - ]); -} -add_action('admin_enqueue_scripts', 'teamcard_admin_scripts'); - -// Shortcode für die Frontend-Anzeige -function teamcard_shortcode($atts) { - $atts = shortcode_atts([ - '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 '

Keine Teammitglieder gefunden.

'; - - ob_start(); - echo '
'; - 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 '
'; - - // Bild links - if ($bild_url) { - echo '
'; - echo ''; - echo '
'; - } - - // Text rechts - echo '
'; - echo '

' . get_the_title() . '

'; - echo '

' . esc_html($funktion) . '

'; - echo '

' . esc_html($zustaendigkeit) . '

'; - echo '
'; - - echo '
'; // Schließt die Teamcard-Div - } - echo '
'; // Schließt die Teamcard-Grid-Div - - wp_reset_postdata(); - return ob_get_clean(); -} +tag_name)) { + $latest_version = $release_data->tag_name; + + // If the latest version differs from the current version, show the banner + if ($latest_version !== $current_version) { + // Display the banner in the admin area + add_action('admin_notices', function() use ($latest_version) { + echo '
+

⚠️ Neue Version von WP Multi Teamcard verfügbar: Version ' . esc_html($latest_version) . ' ist jetzt auf Gitea verfügbar. Hier klicken, um die neue Version herunterzuladen. ⚠️

+
'; + }); + } + } +} + +// Hook into the admin init to check for updates +add_action('admin_init', 'check_for_new_release'); + + + + + + + +// CPT registrieren +function teamcard_register_post_type() { + register_post_type('teamcard', [ + 'labels' => [ + 'name' => 'Teammitglieder', + 'singular_name' => 'Teammitglied', + 'add_new' => 'Neues Teammitglied', + 'add_new_item' => 'Teammitglied hinzufügen', + 'edit_item' => 'Teammitglied bearbeiten', + ], + 'public' => true, + 'show_ui' => false, // Standard-UI ausblenden + 'show_in_menu' => false, // Nicht im Hauptmenü anzeigen + 'menu_icon' => 'dashicons-groups', + 'supports' => ['title'], + 'has_archive' => false, + 'show_in_admin_bar' => false, + ]); + + register_taxonomy('teamcard_kategorie', 'teamcard', [ + 'labels' => [ + 'name' => 'Kategorien', + 'singular_name' => 'Kategorie', + ], + 'hierarchical' => true, + 'public' => true, + 'show_admin_column' => true, + ]); +} +add_action('init', 'teamcard_register_post_type'); + +// Admin-Menü hinzufügen +function teamcard_add_admin_menu() { + add_menu_page( + 'Teammitglieder verwalten', + 'Teamkarten', + 'manage_options', + 'teamcard_management', + 'teamcard_admin_page', + 'dashicons-groups', + 30 + ); +} +add_action('admin_menu', 'teamcard_add_admin_menu'); + +// Die Hauptverwaltungsseite +function teamcard_admin_page() { + ?> +
+

Teammitglieder verwalten

+ + +
+

Neues Teammitglied hinzufügen

+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+ + +
+
+ +
+
+
+ +

Vorhandene Teammitglieder

+

Ziehe die Zeilen, um die Reihenfolge zu ändern. Klicke auf die Felder, um sie zu bearbeiten.

+ + + + + + + + + + + + + + 'teamcard', + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' + ]); + + foreach ($teamcards as $teamcard) { + $funktion = get_post_meta($teamcard->ID, '_teamcard_funktion', true); + $zustaendigkeit = get_post_meta($teamcard->ID, '_teamcard_zustaendigkeit', true); + $bild_id = get_post_meta($teamcard->ID, '_teamcard_bild_id', true); + $bild_url = $bild_id ? wp_get_attachment_image_url($bild_id, 'thumbnail') : ''; + ?> + + + + + + + + + +
BildNameFunktionZuständigkeitAktionen
+
+ + + +
+ +
+
post_title); ?>
+
+
+
+
+
+ +
+ + +
+ 'teamcard', + 'posts_per_page' => 1, + 'orderby' => 'menu_order', + 'order' => 'DESC' + ]); + + if (!empty($posts)) { + $max_order = $posts[0]->menu_order; + } + + // Neuen Post erstellen + $post_id = wp_insert_post([ + 'post_type' => 'teamcard', + 'post_title' => $name, + 'post_status' => 'publish', + 'menu_order' => $max_order + 1 + ]); + + if ($post_id) { + update_post_meta($post_id, '_teamcard_funktion', $funktion); + update_post_meta($post_id, '_teamcard_zustaendigkeit', $zustaendigkeit); + + if ($bild_id > 0) { + update_post_meta($post_id, '_teamcard_bild_id', $bild_id); + } + + $bild_url = $bild_id ? wp_get_attachment_image_url($bild_id, 'thumbnail') : ''; + + wp_send_json_success([ + 'id' => $post_id, + 'bild_url' => $bild_url + ]); + } else { + wp_send_json_error(['message' => 'Fehler beim Erstellen des Teammitglieds']); + } + }); + + // Teammitglied aktualisieren + add_action('wp_ajax_update_teamcard', function() { + $post_id = intval($_POST['id']); + $field = sanitize_text_field($_POST['field']); + $value = sanitize_text_field($_POST['value']); + + if ($field === 'title') { + wp_update_post([ + 'ID' => $post_id, + 'post_title' => $value + ]); + } else { + update_post_meta($post_id, '_teamcard_' . $field, $value); + } + + wp_send_json_success(); + }); + + // Teammitglied löschen + add_action('wp_ajax_delete_teamcard', function() { + $post_id = intval($_POST['id']); + + if (wp_delete_post($post_id, true)) { + wp_send_json_success(); + } else { + wp_send_json_error(['message' => 'Fehler beim Löschen des Teammitglieds']); + } + }); + + // Bild aktualisieren + add_action('wp_ajax_update_teamcard_image', function() { + $post_id = intval($_POST['id']); + $bild_id = intval($_POST['bild_id']); + + update_post_meta($post_id, '_teamcard_bild_id', $bild_id); + $bild_url = wp_get_attachment_image_url($bild_id, 'thumbnail'); + + wp_send_json_success(['bild_url' => $bild_url]); + }); + + // Reihenfolge aktualisieren + add_action('wp_ajax_update_teamcard_order', function() { + $order = $_POST['order']; + + foreach ($order as $position => $post_id) { + wp_update_post([ + 'ID' => intval($post_id), + 'menu_order' => $position + ]); + } + + wp_send_json_success(); + }); +} +add_action('init', 'teamcard_ajax_handlers'); + +// Admin-Skripte und Styles laden +function teamcard_admin_scripts($hook) { + if ($hook !== 'toplevel_page_teamcard_management') return; + + wp_enqueue_media(); + wp_enqueue_script('jquery-ui-sortable'); + + wp_enqueue_style( + 'teamcard-admin-style', + plugin_dir_url(__FILE__) . 'teamcard-admin.css', + [], + '1.0' + ); + + wp_enqueue_script( + 'teamcard-admin-script', + plugin_dir_url(__FILE__) . 'teamcard-admin.js', + ['jquery', 'jquery-ui-sortable'], + '1.0', + true + ); + + wp_localize_script('teamcard-admin-script', 'teamcard_data', [ + 'ajax_url' => admin_url('admin-ajax.php'), + 'nonce' => wp_create_nonce('teamcard_nonce') + ]); +} +add_action('admin_enqueue_scripts', 'teamcard_admin_scripts'); + +// Shortcode für die Frontend-Anzeige +function teamcard_shortcode($atts) { + $atts = shortcode_atts([ + '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 '

Keine Teammitglieder gefunden.

'; + + ob_start(); + echo '
'; + 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 '
'; + + // Bild links + if ($bild_url) { + echo '
'; + echo ''; + echo '
'; + } + + // Text rechts + echo '
'; + echo '

' . get_the_title() . '

'; + echo '

' . esc_html($funktion) . '

'; + echo '

' . esc_html($zustaendigkeit) . '

'; + echo '
'; + + echo '
'; // Schließt die Teamcard-Div + } + echo '
'; // Schließt die Teamcard-Grid-Div + + wp_reset_postdata(); + return ob_get_clean(); +} add_shortcode('teamcards', 'teamcard_shortcode'); \ No newline at end of file