S// AJAX-Handler für manuelle Punctuation-Anwendung function textgen_apply_punctuation() { check_ajax_referer('apply_punctuation_to_textgen_nonce', '_wpnonce'); if (!current_user_can('manage_options')) { wp_send_json_error(array('message' => 'Unauthorized')); return; } // Text aus der Anfrage holen $text = isset($_POST['text']) ? sanitize_textarea_field($_POST['text']) : ''; if (empty($text)) { wp_send_json_error(array('message' => 'Kein Text zum Transformieren')); return; } // Transformieren mit dynamischer Funktion $transformed_text = textgen_apply_punctuation_dynamic($text); // HTML für die Ausgabe generieren $html = textgen_format_output($transformed_text); // Erfolg zurückmelden wp_send_json_success(array( 'text' => $transformed_text, 'html' => $html )); } add_action('wp_ajax_apply_punctuation_to_textgen', 'textgen_apply_punctuation'); // Erfasse API-Antwort für Logging function textgen_capture_api_response($response, $args, $url) { global $api_full_content; if (strpos($url, 'api.openai.com') !== false) { if (!is_wp_error($response)) { $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); if (isset($data['usage'])) { textgen_log("Prompt Tokens: " . $data['usage']['prompt_tokens']); textgen_log("Completion Tokens: " . $data['usage']['completion_tokens']); textgen_log("Total Tokens: " . $data['usage']['total_tokens']); } if (isset($data['choices'][0]['finish_reason'])) { textgen_log("OpenAI finish_reason: " . $data['choices'][0]['finish_reason']); } // Speichere die vollständige API-Antwort global if (isset($data['choices'][0]['message']['content'])) { $content = $data['choices'][0]['message']['content']; textgen_log("API-Antwort (vollständig): " . $content); $api_full_content = $content; } } else { textgen_log("API-Fehler: " . $response->get_error_message(), "ERROR"); } } return $response; } // Bei Plugin-Aktivierung Log-Datei erstellen function textgen_activation() { textgen_log("TextGen Plugin aktiviert"); // Punctuation-Verfügbarkeit prüfen $punctuation_dir = WP_PLUGIN_DIR . '/punctuation'; if (file_exists($punctuation_dir)) { textgen_log("Punctuation-Verzeichnis gefunden: " . $punctuation_dir); if (function_exists('p_replace_text')) { textgen_log("Punctuation-Hauptfunktion gefunden: p_replace_text"); } else { textgen_log("Punctuation-Plugin gefunden, aber Standard-Funktion nicht erkannt. Dynamische Erkennung wird verwendet."); } } else { textgen_log("Punctuation-Plugin nicht gefunden", "WARNING"); } } register_activation_hook(__FILE__, 'textgen_activation'); HundKatzekaufen.de – Seite 399 – Tählich News über Hunde und Katzen