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.

Method of the class: User_Agent_Info{}

No Hooks.

Return

null. Nothing (null).

Usage

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

User_Agent_Info::is_iphone_or_ipod() code WPSCache 1.12.0

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;
	}
}