admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('ds_chatbot_nonce'), 'error_message' => __('An error occurred', 'ai-chat-bot-d33ps33k'), 'message_too_long' => __('Error: Message exceeds 15000 character limit', 'ai-chat-bot-d33ps33k'), 'invalid_content' => __('Error: Invalid message content', 'ai-chat-bot-d33ps33k'), 'generic_error' => __('An error occurred', 'ai-chat-bot-d33ps33k'), 'request_error' => __('Unable to process your request', 'ai-chat-bot-d33ps33k'), 'session_expired' => __('Session expired, please refresh the page', 'ai-chat-bot-d33ps33k') ) ); } add_action('wp_enqueue_scripts', 'ds_chatbot_enqueue_scripts'); function ds_chatbot_uninstall() { // Define the constant manually if it's not defined if (!defined('WP_UNINSTALL_PLUGIN')) { define('WP_UNINSTALL_PLUGIN', true); } try { // Include the uninstall file $uninstall_file = plugin_dir_path(__FILE__) . 'dsai-uninstall.php'; if (file_exists($uninstall_file)) { require_once $uninstall_file; } else { wp_die('Uninstall file not found'); } } catch (Exception $e) { wp_die(esc_html__('Uninstall failed: ', 'ai-chat-bot-d33ps33k') . esc_html($e->getMessage())); } } register_uninstall_hook(__FILE__, 'ds_chatbot_uninstall'); // Add security headers for plugin-specific requests add_action('wp_headers', function($headers) { // Verify nonce before processing if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'ds_chatbot_send_message') { if (!isset($_REQUEST['_ajax_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'ds_chatbot_nonce')) { return $headers; // Return headers unchanged if nonce verification fails } // Only add security headers if nonce verification passes $headers['Content-Security-Policy'] = "default-src 'self'"; $headers['X-Content-Type-Options'] = 'nosniff'; $headers['X-Frame-Options'] = 'DENY'; $headers['X-XSS-Protection'] = '1; mode=block'; } return $headers; });