commit 56383ab109628b48d1ab4f8d28b9c63ecd16238b Author: Victor Giers Date: Fri Feb 7 22:49:36 2025 +0100 ordinary entry selector for wordpress, initial commit diff --git a/ai-translate.php b/ai-translate.php new file mode 100644 index 0000000..f7c3339 --- /dev/null +++ b/ai-translate.php @@ -0,0 +1,247 @@ +

Auswahl hinzugefügt.

'; + } + // Einzelnen Eintrag entfernen + if ( isset( $_GET['remove'] ) ) { + $remove_id = intval( $_GET['remove'] ); + $current = get_option( 'ait_selected_posts', [] ); + if ( ( $key = array_search( $remove_id, $current ) ) !== false ) { + unset( $current[ $key ] ); + update_option( 'ait_selected_posts', $current ); + echo '

Eintrag entfernt.

'; + } + } +} + +/** + * Fügt das Admin-Menü hinzu. + */ +function ait_add_admin_menu() { + add_menu_page( 'AI Translate', 'AI Translate', 'manage_options', 'ai-translate', 'ait_admin_page', 'dashicons-translation', 25 ); +} +add_action( 'admin_menu', 'ait_add_admin_menu' ); + +/** + * Zeigt die Admin-Seite an. + */ +function ait_admin_page() { + // Zuerst werden alle Formular-/URL-Anfragen verarbeitet. + ait_handle_form_submissions(); + + $current_tab = $_GET['tab'] ?? 'post'; + ?> +
+

AI Translate

+ + + +
+ +
+ + + + + +
+ '; + echo '

Gespeicherte Auswahl

'; + if ( ! empty( $selected_posts ) ) { + echo '
'; + $titles = []; + // Optional: Debug-Ausgabe (z.B. per error_log) + // error_log("Gespeicherte Auswahl: " . implode(', ', $selected_posts)); + foreach ( $selected_posts as $post_id ) { + $post = get_post( $post_id ); + if ( $post && ! empty( $post->post_title ) ) { + $remove_url = add_query_arg( [ 'remove' => $post_id, 'tab' => $current_tab ], admin_url( 'admin.php?page=ai-translate' ) ); + $titles[] = '' + . esc_html( $post->post_title ) + . ' [x]'; + } + } + echo implode( ', ', $titles ); + echo '
'; + } else { + echo '

Keine Einträge ausgewählt.

'; + } + echo ''; + return ob_get_clean(); +} + +/** + * Gibt für einen Beitrag alle Begriffe aus den hierarchischen Taxonomien zurück. + */ +function ait_get_post_categories( $post_id, $post_type ) { + $taxonomies = get_object_taxonomies( $post_type, 'objects' ); + $category_names = []; + foreach ( $taxonomies as $taxonomy ) { + if ( $taxonomy->hierarchical ) { + $terms = get_the_terms( $post_id, $taxonomy->name ); + if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { + foreach ( $terms as $term ) { + $category_names[] = $term->name; + } + } + } + } + return $category_names; +} + +/** + * Ermittelt die erste hierarchische Taxonomie für den Post Type. + */ +function ait_get_category_taxonomy( $post_type ) { + $taxonomies = get_object_taxonomies( $post_type, 'objects' ); + foreach ( $taxonomies as $taxonomy ) { + if ( $taxonomy->hierarchical ) { + return $taxonomy->name; + } + } + return ''; +} + +/** + * Zeigt eine Tabelle mit Beiträgen, Seiten oder Custom Post Types inklusive Pagination und Kategorie‑Filter. + * Die Tabelle enthält ein Formular, das per POST abgeschickt wird, um ausgewählte Beiträge zur Auswahl hinzuzufügen. + */ +function ait_display_table( $post_type ) { + $paged = max( 1, intval( $_GET['paged'] ?? 1 ) ); + $posts_per_page = 10; + $selected_category = intval( $_GET['category'] ?? 0 ); + ?> +
+ + + + + + + + + + + + + + + $post_type, + 'posts_per_page' => $posts_per_page, + 'paged' => $paged, + 'post_status' => [ 'publish', 'private', 'draft' ], + ]; + if ( $selected_category && $category_tax ) { + $args['tax_query'] = [[ + 'taxonomy' => $category_tax, + 'field' => 'term_id', + 'terms' => $selected_category, + ]]; + } + $query = new WP_Query( $args ); + if ( $query->have_posts() ) : + while ( $query->have_posts() ) : $query->the_post(); + ?> + + + + + + + + + + + +
TitelKategorie
+ +
Keine Beiträge gefunden.
+

+ +

+
+ + + \ No newline at end of file