Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address CR feedback.
  • Loading branch information
dero committed Jun 22, 2020
commit 45a2fdd44e7c7e92b34a312e8f2c5105e9ac1d3f
35 changes: 3 additions & 32 deletions class.jetpack-user-agent.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
<?php

use Automattic\Jetpack\Device_Detection;

/**
* Determine if the current User Agent matches the passed $kind
*
* @param string $kind Category of mobile device to check for.
* Either: any, dumb, smart.
* @param bool $return_matched_agent Boolean indicating if the UA should be returned
* Deprecated. No longer needed.
*
* @return bool|string Boolean indicating if current UA matches $kind. If
* $return_matched_agent is true, returns the UA string
* @package Jetpack
*/
function jetpack_is_mobile( $kind = 'any', $return_matched_agent = false ) {
$pre = apply_filters( 'pre_jetpack_is_mobile', null, $kind, $return_matched_agent );
if ( $pre ) {
return $pre;
}

$return = false;
$device_info = Device_Detection::get_info();

if ( 'any' === $kind ) {
$return = $device_info['is_phone'];
} elseif ( 'smart' === $kind ) {
$return = $device_info['is_smartphone'];
} elseif ( 'dumb' === $kind ) {
$return = $device_info['is_phone'] && ! $device_info['is_smartphone'];
}

if ( $return_matched_agent && true === $return ) {
$return = $device_info['is_phone_matched_ua'];
}

return apply_filters( 'jetpack_is_mobile', $return, $kind, $return_matched_agent );
}
// Silence is golden.
59 changes: 59 additions & 0 deletions functions.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Redirect;
use Automattic\Jetpack\Device_Detection;

/**
* Disable direct access.
Expand Down Expand Up @@ -305,3 +306,61 @@ function jetpack_is_file_supported_for_sideloading( $file ) {

return in_array( $type, $supported_mime_types, true );
}

/**
* Determine if the current User Agent matches the passed $kind
*
* @param string $kind Category of mobile device to check for.
* Either: any, dumb, smart.
* @param bool $return_matched_agent Boolean indicating if the UA should be returned.
*
* @return bool|string Boolean indicating if current UA matches $kind. If
* $return_matched_agent is true, returns the UA string
*/
function jetpack_is_mobile( $kind = 'any', $return_matched_agent = false ) {

/**
* Filter the value of jetpack_is_mobile before it is calculated.
*
* Passing a truthy value to the filter will short-circuit determining the
* mobile type, returning the passed value instead.
*
* @since 4.2.0
*
* @param bool|string $matches Boolean if current UA matches $kind or not. If
* $return_matched_agent is true, should return the UA string
* @param string $kind Category of mobile device being checked
* @param bool $return_matched_agent Boolean indicating if the UA should be returned
*/
$pre = apply_filters( 'pre_jetpack_is_mobile', null, $kind, $return_matched_agent );
if ( $pre ) {
return $pre;
}

$return = false;
$device_info = Device_Detection::get_info();

if ( 'any' === $kind ) {
$return = $device_info['is_phone'];
} elseif ( 'smart' === $kind ) {
$return = $device_info['is_smartphone'];
} elseif ( 'dumb' === $kind ) {
$return = $device_info['is_phone'] && ! $device_info['is_smartphone'];
}

if ( $return_matched_agent && true === $return ) {
$return = $device_info['is_phone_matched_ua'];
}

/**
* Filter the value of jetpack_is_mobile
*
* @since 4.2.0
*
* @param bool|string $matches Boolean if current UA matches $kind or not. If
* $return_matched_agent is true, should return the UA string
* @param string $kind Category of mobile device being checked
* @param bool $return_matched_agent Boolean indicating if the UA should be returned
*/
return apply_filters( 'jetpack_is_mobile', $return, $kind, $return_matched_agent );
}
Loading