Automattic\Jetpack\Device_Detection
User_Agent_Info::is_mobile_app
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 );
- $user_agent(строка|null)
- User agent string to check. If not provided, uses $_SERVER['HTTP_USER_AGENT'].
По умолчанию: null
Код User_Agent_Info::is_mobile_app() User Agent Info::is mobile app WPSCache 3.0.3
public static function is_mobile_app( $user_agent = null ) {
$user_agent = self::maybe_get_user_agent_from_server( $user_agent );
if ( empty( $user_agent ) ) {
return false;
}
$agent = strtolower( wp_unslash( $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;
}