jetpack_is_mobile

Determine if the current User Agent matches the passed $kind.

Description

jetpack_is_mobile( (string) $kind = 'any', (bool) $return_matched_agent = false ); 

Parameters (2)

0. $kind — Optional. (string) => 'any'
The kind.
1. $return_matched_agent — Optional. (bool) => false
The return matched agent.

Usage

  1. if ( !function_exists( 'jetpack_is_mobile' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/class.jetpack-user-agent.php'; 
  3.  
  4. // The kind. 
  5. $kind = 'any'; 
  6.  
  7. // The return matched agent. 
  8. $return_matched_agent = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = jetpack_is_mobile($kind, $return_matched_agent); 
  12.  

Defined (1)

The function is defined in the following location(s).

/class.jetpack-user-agent.php  
  1. function jetpack_is_mobile( $kind = 'any', $return_matched_agent = false ) { 
  2. static $kinds = array( 'smart' => false, 'dumb' => false, 'any' => false ); 
  3. static $first_run = true; 
  4. static $matched_agent = ''; 
  5.  
  6. $ua_info = new Jetpack_User_Agent_Info(); 
  7.  
  8. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) || strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ), 'ipad' ) ) 
  9. return false; 
  10.  
  11. // Remove Samsung Galaxy tablets (SCH-I800) from being mobile devices 
  12. if ( strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ) , 'sch-i800') ) 
  13. return false; 
  14.  
  15. if( $ua_info->is_android_tablet() && $ua_info->is_kindle_touch() === false ) 
  16. return false; 
  17.  
  18. if( $ua_info->is_blackberry_tablet() ) 
  19. return false; 
  20.  
  21. if ( $first_run ) { 
  22. $first_run = false; 
  23.  
  24. //checks for iPhoneTier devices & RichCSS devices 
  25. if ( $ua_info->isTierIphone() || $ua_info->isTierRichCSS() ) { 
  26. $kinds['smart'] = true; 
  27. $matched_agent = $ua_info->matched_agent; 
  28.  
  29. if ( !$kinds['smart'] ) { 
  30. // if smart, we are not dumb so no need to check 
  31. $dumb_agents = $ua_info->dumb_agents; 
  32. $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); 
  33. foreach ( $dumb_agents as $dumb_agent ) { 
  34. if ( false !== strpos( $agent, $dumb_agent ) ) { 
  35. $kinds['dumb'] = true; 
  36. $matched_agent = $dumb_agent; 
  37. break; 
  38.  
  39. if ( !$kinds['dumb'] ) { 
  40. if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) { 
  41. $kinds['dumb'] = true; 
  42. $matched_agent = 'http_x_wap_profile'; 
  43. } elseif ( isset( $_SERVER['HTTP_ACCEPT']) && ( preg_match( '/wap\.|\.wap/i', $_SERVER['HTTP_ACCEPT'] ) || false !== strpos( strtolower( $_SERVER['HTTP_ACCEPT'] ), 'application/vnd.wap.xhtml+xml' ) ) ) { 
  44. $kinds['dumb'] = true; 
  45. $matched_agent = 'vnd.wap.xhtml+xml'; 
  46.  
  47. if ( $kinds['dumb'] || $kinds['smart'] ) 
  48. $kinds['any'] = true; 
  49.  
  50. if ( $return_matched_agent ) 
  51. return $matched_agent; 
  52.  
  53. return $kinds[$kind];