Return to Snippet

Revision: 40199
at January 27, 2011 10:40 by websitez


Updated Code
/**
 * Detects mobile group
 * 
 * @return string
 */
function get_group()
{
    static $mobile_group = null;

    if(function_exists('websitez_get_mobile_device')){ //Check to see if the WP Mobile Detector is installed
        $mobile_device = websitez_get_mobile_device(); //Returns an array with mobile detection values
	if(is_array($mobile_device) && $mobile_device['type'] == "1" && array_key_exists('high', $this->groups) && $this->groups["high"]["enabled"]){
		return "high"; //Smart phone device
	}else if(is_array($mobile_device) && $mobile_device['type'] == "2" && array_key_exists('low', $this->groups) && $this->groups["low"]["enabled"]){
		return "low"; //Feature phone device
	}
    } //End WP Mobile Detector hook
    
    if ($mobile_group === null) {
        foreach ($this->groups as $group => $config) {
            if (isset($config['enabled']) && $config['enabled'] && isset($config['agents'])) {
                foreach ((array) $config['agents'] as $agent) {
                    if ($agent && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('~' . $agent . '~i', $_SERVER['HTTP_USER_AGENT'])) {
                        $mobile_group = $group;
                        
                        return $mobile_group;
                    }
                }
            }
        }
        
        $mobile_group = false;
    }
    
    return $mobile_group;
}

Revision: 40198
at January 27, 2011 10:39 by websitez


Initial Code
/**
 * Detects mobile group
 * 
 * @return string
 */
function get_group()
{
    static $mobile_group = null;

    if(function_exists('websitez_get_mobile_device')){ //Check to see if the WP Mobile Detector is installed
			$mobile_device = websitez_get_mobile_device(); //Returns an array with mobile detection values
			if(is_array($mobile_device) && $mobile_device['type'] == "1" && array_key_exists('high', $this->groups) && $this->groups["high"]["enabled"]){
					return "high"; //Smart phone device
			}else if(is_array($mobile_device) && $mobile_device['type'] == "2" && array_key_exists('low', $this->groups) && $this->groups["low"]["enabled"]){
					return "low"; //Feature phone device
			}
		} //End WP Mobile Detector hook
    
    if ($mobile_group === null) {
        foreach ($this->groups as $group => $config) {
            if (isset($config['enabled']) && $config['enabled'] && isset($config['agents'])) {
                foreach ((array) $config['agents'] as $agent) {
                    if ($agent && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('~' . $agent . '~i', $_SERVER['HTTP_USER_AGENT'])) {
                        $mobile_group = $group;
                        
                        return $mobile_group;
                    }
                }
            }
        }
        
        $mobile_group = false;
    }
    
    return $mobile_group;
}

Initial URL
http://websitez.com

Initial Description

                                

Initial Title
WP Mobile Detector & W3 Total Cache Integration

Initial Tags

                                

Initial Language
PHP