Posted By

websitez on 01/27/11


Tagged


Versions (?)

WP Mobile Detector & W3 Total Cache Integration


 / Published in: PHP
 

URL: http://websitez.com

  1. /**
  2.  * Detects mobile group
  3.  *
  4.  * @return string
  5.  */
  6. function get_group()
  7. {
  8. static $mobile_group = null;
  9.  
  10. if(function_exists('websitez_get_mobile_device')){ //Check to see if the WP Mobile Detector is installed
  11. $mobile_device = websitez_get_mobile_device(); //Returns an array with mobile detection values
  12. if(is_array($mobile_device) && $mobile_device['type'] == "1" && array_key_exists('high', $this->groups) && $this->groups["high"]["enabled"]){
  13. return "high"; //Smart phone device
  14. }else if(is_array($mobile_device) && $mobile_device['type'] == "2" && array_key_exists('low', $this->groups) && $this->groups["low"]["enabled"]){
  15. return "low"; //Feature phone device
  16. }
  17. } //End WP Mobile Detector hook
  18.  
  19. if ($mobile_group === null) {
  20. foreach ($this->groups as $group => $config) {
  21. if (isset($config['enabled']) && $config['enabled'] && isset($config['agents'])) {
  22. foreach ((array) $config['agents'] as $agent) {
  23. if ($agent && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('~' . $agent . '~i', $_SERVER['HTTP_USER_AGENT'])) {
  24. $mobile_group = $group;
  25.  
  26. return $mobile_group;
  27. }
  28. }
  29. }
  30. }
  31.  
  32. $mobile_group = false;
  33. }
  34.  
  35. return $mobile_group;
  36. }

Report this snippet  

You need to login to post a comment.