config = $config; } /** * Render preview tab * * @return void */ public function render() { $is_configured = $this->config->is_configured(); if (!$is_configured) { $this->render_not_configured_notice(); return; } ?>

config->is_configured()) { wp_send_json_error(__('AI provider is not configured', 'ai-comment-guard')); } try { // Get AI configuration $provider = $this->config->get('ai_provider'); $token = $this->config->get('ai_provider_token'); // Initialize AI manager $ai_manager = new AIManager($provider, $token); // Get system message from configuration $system_message = $this->config->get_prompt('system'); // Create mock comment data $comment_data = [ 'comment_author' => $comment_author, 'comment_author_email' => $comment_email, 'comment_author_url' => '', // Empty URL for preview 'comment_content' => $comment_content, 'comment_author_IP' => '127.0.0.1', // Mock IP for testing 'comment_agent' => 'Preview Test', // Mock user agent 'comment_date' => current_time('mysql'), 'comment_post_ID' => 1 // Mock post ID ]; // Analyze the comment $result = $ai_manager->analyze_comment($comment_data, $system_message); if ($result) { wp_send_json_success([ 'status' => $result['status'], 'confidence' => $result['confidence'], 'reasoning' => $result['reasoning'], 'prompt_used' => isset($result['prompt_used']) ? $result['prompt_used'] : null, 'system_message' => isset($result['system_message']) ? $result['system_message'] : null, 'raw_response' => isset($result['raw_response']) ? $result['raw_response'] : null ]); } else { wp_send_json_error(__('Failed to analyze comment', 'ai-comment-guard')); } } catch (\Exception $e) { wp_send_json_error(sprintf( /* translators: %s is the error message from the analysis attempt */ __('Analysis error: %s', 'ai-comment-guard'), $e->getMessage() )); } } }