*/ public static function patterns(): array { return array_values( array_filter( (array) apply_filters( 'pixelpair_bot_user_agents', array( 'bot', 'crawler', 'spider', 'slurp', 'facebookexternalhit', 'headlesschrome', 'lighthouse', 'wp rocket/preload', 'litespeed cache', 'wp-super-cache' ) ), 'is_string' ) ); } /** * Identify common automated clients. * * @param string $agent User agent. * @return bool */ public static function is_bot( string $agent ): bool { return self::contains( $agent, self::patterns() ); } /** * Keep inert configuration in pages generated by cache warmers. * * @param string $agent User agent. * @return bool */ public static function is_preloader( string $agent ): bool { return self::contains( $agent, (array) apply_filters( 'pixelpair_cache_preloaders', array( 'wp rocket/preload', 'litespeed cache', 'wp-super-cache' ) ) ); } /** * Match literal nonempty patterns. * * @param string $agent Agent string. * @param array $patterns Substrings. * @return bool */ private static function contains( string $agent, array $patterns ): bool { foreach ( $patterns as $pattern ) { if ( is_string( $pattern ) && '' !== $pattern && false !== stripos( $agent, $pattern ) ) { return true; } } return false; } }