Automattic\Jetpack\Device_Detection

User_Agent_Info::is_iphone_or_ipod()public staticWPSCache 1.0

Detects if the current UA is iPhone Mobile Safari or another iPhone or iPod Touch Browser.

They type can check for any iPhone, an iPhone using Safari, or an iPhone using something other than Safari.

Note: If you want to check for Opera mini, Opera mobile or Firefox mobile (or any 3rd party iPhone browser), you should put the check condition before the check for 'iphone-any' or 'iphone-not-safari'. Otherwise those browsers will be 'catched' by the iphone string.

@param string $type Type of iPhone detection.

Метод класса: User_Agent_Info{}

No Hooks.

Return

null. Nothing.

Usage

$result = User_Agent_Info::is_iphone_or_ipod( $type );
$type **
-
Default: 'iphone-any'

Code of User_Agent_Info::is_iphone_or_ipod() WPSCache 1.9.1

public static function is_iphone_or_ipod( $type = 'iphone-any' ) {
	if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
		return false;
	}

	$ua        = strtolower( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- This is validating.
	$is_iphone = ( strpos( $ua, 'iphone' ) !== false ) || ( strpos( $ua, 'ipod' ) !== false );
	$is_safari = ( false !== strpos( $ua, 'safari' ) );

	if ( 'iphone-safari' === $type ) {
		return $is_iphone && $is_safari;
	} elseif ( 'iphone-not-safari' === $type ) {
		return $is_iphone && ! $is_safari;
	} else {
		return $is_iphone;
	}
}