Automattic\WPSC\Device_Detection

User_Agent_Info::maybe_get_user_agent_from_serverprivate staticWPSCache 1.0

Retrieves the user agent from the server if not provided.

Method of the class: User_Agent_Info{}

No Hooks.

Returns

String|false. The user agent string or false if not available.

Usage

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

User_Agent_Info::maybe_get_user_agent_from_server() code WPSCache 3.1.0

private static function maybe_get_user_agent_from_server( $user_agent = null ) {
	if ( null !== $user_agent ) {
		return $user_agent;
	}

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