false, 'ui_button_label' => 'Help', 'ui_panel_side' => 'right', // Button/panel is shown by default; hide only for selected roles. 'ui_hide_for_roles' => array(), 'guidance_disabled' => false, 'guidance_max_items' => 3, 'guidance_warning_style' => 'standard', 'ai_disabled' => false, // AI is available by default; hide only for selected roles. 'ai_hide_for_roles' => array(), 'ai_response_style' => 'balanced', 'ai_show_suggested_docs' => true, 'disable_extra_context_checkbox' => 0, // OpenAI settings (needed for "Ask AI" to work immediately). 'openai_api_key' => '', 'openai_model' => 'gpt-4o', 'openai_temperature' => 0.3, 'openai_max_output_tokens' => 700, 'openai_default_language' => 'auto', 'ai_include_site_context' => true, 'ai_daily_limit' => 50, 'ai_daily_limits_per_role' => array(), // infinite_table 'debug_logging' => false, ); public function __construct() { // Register SAP settings page on init like the other plugins (priority 11). add_action( 'init', array( $this, 'register_settings_page' ), 11 ); } public static function get_defaults() { return apply_filters( 'ait_aiaa_settings_defaults', self::$defaults ); } public static function get_options() { $defaults = self::get_defaults(); $saved = get_option( AIT_AIAA_OPTION, array() ); if ( ! is_array( $saved ) ) { $saved = array(); } // Back-compat: older versions used "enabled" / "guidance_enabled". if ( isset( $saved['enabled'] ) && ! isset( $saved['disabled_plugin'] ) ) { $saved['disabled_plugin'] = empty( $saved['enabled'] ) ? true : false; } if ( isset( $saved['guidance_enabled'] ) && ! isset( $saved['guidance_disabled'] ) ) { $saved['guidance_disabled'] = empty( $saved['guidance_enabled'] ) ? true : false; } $merged = array_merge( $defaults, $saved ); // Normalize language option (Auto by default). if ( empty( $merged['openai_default_language'] ) ) { $merged['openai_default_language'] = 'auto'; } $opts = self::get_language_options(); if ( ! isset( $opts[ $merged['openai_default_language'] ] ) ) { $merged['openai_default_language'] = 'auto'; } return $merged; } public static function get( $key ) { $options = self::get_options(); return isset( $options[ $key ] ) ? $options[ $key ] : null; } public static function update( $key, $value ) { $options = self::get_options(); $options[ $key ] = $value; return update_option( AIT_AIAA_OPTION, $options ); } public static function reset() { return update_option( AIT_AIAA_OPTION, self::$defaults ); } public function register_settings_page() { if ( ! is_admin() ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } // Load SAP. require_once AIT_AIAA_PLUGIN_DIR . 'lib/simple-admin-pages/simple-admin-pages.php'; // Initialize SAP library. if ( ! function_exists( 'sap_initialize_library' ) ) { return; } $sap = sap_initialize_library( array( 'version' => '2.7.3', 'theme' => 'ait', 'lib_url' => AIT_AIAA_PLUGIN_URL . 'lib/simple-admin-pages/', ) ); $sap->add_page( 'submenu', array( 'id' => AIT_AIAA_OPTION, 'title' => __( 'Settings', 'ait-ai-admin-assistance' ), 'menu_title' => __( 'Settings', 'ait-ai-admin-assistance' ), 'parent_menu' => 'edit.php?post_type=' . AIT_AIAA_Guidance_CPT::CPT, 'description' => '', 'capability' => 'manage_options', 'default_tab' => 'ait_aiaa_license', ) ); $sap->add_section( 'ait-aiaa-settings', array( 'id' => 'ait_aiaa_license_tab', 'title' => __('License', 'ait-ai-admin-assistance'), 'is_tab' => true, 'icon' => 'admin-network', 'rank' => 0, ) ); $sap->add_section( 'ait-aiaa-settings', array( 'id' => 'ait_aiaa_dashboard', 'title' => __( 'Dashboard', 'ait-ai-admin-assistance' ), 'tab' => 'ait_aiaa_license_tab', ) ); $sap->add_setting( 'ait-aiaa-settings', 'ait_aiaa_dashboard', 'html', array( 'id' => 'ait_aiaa_license_grid', 'title' => __('License', 'ait-ai-admin-assistance' ), 'html' => [ 'AIT_AIAA_Dashboard', 'display_dashboard_license' ], ) ); // Tabs $sap->add_section( AIT_AIAA_OPTION, array( 'id' => 'aiaa_tab_general', 'title' => __( 'General', 'ait-ai-admin-assistance' ), 'is_tab' => true, 'icon' => 'text' ) ); $sap->add_section( AIT_AIAA_OPTION, array( 'id' => 'aiaa_tab_guidance', 'title' => __( 'Designer Guidance', 'ait-ai-admin-assistance' ), 'is_tab' => true, 'icon' => 'admin-users' ) ); $sap->add_section( AIT_AIAA_OPTION, array( 'id' => 'aiaa_tab_ai', 'title' => __( 'AI Assistant', 'ait-ai-admin-assistance' ), 'is_tab' => true, 'icon' => 'desktop' ) ); $sap->add_section( AIT_AIAA_OPTION, array( 'id' => 'aiaa_tab_advanced', 'title' => __( 'Advanced', 'ait-ai-admin-assistance' ), 'is_tab' => true, 'icon' => 'awards' ) ); $sap->add_section( AIT_AIAA_OPTION, array( 'id' => 'aiaa_tab_styling', 'title' => __( 'Styling', 'ait-ai-admin-assistance' ), 'is_tab' => true, 'icon' => 'welcome-widgets-menus' ) ); // ========== General ========== $sap->add_section( AIT_AIAA_OPTION, array( 'id' => 'aiaa_general_section', 'title' => __( 'General Settings', 'ait-ai-admin-assistance' ), 'tab' => 'aiaa_tab_general', ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_general_section', 'toggle', array( 'id' => 'disabled_plugin', 'title' => __( 'Disable Plugin', 'ait-ai-admin-assistance' ), 'description' => __( 'Disable the AI Admin Assistance panel in wp-admin.', 'ait-ai-admin-assistance' ), ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_general_section', 'text', array( 'id' => 'ui_button_label', 'title' => __( 'Help Button Label', 'ait-ai-admin-assistance' ), 'description' => __( 'Text shown on the help panel button.', 'ait-ai-admin-assistance' ), ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_general_section', 'radio', array( 'id' => 'ui_panel_side', 'title' => __( 'Panel Side', 'ait-ai-admin-assistance' ), 'description' => __( 'Choose which side the panel opens from.', 'ait-ai-admin-assistance' ), 'options' => array( 'right' => __( 'Right', 'ait-ai-admin-assistance' ), 'left' => __( 'Left', 'ait-ai-admin-assistance' ), ), ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_general_section', 'checkbox', array( 'id' => 'ui_hide_for_roles', 'title' => __( 'Hide for Roles', 'ait-ai-admin-assistance' ), 'description' => __( 'By default, the help panel is shown to all roles that can access wp-admin. Select roles here to hide the panel button for them.', 'ait-ai-admin-assistance' ), 'options' => $this->get_roles_for_settings(), ) ); // ========== Designer Guidance ========== $sap->add_section( AIT_AIAA_OPTION, array( 'id' => 'aiaa_guidance_section', 'title' => __( 'Designer Guidance', 'ait-ai-admin-assistance' ), 'tab' => 'aiaa_tab_guidance', ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_guidance_section', 'toggle', array( 'id' => 'guidance_disabled', 'title' => __( 'Disable Designer Guidance', 'ait-ai-admin-assistance' ), 'description' => __( 'Show designer-provided guidance content in the panel.', 'ait-ai-admin-assistance' ), ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_guidance_section', 'number', array( 'id' => 'guidance_max_items', 'title' => __( 'Max Guidance Items', 'ait-ai-admin-assistance' ), 'description' => __( 'Maximum number of guidance items to show for a screen.', 'ait-ai-admin-assistance' ), 'min' => 1, 'max' => 20, ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_guidance_section', 'select', array( 'id' => 'guidance_warning_style', 'title' => __( 'Warning Style', 'ait-ai-admin-assistance' ), 'description' => __( 'Controls how "warning" guidance items will be styled.', 'ait-ai-admin-assistance' ), 'options' => array( 'subtle' => __( 'Subtle', 'ait-ai-admin-assistance' ), 'standard' => __( 'Standard', 'ait-ai-admin-assistance' ), 'strong' => __( 'Strong', 'ait-ai-admin-assistance' ), ), ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_guidance_section', 'infinite_table', array( 'id' => 'quick_links', 'title' => __( 'Quick Help Links', 'ait-ai-admin-assistance' ), 'add_label' => __( 'Add Link', 'ait-ai-admin-assistance' ), 'del_label' => __( 'Delete', 'ait-ai-admin-assistance' ), 'description' => __( 'Optional list of quick links shown in the panel.', 'ait-ai-admin-assistance' ), 'fields' => array( 'label' => array( 'label' => __( 'Label', 'ait-ai-admin-assistance' ), 'type' => 'text', 'required' => true, ), 'url' => array( 'label' => __( 'URL', 'ait-ai-admin-assistance' ), 'type' => 'text', 'required' => true, ), 'roles' => array( 'label' => __( 'Exclude Roles (comma-separated)', 'ait-ai-admin-assistance' ), 'type' => 'text', 'required' => false, ), ), ) ); // ========== AI Assistant ========== $sap->add_section( AIT_AIAA_OPTION, array( 'id' => 'aiaa_ai_section', 'title' => __( 'AI Assistant', 'ait-ai-admin-assistance' ), 'tab' => 'aiaa_tab_ai', ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_ai_section', 'toggle', array( 'id' => 'ai_disabled', 'title' => __( 'Disable AI Assistant', 'ait-ai-admin-assistance' ), 'description' => __( 'Prevent all users from asking questions about the current admin screen which the "Ask AI" tab in the helper panel.', 'ait-ai-admin-assistance' ), ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_ai_section', 'checkbox', array( 'id' => 'ai_hide_for_roles', 'title' => __( 'AI Hide for Roles', 'ait-ai-admin-assistance' ), 'description' => __( 'By default, AI is available to all roles that can access wp-admin. Select roles here to hide the "Ask AI" tab and block AI usage for them.', 'ait-ai-admin-assistance' ), 'options' => $this->get_roles_for_settings(), ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_ai_section', 'radio', array( 'id' => 'ai_response_style', 'title' => __( 'Response Style', 'ait-ai-admin-assistance' ), 'description' => __( 'How detailed AI answers should be.', 'ait-ai-admin-assistance' ), 'options' => array( 'concise' => __( 'Concise', 'ait-ai-admin-assistance' ), 'balanced' => __( 'Balanced', 'ait-ai-admin-assistance' ), 'detailed' => __( 'Detailed', 'ait-ai-admin-assistance' ), ), ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_ai_section', 'toggle', array( 'id' => 'ai_show_suggested_docs', 'title' => __( 'Show Suggested Docs', 'ait-ai-admin-assistance' ), 'description' => __( 'Show suggested WordPress documentation links in AI answers when available.', 'ait-ai-admin-assistance' ), ) ); // OpenAI $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_ai_section', 'text', array( 'id' => 'openai_api_key', 'title' => __( 'OpenAI API Key', 'ait-ai-admin-assistance' ), 'description' => __( 'Server-side key used to call OpenAI. Keep this secret and do not paste it anywhere public.', 'ait-ai-admin-assistance' ), ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_ai_section', 'select', [ 'id' => 'openai_model', 'title' => __( 'OpenAI Model', 'ait-ai-admin-assistance' ), 'description' => __('Which OpenAI model should be used to handle the image processing requests?', 'ait-ai-admin-assistance'), 'options' => [ 'gpt-5.1' => __( 'GPT-5.1', 'ait-ai-admin-assistance' ), 'gpt-5' => __( 'GPT-5', 'ait-ai-admin-assistance' ), 'gpt-5-mini' => __( 'GPT-5 Mini', 'ait-ai-admin-assistance' ), 'gpt-4.1' => __( 'GPT-4.1', 'ait-ai-admin-assistance' ), 'gpt-4o' => __( 'GPT-4o', 'ait-ai-admin-assistance' ), 'gpt-3.5-turbo' => __( 'GPT-3.5 Turbo', 'ait-ai-admin-assistance' ), ], 'blank_option' => false, 'default' => self::$defaults['openai_model'], ] ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_ai_section', 'number', array( 'id' => 'openai_temperature', 'title' => __( 'Temperature', 'ait-ai-admin-assistance' ), 'description' => __( 'Controls randomness. Lower values are more deterministic.', 'ait-ai-admin-assistance' ), 'min' => 0, 'max' => 2, 'step' => 0.1, ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_ai_section', 'number', array( 'id' => 'openai_max_output_tokens', 'title' => __( 'Max Output Tokens', 'ait-ai-admin-assistance' ), 'description' => __( 'Hard cap on response length. Leave blank for no limit.', 'ait-ai-admin-assistance' ), 'min' => 0, 'max' => 4000, 'step' => 1, ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_ai_section', 'select', array( 'id' => 'openai_default_language', 'title' => __('Language', 'ait-ai-admin-assistance' ), 'description' => __( 'Choose the response language, or leave on Auto to follow the user\'s language.', 'ait-ai-admin-assistance' ), 'options' => self::get_language_options(), 'blank_option' => false, ) ); // ========== Advanced ========== $sap->add_section( AIT_AIAA_OPTION, array( 'id' => 'aiaa_advanced_section', 'title' => __( 'Advanced', 'ait-ai-admin-assistance' ), 'tab' => 'aiaa_tab_advanced', ) ); $sap->add_setting( AIT_AIAA_OPTION, 'aiaa_advanced_section', 'toggle', array( 'id' => 'debug_logging', 'title' => __( 'Debug Logging', 'ait-ai-admin-assistance' ), 'description' => __( 'Enable debug logging for troubleshooting.', 'ait-ai-admin-assistance' ), ) ); // ========== Styling ========== $sap->add_section( AIT_AIAA_OPTION, array( 'id' => 'aiaa_styling_section', 'title' => __( 'Styling', 'ait-ai-admin-assistance' ), 'tab' => 'aiaa_tab_styling', ) ); $sap = apply_filters( 'ait_aiaa_settings_page', $sap, $this ); // Render $sap->add_admin_menus(); } protected function get_roles_for_settings() { $roles = array(); if ( function_exists( 'wp_roles' ) ) { $wp_roles = wp_roles(); if ( $wp_roles && is_array( $wp_roles->roles ) ) { foreach ( $wp_roles->roles as $key => $role ) { $roles[ $key ] = isset( $role['name'] ) ? $role['name'] : $key; } } } if ( empty( $roles ) ) { $roles = array( 'administrator' => __( 'Administrator', 'ait-ai-admin-assistance' ), 'editor' => __( 'Editor', 'ait-ai-admin-assistance' ), 'author' => __( 'Author', 'ait-ai-admin-assistance' ), 'contributor' => __( 'Contributor', 'ait-ai-admin-assistance' ), 'subscriber' => __( 'Subscriber', 'ait-ai-admin-assistance' ), ); } return $roles; } public static function get_language_options() { return [ 'auto' => __( 'Auto', 'ait-ai-admin-assistance' ), 'af' => 'Afrikaans', 'sq' => 'Shqip', 'am' => 'አማርኛ', 'ar' => 'العربية', 'hy' => 'Հայերեն', 'az' => 'Azərbaycan dili', 'bn' => 'বাংলা', 'bs' => 'Bosanski', 'bg' => 'Български', 'ca' => 'Català', 'zh_CN' => '简体中文', 'zh_TW' => '繁體中文', 'hr' => 'Hrvatski', 'cs' => 'Čeština', 'da' => 'Dansk', 'nl' => 'Nederlands', 'en' => 'English', 'et' => 'Eesti', 'fi' => 'Suomi', 'fr' => 'Français', 'de' => 'Deutsch', 'el' => 'Ελληνικά', 'gu' => 'ગુજરાતી', 'he' => 'עברית', 'hi' => 'हिन्दी', 'hu' => 'Magyar', 'is' => 'Íslenska', 'id' => 'Bahasa Indonesia', 'it' => 'Italiano', 'ja' => '日本語', 'kn' => 'ಕನ್ನಡ', 'ko' => '한국어', 'lv' => 'Latviešu', 'lt' => 'Lietuvių', 'mk' => 'Македонски', 'ms' => 'Bahasa Melayu', 'ml' => 'മലയാളം', 'mr' => 'मराठी', 'ne' => 'नेपाली', 'nb' => 'Norsk Bokmål', 'fa' => 'فارسی', 'pl' => 'Polski', 'pt_BR' => 'Português do Brasil', 'pt_PT' => 'Português', 'pa' => 'ਪੰਜਾਬੀ', 'ro' => 'Română', 'ru' => 'Русский', 'sr' => 'Српски', 'si' => 'සිංහල', 'sk' => 'Slovenčina', 'sl' => 'Slovenščina', 'es' => 'Español', 'sv' => 'Svenska', 'ta' => 'தமிழ்', 'te' => 'తెలుగు', 'th' => 'ไทย', 'tr' => 'Türkçe', 'uk' => 'Українська', 'ur' => 'اردو', 'vi' => 'Tiếng Việt', 'zh_HK' => '香港中文版', ]; } }