Automattic\WPSC\Device_Detection

User_Agent_Info::is_botpublic staticWPSCache 1.0

Was the current request made by a known bot?

Method of the class: User_Agent_Info{}

No Hooks.

Returns

true|false.

Usage

$result = User_Agent_Info::is_bot( $user_agent );
$user_agent(string|null)
User agent string to check. If not provided, uses $_SERVER['HTTP_USER_AGENT'].
Default: null

User_Agent_Info::is_bot() code WPSCache 3.1.1

public static function is_bot( $user_agent = null ) {
	static $is_bot = null;

	if ( null === $user_agent ) {
		if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
			return false;
		}
		$user_agent = wp_unslash( $_SERVER['HTTP_USER_AGENT'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- This is validating.

		// Use cached result only when using the default $_SERVER['HTTP_USER_AGENT'].
		if ( $is_bot === null ) {
			$is_bot = self::is_bot_user_agent( $user_agent );
		}
		return $is_bot;
	}

	if ( empty( $user_agent ) ) {
		return false;
	}

	// Don't use cache when a custom user agent is provided.
	return self::is_bot_user_agent( $user_agent );
}