*/ private array $patterns = [ 'googlebot', 'bingbot', 'slurp', 'duckduckbot', 'baiduspider', 'yandexbot', 'sogou', 'exabot', 'facebot', 'ia_archiver', 'semrushbot', 'ahrefsbot', 'mj12bot', 'dotbot', 'rogerbot', 'screaming frog', 'python-requests', 'curl/', 'wget/', 'libwww-perl', 'go-http-client', 'java/', 'axios/', 'headlesschrome', 'phantomjs', 'scrapy', 'zgrab', 'nmap', 'masscan', 'nessus', 'qualys', 'facebookexternalhit', 'twitterbot', 'linkedinbot', 'whatsapp', 'telegrambot', 'slackbot', 'discordbot', ]; /** * Determine if a User-Agent string belongs to a bot. */ public function is_bot( string $user_agent ): bool { if ( '' === $user_agent ) { return true; // No UA = almost certainly a bot or script. } $ua_lower = strtolower( $user_agent ); /** * Filter: extend or replace the bot UA pattern list. * * @param array $patterns List of lowercase regex fragments. * @param string $ua_lower Lowercased User-Agent being tested. * * @since 1.0.0 */ $patterns = apply_filters( 'pulseviews/bot_patterns', $this->patterns, $ua_lower ); foreach ( $patterns as $pattern ) { if ( str_contains( $ua_lower, $pattern ) ) { return true; } } // Regex-based check for less obvious bots. if ( preg_match( '/\bbot\b|\bspider\b|\bcrawler\b|\bscraper\b/i', $user_agent ) ) { return true; } return false; } }