'Heading: "Join the conversation"', 'name_placeholder' => 'Placeholder: "Enter your name"', 'join_button' => 'Button: "Join"', 'checking_text' => 'Button Text: "Checking..."', 'write_placeholder' => 'Placeholder: "Write a message..."', 'send_button' => 'Button: "Send"', 'ask_ai_placeholder' => 'Title: "Ask AI a question"', 'alert_enter_name' => 'Alert: "Please enter a name."', 'alert_unexpected_error' => 'Alert: "An unexpected error occurred..."', 'alert_confirmation_failed' => 'Alert: "Confirmation failed."', 'alert_sending_error' => 'Alert: "Error sending message."', ]; foreach ($text_fields as $id => $label) { add_settings_field($id, $label, 'aish_text_field_render', 'aish_settings_group', 'aish_text_section', ['id' => $id]); } add_settings_section('aish_tools_section', 'Tools', 'aish_tools_section_callback', 'aish_settings_group'); add_settings_field('clear_chat', 'Clear Chat History', 'aish_clear_chat_render', 'aish_settings_group', 'aish_tools_section'); } function aish_api_section_callback() { echo '

Enter your API keys and configure the AI model settings below.

'; } function aish_openai_key_render() { $options = get_option('aish_options', []); $value = $options['openai_key'] ?? ''; printf('', esc_attr($value)); printf('

%s

', sprintf('Get your API key from the %s OpenAI API Keys page%s.', '', '')); } function aish_max_tokens_render() { $options = get_option('aish_options', []); $value = $options['openai_max_tokens'] ?? '150'; printf('', esc_attr($value)); echo '

Controls the maximum length of the AI\'s answer. 100 tokens ≈ 75 words. Default is 150.

'; } function aish_recaptcha_site_key_render() { $options = get_option('aish_options', []); $value = $options['recaptcha_site_key'] ?? ''; printf('', esc_attr($value)); printf('

%s

', sprintf('Get your v3 keys from the %s Google reCAPTCHA Admin Console%s.', '', '')); } function aish_recaptcha_secret_key_render() { $options = get_option('aish_options', []); $value = $options['recaptcha_secret_key'] ?? ''; printf('', esc_attr($value)); echo '

This is the "Secret Key" for server-side validation.

'; } function aish_text_section_callback() { echo '

Here you can translate the publicly visible texts of the shoutbox. English texts are used by default if a field is empty.

'; } function aish_text_field_render($args) { $options = get_option('aish_options', []); $id = $args['id']; $value = $options[$id] ?? ''; printf('', esc_attr($id), esc_attr($value)); } function aish_tools_section_callback() { echo '

Use these tools for plugin maintenance.

'; } function aish_clear_chat_render() { echo '

Warning: This will permanently delete all messages from the shoutbox.

'; } function aish_options_sanitize($input) { $new_input = []; $fields = ['openai_key', 'recaptcha_site_key', 'recaptcha_secret_key', 'join_heading', 'name_placeholder', 'join_button', 'write_placeholder', 'send_button', 'ask_ai_placeholder', 'checking_text', 'alert_enter_name', 'alert_unexpected_error', 'alert_confirmation_failed', 'alert_sending_error']; foreach ($fields as $field) { if (isset($input[$field])) { $new_input[$field] = sanitize_text_field($input[$field]); } } if (isset($input['openai_max_tokens'])) { $new_input['openai_max_tokens'] = absint($input['openai_max_tokens']); } return $new_input; } function aish_options_page_html() { if (!current_user_can('manage_options')) return; ?>