diff --git a/includes/class-psa-admin.php b/includes/class-psa-admin.php index 3924dc5..c93c56a 100644 --- a/includes/class-psa-admin.php +++ b/includes/class-psa-admin.php @@ -7,34 +7,34 @@ */ if ( ! defined( 'ABSPATH' ) ) { - exit; + exit; } class PSA_Admin { - public static function init() { - add_action( 'admin_menu', array( __CLASS__, 'add_menu_pages' ) ); - add_action( 'admin_init', array( __CLASS__, 'register_settings' ) ); - } + public static function init() { + add_action( 'admin_menu', array( __CLASS__, 'add_menu_pages' ) ); + add_action( 'admin_init', array( __CLASS__, 'register_settings' ) ); + } - /** - * Add settings page under Settings menu. - */ - public static function add_menu_pages() { - add_options_page( - __( 'Peptide Search AI', 'peptide-search-ai' ), - __( 'Peptide Search AI', 'peptide-search-ai' ), - 'manage_options', - 'peptide-search-ai', - array( __CLASS__, 'render_settings_page' ) - ); - } + /** + * Add settings page under Settings menu. + */ + public static function add_menu_pages() { + add_options_page( + __( 'Peptide Search AI', 'peptide-search-ai' ), + __( 'Peptide Search AI', 'peptide-search-ai' ), + 'manage_options', + 'peptide-search-ai', + array( __CLASS__, 'render_settings_page' ) + ); + } - /** - * Register settings fields. - */ - public static function register_settings() { - register_setting( + /** + * Register settings fields. + */ + public static function register_settings() { + register_setting( 'psa_settings_group', 'psa_settings', array( @@ -42,28 +42,28 @@ class PSA_Admin { ) ); - // OpenRouter Section. - add_settings_section( + // OpenRouter Section. + add_settings_section( 'psa_ai_section', __( 'OpenRouter API Settings', 'peptide-search-ai' ), array( __CLASS__, 'render_section_description' ), 'peptide-search-ai' ); - add_settings_field( + add_settings_field( 'api_key', __( 'API Key', 'peptide-search-ai' ), array( __CLASS__, 'render_api_key_field' ), 'peptide-search-ai', 'psa_ai_section' ); - add_settings_field( + add_settings_field( 'ai_model', __( 'Generation Model', 'peptide-search-ai' ), array( __CLASS__, 'render_model_field' ), 'peptide-search-ai', 'psa_ai_section' ); - add_settings_field( + add_settings_field( 'validation_model', __( 'Validation Model', 'peptide-search-ai' ), array( __CLASS__, 'render_validation_model_field' ), @@ -71,177 +71,177 @@ class PSA_Admin { 'psa_ai_section' ); - // Behavior Section. - add_settings_section( + // Behavior Section. + add_settings_section( 'psa_behavior_section', __( 'Behavior Settings', 'peptide-search-ai' ), null, 'peptide-search-ai' ); - add_settings_field( + add_settings_field( 'auto_publish', __( 'Auto-Publish', 'peptide-search-ai' ), array( __CLASS__, 'render_publish_field' ), 'peptide-search-ai', 'psa_behavior_section' ); - add_settings_field( + add_settings_field( 'use_pubchem', __( 'PubChem Enrichment', 'peptide-search-ai' ), array( __CLASS__, 'render_pubchem_field' ), 'peptide-search-ai', 'psa_behavior_section' ); - } + } - /** - * Sanitize settings input. - * - * @param array $input Raw input from the form. - * @return array Sanitized settings. - */ - public static function sanitize_settings( $input ) { - return array( - 'api_key' => sanitize_text_field( $input['api_key'] ?? '' ), - 'ai_model' => sanitize_text_field( $input['ai_model'] ?? '' ), - 'validation_model' => sanitize_text_field( $input['validation_model'] ?? '' ), - 'auto_publish' => sanitize_text_field( $input['auto_publish'] ?? 'draft' ), - // Checkbox: if key is absent in POST, it was unchecked → '0'. - 'use_pubchem' => ! empty( $input['use_pubchem'] ) ? '1' : '0', - ); - } + /** + * Sanitize settings input. + * + * @param array $input Raw input from the form. + * @return array Sanitized settings. + */ + public static function sanitize_settings( $input ) { + return array( + 'api_key' => sanitize_text_field( $input['api_key'] ?? '' ), + 'ai_model' => sanitize_text_field( $input['ai_model'] ?? '' ), + 'validation_model' => sanitize_text_field( $input['validation_model'] ?? '' ), + 'auto_publish' => sanitize_text_field( $input['auto_publish'] ?? 'draft' ), + // Checkbox: if key is absent in POST, it was unchecked → '0'. + 'use_pubchem' => ! empty( $input['use_pubchem'] ) ? '1' : '0', + ); + } - // ------------------------------------------------------------------------- - // Field renderers - // ------------------------------------------------------------------------- + // ------------------------------------------------------------------------- + // Field renderers + // ------------------------------------------------------------------------- - public static function render_section_description() { - ?> -
- OpenRouter to access AI models. OpenRouter provides a unified API for hundreds of models including open-source options like Gemini Flash, Llama, Mistral, Qwen, and DeepSeek, as well as commercial models.', 'peptide-search-ai' ), - escourl( 'https://openrouter.ai/' ) - ); - ?> -
- ++ OpenRouter to access AI models. OpenRouter provides a unified API for hundreds of models including open-source options like Gemini Flash, Llama, Mistral, Qwen, and DeepSeek, as well as commercial models.', 'peptide-search-ai' ), + esc_url( 'https://openrouter.ai/' ) + ); + ?> +
+ - - - - - -
-
- openrouter.ai/settings/keys.
- define( 'PSA_OPENROUTER_KEY', 'your-key-here' );
-
+
+ openrouter.ai/settings/keys.
+ define( 'PSA_OPENROUTER_KEY', 'your-key-here' );
+
- google/gemini-2.5-flash.
- openrouter.ai/models.
- meta-llama/llama-4-maverick, deepseek/deepseek-chat-v3-0324, qwen/qwen-2.5-72b-instruct.
-
+ google/gemini-2.5-flash.
+ openrouter.ai/models.
+ meta-llama/llama-4-maverick, deepseek/deepseek-chat-v3-0324, qwen/qwen-2.5-72b-instruct.
+
- google/gemini-2.0-flash-001.
- meta-llama/llama-4-scout, mistralai/mistral-small-3.1-24b-instruct.
-
+ google/gemini-2.0-flash-001.
+ meta-llama/llama-4-scout, mistralai/mistral-small-3.1-24b-instruct.
+
[peptide_search]
[peptide_search placeholder="Search peptides..."]
[peptide_search]
[peptide_search placeholder="Search peptides..."]
GET /wp-json/peptides/v1/search?q=BPC-157
GET /wp-json/peptides/v1/search?q=BPC-157