array( 'enabled' => true, 'retention_days' => 30, 'anonymize_ip' => true, 'categories' => array( 'ai_training', 'ai_search', 'ai_assistant', 'ai_agent', 'search_engine', 'seo', 'social', 'monitoring', 'archive', 'feed', 'scraper', 'other' ), 'unknown_bots' => true, 'referrals' => true, 'cache_bypass' => false, ), 'robots' => array( 'enabled' => true, 'policies' => array(), 'content_signals' => false, 'signal_search' => 'yes', 'signal_ai_input' => 'yes', 'signal_ai_train' => 'yes', 'llms_hint' => true, 'custom' => '', // Keep aeoora's rules in a physical robots.txt automatically (after the owner opts in). 'auto_sync' => false, ), 'blocker' => array( 'enabled' => true, 'message' => '', ), 'llms' => array( 'enabled' => true, 'full_enabled' => true, 'post_types' => array( 'page', 'post' ), 'max_items' => 0, // 0 = every page. 'full_max_items' => 0, // 0 = every page. 'full_max_kb' => 0, // 0 = no size limit. 'summary' => '', 'details' => '', 'custom_sections' => '', 'exclude_ids' => array(), 'taxonomies' => true, 'link_markdown' => true, 'static_files' => false, 'refresh' => 'twicedaily', // Scheduled rebuild, on top of rebuilds when content changes. // Replace llms.txt from other plugins and foreign files, and keep it replaced (after the owner opts in). 'takeover' => false, ), 'markdown' => array( 'enabled' => true, 'post_types' => array( 'post', 'page' ), 'negotiation' => false, 'link_tag' => true, 'link_header' => true, 'frontmatter' => true, 'archives' => true, 'render' => 'auto', ), 'schema' => array( 'faq' => true, 'faq_display' => 'auto', 'tldr_display' => 'off', 'article' => 'auto', 'organization' => 'auto', 'breadcrumbs' => 'auto', 'speakable' => false, 'org_type' => 'Organization', 'org_name' => '', 'org_logo' => '', 'same_as' => '', ), 'meta' => array( 'output' => 'auto', 'og' => true, ), 'ai' => array( 'provider' => 'wordpress', 'models' => array(), 'base_urls' => array(), 'temperature' => 0.7, 'max_tokens' => 4096, 'language' => '', 'tone' => 'helpful, clear and expert', 'audience' => '', 'brand_voice' => '', 'daily_limit' => 200, 'roles' => 'publish_posts', ), 'suggestions' => array( 'enabled' => true, 'scope' => 'all', // all = every page that needs it, in background batches; daily = per_day pages a day. 'per_day' => 10, 'use_ai' => false, 'ideas' => true, 'auto_apply_meta' => false, 'post_types' => array( 'post', 'page' ), ), 'reports' => array( 'enabled' => false, 'frequency' => 'weekly', 'recipient' => '', ), 'indexnow' => array( 'enabled' => false, 'key' => '', ), 'general' => array( 'keep_data' => false, 'favicons' => true, ), // Optional aeoora Cloud connection (Aeoora_Cloud). The connection // secret is stored encrypted in its own option, never here. 'cloud' => array( 'tracking_code' => '', ), ); } /** * All settings merged with defaults. * * @return array */ public static function all() { if ( null === self::$cache ) { $saved = get_option( self::OPTION, array() ); if ( ! is_array( $saved ) ) { $saved = array(); } self::$cache = self::merge( self::defaults(), $saved ); } return self::$cache; } /** * One group, or one key in a group. * * @param string $group Group name. * @param string|null $key Optional key. * @param mixed $default Fallback. * @return mixed */ public static function get( $group, $key = null, $default = null ) { $all = self::all(); if ( ! isset( $all[ $group ] ) ) { return $default; } if ( null === $key ) { return $all[ $group ]; } return array_key_exists( $key, $all[ $group ] ) ? $all[ $group ][ $key ] : $default; } /** * Update settings (partial). Input is sanitized against the defaults' shape. * * @param array $input Partial settings, grouped. * @param bool $notify Fire `aeoora_settings_updated` (llms.txt, robots.txt and cache * refreshes). Off for groups none of those read. * @return array Saved settings. */ public static function update( array $input, $notify = true ) { $current = self::all(); $defaults = self::defaults(); $old_pol = (array) $current['robots']['policies']; foreach ( $input as $group => $values ) { if ( ! isset( $defaults[ $group ] ) || ! is_array( $values ) ) { continue; } foreach ( $values as $key => $value ) { if ( ! array_key_exists( $key, $defaults[ $group ] ) ) { continue; } $current[ $group ][ $key ] = self::sanitize_value( $group, $key, $value, $defaults[ $group ][ $key ] ); } } // Remember when each crawler's policy changed (robots.txt compliance needs a grace period). $new_pol = (array) $current['robots']['policies']; if ( $new_pol !== $old_pol ) { $changed = (array) get_option( 'aeoora_policy_changed', array() ); foreach ( array_unique( array_merge( array_keys( $old_pol ), array_keys( $new_pol ) ) ) as $bot ) { $was = isset( $old_pol[ $bot ] ) ? $old_pol[ $bot ] : 'allow'; $now = isset( $new_pol[ $bot ] ) ? $new_pol[ $bot ] : 'allow'; if ( $was !== $now ) { $changed[ $bot ] = time(); } } update_option( 'aeoora_policy_changed', $changed, false ); } update_option( self::OPTION, $current, true ); self::$cache = null; if ( $notify ) { do_action( 'aeoora_settings_updated', $current ); } return self::all(); } /** * Flush request cache (e.g. after direct option writes). */ public static function flush() { self::$cache = null; } /** * Sanitize one value, guided by the type of its default. * * @param string $group Group. * @param string $key Key. * @param mixed $value Raw value. * @param mixed $default Default (type reference). * @return mixed */ private static function sanitize_value( $group, $key, $value, $default ) { // Special cases first. $textareas = array( 'custom', 'details', 'custom_sections', 'brand_voice', 'same_as', 'message', 'summary' ); if ( in_array( $key, $textareas, true ) ) { return sanitize_textarea_field( (string) $value ); } if ( 'policies' === $key ) { $out = array(); foreach ( (array) $value as $bot => $policy ) { $bot = sanitize_key( $bot ); if ( '' !== $bot && in_array( $policy, array( 'allow', 'disallow', 'block' ), true ) ) { $out[ $bot ] = $policy; } } return $out; } if ( 'models' === $key || 'base_urls' === $key ) { $out = array(); foreach ( (array) $value as $provider => $model ) { $provider = sanitize_key( $provider ); if ( '' === $provider ) { continue; } $out[ $provider ] = 'base_urls' === $key ? esc_url_raw( trim( (string) $model ) ) : sanitize_text_field( (string) $model ); } return $out; } if ( 'exclude_ids' === $key ) { return array_values( array_filter( array_map( 'absint', (array) $value ) ) ); } if ( 'org_logo' === $key ) { return esc_url_raw( (string) $value ); } if ( 'cloud' === $group && 'tracking_code' === $key ) { $code = Aeoora_Cloud::parse_code( (string) $value ); return false === $code ? '' : $code; } if ( 'recipient' === $key ) { $emails = array_filter( array_map( 'sanitize_email', array_map( 'trim', explode( ',', (string) $value ) ) ) ); return implode( ', ', $emails ); } if ( 'temperature' === $key ) { return max( 0.0, min( 2.0, (float) $value ) ); } if ( in_array( $key, array( 'signal_search', 'signal_ai_input', 'signal_ai_train' ), true ) ) { return 'no' === $value ? 'no' : 'yes'; } $enums = array( 'faq_display' => array( 'auto', 'off' ), 'tldr_display' => array( 'off', 'top', 'bottom' ), 'article' => array( 'auto', 'on', 'off' ), 'organization' => array( 'auto', 'on', 'off' ), 'breadcrumbs' => array( 'auto', 'on', 'off' ), 'output' => array( 'auto', 'on', 'off' ), 'render' => array( 'auto', 'content', 'rendered' ), 'frequency' => array( 'daily', 'weekly', 'monthly' ), 'org_type' => array( 'Organization', 'LocalBusiness', 'Person', 'NewsMediaOrganization', 'OnlineStore' ), 'roles' => array( 'edit_posts', 'publish_posts', 'edit_others_posts', 'manage_options' ), 'refresh' => array( 'twicedaily', 'hourly', 'daily' ), 'scope' => array( 'all', 'daily' ), ); if ( isset( $enums[ $key ] ) ) { return in_array( $value, $enums[ $key ], true ) ? $value : $enums[ $key ][0]; } if ( is_bool( $default ) ) { return in_array( $value, array( true, 1, '1', 'true', 'on', 'yes' ), true ); } if ( is_int( $default ) ) { $int = (int) $value; $caps = array( 'retention_days' => array( 1, 3650 ), 'max_items' => array( 0, 1000000 ), 'full_max_items' => array( 0, 1000000 ), 'full_max_kb' => array( 0, 1048576 ), 'per_day' => array( 0, 1000 ), 'max_tokens' => array( 256, 64000 ), 'daily_limit' => array( 0, 100000 ), ); if ( isset( $caps[ $key ] ) ) { $int = max( $caps[ $key ][0], min( $caps[ $key ][1], $int ) ); } return $int; } if ( is_float( $default ) ) { return (float) $value; } if ( is_array( $default ) ) { return array_values( array_filter( array_map( 'sanitize_key', (array) $value ) ) ); } return sanitize_text_field( (string) $value ); } /** * Recursive merge where saved values replace defaults, but list-type * arrays (numeric keys) are taken whole from the saved value. * * @param array $defaults Defaults. * @param array $saved Saved. * @return array */ private static function merge( array $defaults, array $saved ) { foreach ( $saved as $key => $value ) { if ( isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) && is_array( $value ) && self::is_assoc( $defaults[ $key ] ) ) { $defaults[ $key ] = self::merge( $defaults[ $key ], $value ); } else { $defaults[ $key ] = $value; } } return $defaults; } /** * Is the array associative? * * @param array $arr Array. * @return bool */ private static function is_assoc( array $arr ) { if ( array() === $arr ) { return false; } return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); } }