$bot ) { $id = sanitize_key( $id ); $token = is_array( $bot ) && isset( $bot['token'] ) ? preg_replace( '/[^A-Za-z0-9._-]/', '', (string) $bot['token'] ) : ''; if ( '' === $id || '' === $token ) { continue; } $purpose = isset( $bot['purpose'] ) && in_array( $bot['purpose'], array( self::TRAINING, self::SEARCH, self::USER ), true ) ? $bot['purpose'] : self::TRAINING; $out[ $id ] = array( 'token' => $token, 'name' => isset( $bot['name'] ) ? (string) $bot['name'] : $token, 'operator' => isset( $bot['operator'] ) ? (string) $bot['operator'] : '', 'purpose' => $purpose, 'ua' => isset( $bot['ua'] ) ? (string) $bot['ua'] : $token, ); } return $out; } public static function match( $user_agent ) { $user_agent = (string) $user_agent; if ( '' === $user_agent ) { return ''; } foreach ( self::all() as $id => $bot ) { if ( '' !== $bot['ua'] && false !== stripos( $user_agent, $bot['ua'] ) ) { return $id; } } return ''; } public static function purpose_label( $purpose ) { switch ( $purpose ) { case self::SEARCH: return __( 'AI search', 'latchbot' ); case self::USER: return __( 'Fetches for a user', 'latchbot' ); default: return __( 'AI training', 'latchbot' ); } } private static function defaults() { $list = array( array( 'gptbot', 'GPTBot', 'GPTBot', 'OpenAI', self::TRAINING ), array( 'oai-searchbot', 'OAI-SearchBot', 'OAI-SearchBot', 'OpenAI', self::SEARCH ), array( 'chatgpt-user', 'ChatGPT-User', 'ChatGPT-User', 'OpenAI', self::USER ), array( 'claudebot', 'ClaudeBot', 'ClaudeBot', 'Anthropic', self::TRAINING ), array( 'claude-searchbot', 'Claude-SearchBot', 'Claude-SearchBot', 'Anthropic', self::SEARCH ), array( 'claude-user', 'Claude-User', 'Claude-User', 'Anthropic', self::USER ), array( 'anthropic-ai', 'anthropic-ai', 'anthropic-ai (legacy)', 'Anthropic', self::TRAINING ), array( 'google-extended', 'Google-Extended', 'Google-Extended', 'Google', self::TRAINING, '' ), array( 'applebot-extended', 'Applebot-Extended', 'Applebot-Extended', 'Apple', self::TRAINING, '' ), array( 'perplexitybot', 'PerplexityBot', 'PerplexityBot', 'Perplexity', self::SEARCH ), array( 'perplexity-user', 'Perplexity-User', 'Perplexity-User', 'Perplexity', self::USER ), array( 'meta-externalagent', 'meta-externalagent', 'Meta-ExternalAgent', 'Meta', self::TRAINING ), array( 'meta-externalfetcher', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'Meta', self::USER ), array( 'facebookbot', 'FacebookBot', 'FacebookBot', 'Meta', self::TRAINING ), array( 'ccbot', 'CCBot', 'CCBot', 'Common Crawl', self::TRAINING ), array( 'bytespider', 'Bytespider', 'Bytespider', 'ByteDance', self::TRAINING ), array( 'amazonbot', 'Amazonbot', 'Amazonbot', 'Amazon', self::TRAINING ), array( 'cohere-training-data-crawler', 'cohere-training-data-crawler', 'Cohere training crawler', 'Cohere', self::TRAINING ), array( 'cohere-ai', 'cohere-ai', 'cohere-ai', 'Cohere', self::USER ), array( 'mistralai-user', 'MistralAI-User', 'MistralAI-User', 'Mistral AI', self::USER ), array( 'duckassistbot', 'DuckAssistBot', 'DuckAssistBot', 'DuckDuckGo', self::SEARCH ), array( 'youbot', 'YouBot', 'YouBot', 'You.com', self::SEARCH ), array( 'ai2bot', 'AI2Bot', 'AI2Bot', 'Allen Institute for AI', self::TRAINING ), array( 'diffbot', 'Diffbot', 'Diffbot', 'Diffbot', self::TRAINING ), array( 'timpibot', 'Timpibot', 'Timpibot', 'Timpi', self::TRAINING ), array( 'imagesiftbot', 'ImagesiftBot', 'ImagesiftBot', 'ImageSift', self::TRAINING ), array( 'omgilibot', 'omgilibot', 'Omgilibot', 'Webz.io', self::TRAINING ), array( 'pangubot', 'PanguBot', 'PanguBot', 'Huawei', self::TRAINING ), ); $bots = array(); foreach ( $list as $row ) { $bots[ $row[0] ] = array( 'token' => $row[1], 'name' => $row[2], 'operator' => $row[3], 'purpose' => $row[4], 'ua' => array_key_exists( 5, $row ) ? $row[5] : $row[1], ); } return $bots; } }