'perplexity', // Credentials. 'perplexity_key' => '', 'perplexity_model' => 'sonar', 'gemini_key' => '', 'gemini_model' => 'gemini-2.5-flash', 'google_key' => '', 'google_cx' => '', 'use_google' => 1, // What a check consists of. 'check_mode' => 'regex', // When checks fire automatically. 'run_on' => 'publish', // Tuning. 'max_claims' => 10, 'flag_threshold' => 40, 'skip_scanned' => 1, ); } /** * Available Perplexity models. * * @return array */ public static function models() { return array( 'sonar' => __( 'sonar — cheapest, fine for most checks', 'ai-slop-checker' ), 'sonar-pro' => __( 'sonar-pro — deeper search, better on niche claims', 'ai-slop-checker' ), 'sonar-reasoning' => __( 'sonar-reasoning — slowest, best on claims needing inference', 'ai-slop-checker' ), ); } /** * Available Gemini models. * * Model IDs churn faster than plugin releases, so this list is filterable * and the settings screen accepts whatever is stored even if it drops off. * * @return array */ public static function gemini_models() { /** * Filter the selectable Gemini models. * * @param array $models Map of model ID to label. */ return apply_filters( 'aisc_gemini_models', array( 'gemini-2.5-flash' => __( 'gemini-2.5-flash — fast and cheap, good default', 'ai-slop-checker' ), 'gemini-2.5-pro' => __( 'gemini-2.5-pro — stronger reasoning, costs more', 'ai-slop-checker' ), 'gemini-2.0-flash' => __( 'gemini-2.0-flash — older, cheapest', 'ai-slop-checker' ), ) ); } /** * Which AI provider produces verdicts. * * @return array */ public static function ai_providers() { return array( 'perplexity' => __( 'Perplexity — search-grounded by default', 'ai-slop-checker' ), 'gemini' => __( 'Gemini — with Google Search grounding', 'ai-slop-checker' ), 'both' => __( 'Both, and compare — strongest signal, double the cost', 'ai-slop-checker' ), ); } /** * Providers currently selected and usable. * * @return array */ public static function active_providers() { $choice = self::get( 'ai_provider' ); $out = array(); if ( in_array( $choice, array( 'perplexity', 'both' ), true ) && '' !== trim( (string) self::get( 'perplexity_key' ) ) ) { $out[] = 'perplexity'; } if ( in_array( $choice, array( 'gemini', 'both' ), true ) && '' !== trim( (string) self::get( 'gemini_key' ) ) ) { $out[] = 'gemini'; } return $out; } /** * Check modes. * * @return array */ public static function check_modes() { return array( 'regex' => __( 'Patterns only — instant, free, no API key needed', 'ai-slop-checker' ), 'regex_ai' => __( 'Patterns + AI fact-check — slower and metered, but catches outdated facts', 'ai-slop-checker' ), ); } /** * When automatic checks fire. * * @return array */ public static function run_on_options() { return array( 'publish' => __( 'On publish only', 'ai-slop-checker' ), 'save' => __( 'On every save, including drafts', 'ai-slop-checker' ), 'never' => __( 'Never — I will run checks by hand', 'ai-slop-checker' ), ); } /** * Read every setting, merged over defaults. * * @return array */ public static function all() { $stored = get_option( AISC_OPTION, array() ); if ( ! is_array( $stored ) ) { $stored = array(); } return wp_parse_args( $stored, self::defaults() ); } /** * Read one setting. * * @param string $key Setting key. * @return mixed */ public static function get( $key ) { $all = self::all(); return $all[ $key ] ?? null; } /** * Whether enough is configured to run a fact check. * * @return bool */ public static function can_verify() { return ! empty( self::active_providers() ); } /** * Whether AI checking is both selected and usable. * * @return bool */ public static function ai_enabled() { return 'regex_ai' === self::get( 'check_mode' ) && self::can_verify(); } /** * Sanitise a submitted settings array. * * Blank API key fields are treated as "leave unchanged" so that the masked * values rendered in the form never wipe a stored key on save. * * @param array $input Raw form input. * @return array */ public static function sanitize( $input ) { $current = self::all(); $out = self::defaults(); foreach ( array( 'perplexity_key', 'gemini_key', 'google_key' ) as $secret ) { $submitted = isset( $input[ $secret ] ) ? trim( sanitize_text_field( $input[ $secret ] ) ) : ''; $out[ $secret ] = ( '' === $submitted ) ? $current[ $secret ] : $submitted; } $out['google_cx'] = isset( $input['google_cx'] ) ? trim( sanitize_text_field( $input['google_cx'] ) ) : ''; $provider = isset( $input['ai_provider'] ) ? sanitize_text_field( $input['ai_provider'] ) : ''; $out['ai_provider'] = array_key_exists( $provider, self::ai_providers() ) ? $provider : 'perplexity'; $model = isset( $input['perplexity_model'] ) ? sanitize_text_field( $input['perplexity_model'] ) : ''; $out['perplexity_model'] = array_key_exists( $model, self::models() ) ? $model : 'sonar'; // Accept an unlisted Gemini model so a newly released ID can be used // without waiting for a plugin update. $gemini = isset( $input['gemini_model'] ) ? trim( sanitize_text_field( $input['gemini_model'] ) ) : ''; $out['gemini_model'] = ( '' === $gemini ) ? 'gemini-2.5-flash' : $gemini; $mode = isset( $input['check_mode'] ) ? sanitize_text_field( $input['check_mode'] ) : ''; $out['check_mode'] = array_key_exists( $mode, self::check_modes() ) ? $mode : 'regex'; $run_on = isset( $input['run_on'] ) ? sanitize_text_field( $input['run_on'] ) : ''; $out['run_on'] = array_key_exists( $run_on, self::run_on_options() ) ? $run_on : 'publish'; $out['use_google'] = empty( $input['use_google'] ) ? 0 : 1; $out['skip_scanned'] = empty( $input['skip_scanned'] ) ? 0 : 1; $max = isset( $input['max_claims'] ) ? (int) $input['max_claims'] : 10; $out['max_claims'] = max( 1, min( 25, $max ) ); $threshold = isset( $input['flag_threshold'] ) ? (int) $input['flag_threshold'] : 40; $out['flag_threshold'] = max( 1, min( 100, $threshold ) ); return $out; } }