Automattic\Jetpack\Device_Detection

User_Agent_Info::is_mobile_app()public staticWPSCache 1.0

Checks if a visitor is coming from one of the WordPress mobile apps.

Method of the class: User_Agent_Info{}

No Hooks.

Return

true|false.

Usage

$result = User_Agent_Info::is_mobile_app();

User_Agent_Info::is_mobile_app() code WPSCache 1.11.0

public static function is_mobile_app() {

	if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
		return false;
	}

	$agent = strtolower( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- This is validating.

	if ( isset( $_SERVER['X_USER_AGENT'] ) && preg_match( '|wp-webos|', $_SERVER['X_USER_AGENT'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is validating.
		return true; // Wp4webos 1.1 or higher.
	}

	$app_agents = array( 'wp-android', 'wp-blackberry', 'wp-iphone', 'wp-nokia', 'wp-webos', 'wp-windowsphone' );
	// the mobile reader on iOS has an incorrect UA when loading the reader
	// currently it is the default one provided by the iOS framework which
	// causes problems with 2-step-auth
	// User-Agent   WordPress/3.1.4 CFNetwork/609 Darwin/13.0.0.
	$app_agents[] = 'wordpress/3.1';

	foreach ( $app_agents as $app_agent ) {
		if ( false !== strpos( $agent, $app_agent ) ) {
			return true;
		}
	}
	return false;
}