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.

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

Хуков нет.

Возвращает

true|false.

Использование

$result = User_Agent_Info::is_mobile_app();

Код User_Agent_Info::is_mobile_app() WPSCache 1.12.4

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