' . esc_html__( 'Configure API access and the bot user.', 'ai-bot-for-bbpress' ) . '

'; } function ai_bot_behavior_settings_section_callback() { echo '

' . esc_html__( 'Define how the bot behaves, its personality, and what triggers responses.', 'ai-bot-for-bbpress' ) . '

'; } function ai_bot_context_settings_section_callback() { echo '

' . esc_html__( 'Configure how the bot accesses local and remote information to provide contextually relevant answers.', 'ai-bot-for-bbpress' ) . '

'; } // Field Callbacks function ai_bot_api_key_callback() { $api_key = get_option( 'ai_bot_api_key' ); echo ''; echo '

' . esc_html__( 'Enter your OpenAI API key.', 'ai-bot-for-bbpress' ) . '

'; } function ai_bot_user_id_callback() { $user_id = get_option( 'ai_bot_user_id' ); echo ''; echo '

' . esc_html__( 'Enter the WordPress User ID for the bot account.', 'ai-bot-for-bbpress' ) . '

'; } function ai_bot_system_prompt_callback() { $prompt = get_option( 'ai_bot_system_prompt', 'You are a helpful forum assistant.' ); echo ''; echo '

' . esc_html__( 'Define the base personality and role of the bot.', 'ai-bot-for-bbpress' ) . '

'; } function ai_bot_custom_prompt_callback() { $prompt = get_option( 'ai_bot_custom_prompt' ); echo ''; echo '

' . esc_html__( 'Add specific instructions to guide the bot\'s responses (e.g., formatting rules, tone adjustments). Appended to every request.', 'ai-bot-for-bbpress' ) . '

'; } function ai_bot_temperature_callback() { $temperature = get_option( 'ai_bot_temperature', 0.5 ); echo ''; echo '

' . esc_html__( 'Controls randomness (0.0 = deterministic, 1.0 = max creativity). Default: 0.5', 'ai-bot-for-bbpress' ) . '

'; } function ai_bot_trigger_keywords_callback() { $keywords = get_option( 'ai_bot_trigger_keywords', '' ); echo ''; echo '

' . esc_html__( 'Comma-separated list of keywords that trigger the bot (case-insensitive). Mentioning the bot user always triggers it.', 'ai-bot-for-bbpress' ) . '

'; } function ai_bot_local_search_limit_callback() { $limit = get_option( 'ai_bot_local_search_limit', 3 ); echo ''; echo '

' . esc_html__( 'Max number of relevant posts/topics from this forum to use as context. Default: 3.', 'ai-bot-for-bbpress' ) . '

'; } function ai_bot_remote_endpoint_url_callback() { $url = get_option( 'ai_bot_remote_endpoint_url', '' ); echo ''; echo '

' . esc_html__( 'URL of the AI Bot for bbPress Helper plugin\'s REST endpoint on your remote site. Leave blank to disable remote context.', 'ai-bot-for-bbpress' ) . '

'; } function ai_bot_remote_search_limit_callback() { $limit = get_option( 'ai_bot_remote_search_limit', 3 ); echo ''; echo '

' . esc_html__( 'Max number of relevant posts from the remote site to use as context. Default: 3.', 'ai-bot-for-bbpress' ) . '

'; } // Forum restriction callback function ai_bot_forum_restriction_callback() { $restriction_mode = get_option( 'ai_bot_forum_restriction', 'all' ); $allowed_forums = get_option( 'ai_bot_allowed_forums', array() ); echo '
'; // Radio buttons echo '

'; echo '
'; echo ''; echo '

'; // Forum selection box echo '
'; // Get forums using WP_Query (bbPress stores forums as 'forum' post type) if ( function_exists( 'bbp_get_forum_post_type' ) ) { // Get all forums with hierarchy support $forums = new WP_Query( array( 'post_type' => bbp_get_forum_post_type(), 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'menu_order title', 'order' => 'ASC' ) ); if ( $forums->have_posts() ) { // Build hierarchical array $forum_hierarchy = array(); $all_forums = array(); while ( $forums->have_posts() ) { $forums->the_post(); $forum_id = get_the_ID(); $forum_data = array( 'id' => $forum_id, 'title' => get_the_title(), 'parent' => get_post()->post_parent, 'children' => array() ); $all_forums[$forum_id] = $forum_data; } wp_reset_postdata(); // Build hierarchy foreach ( $all_forums as $forum_id => $forum_data ) { if ( $forum_data['parent'] == 0 ) { $forum_hierarchy[$forum_id] = $forum_data; } else { if ( isset( $all_forums[$forum_data['parent']] ) ) { $all_forums[$forum_data['parent']]['children'][$forum_id] = $forum_data; } else { // Parent doesn't exist, treat as root level $forum_hierarchy[$forum_id] = $forum_data; } } } // Update hierarchy with children foreach ( $all_forums as $forum_id => $forum_data ) { if ( isset( $forum_hierarchy[$forum_id] ) ) { $forum_hierarchy[$forum_id]['children'] = $forum_data['children']; } } // Display hierarchical forum list ai_bot_display_forum_hierarchy( $forum_hierarchy, $allowed_forums, 0 ); } else { echo '

' . esc_html__( 'No forums found. Create some forums in bbPress to enable forum restriction.', 'ai-bot-for-bbpress' ) . '

'; } } else { echo '

' . esc_html__( 'bbPress functions not yet loaded. Please refresh the page.', 'ai-bot-for-bbpress' ) . '

'; } echo '
'; echo '

' . esc_html__( 'Choose "Selected Forums Only" to restrict the bot to specific forums. This helps prevent spam and keeps the bot focused on professional sections.', 'ai-bot-for-bbpress' ) . '

'; echo '
'; // JavaScript for enabling/disabling checkboxes echo ''; } // Sanitization callback for temperature function ai_bot_sanitize_temperature( $input ) { $input = floatval($input); if ($input < 0) return 0; if ($input > 1) return 1; return $input; } // Sanitization callback for forum array function ai_bot_sanitize_forum_array( $input ) { if ( ! is_array( $input ) ) { return array(); } return array_map( 'absint', $input ); } /** * Display hierarchical forum list with proper indentation * * @param array $forums Array of forums in hierarchical structure * @param array $allowed_forums Array of currently selected forum IDs * @param int $depth Current depth level for indentation */ function ai_bot_display_forum_hierarchy( $forums, $allowed_forums, $depth = 0 ) { foreach ( $forums as $forum ) { $forum_id = $forum['id']; $forum_title = $forum['title']; $checked = in_array( $forum_id, (array) $allowed_forums ) ? 'checked' : ''; // Calculate indentation based on depth $indent_style = $depth > 0 ? 'margin-left: ' . ( $depth * 20 ) . 'px;' : ''; $depth_indicator = $depth > 0 ? str_repeat( '— ', $depth ) : ''; echo ''; // Recursively display child forums if ( ! empty( $forum['children'] ) ) { ai_bot_display_forum_hierarchy( $forum['children'], $allowed_forums, $depth + 1 ); } } }