tobiasolssonse
11/12/2018 - 10:13 AM

Timber useragent

iphone ipad osv

function add_to_context($context){
			$context['foo'] 	= 'bar';
			$context['stuff'] = 'I am a value set in your functions.php file';
			$context['notes'] = 'These values are available everytime you call Timber::get_context();';
			$context['menu'] 	= new TimberMenu();
			$context['site'] 	= $this;
			$context['pagination'] = Timber::get_pagination();
			$context['option'] 		= get_fields('option');
			$context['userAgent'] = mobile_user_agent_switch();
			// if(isMobile()){
  		//  	$context['iphone'] = 'iphone';
			// }else{
			// 	$context['iphone'] = 'no';
			// }
			return $context;
		}
		
		
		if( !function_exists('mobile_user_agent_switch') ){
	function mobile_user_agent_switch(){
		$device = '';

		if( stristr($_SERVER['HTTP_USER_AGENT'],'ipad') ) {
			$device = "ipad";
		} else if( stristr($_SERVER['HTTP_USER_AGENT'],'iphone') || strstr($_SERVER['HTTP_USER_AGENT'],'iphone') ) {
			$device = "iphone";
		} else if( stristr($_SERVER['HTTP_USER_AGENT'],'blackberry') ) {
			$device = "blackberry";
		} else if( stristr($_SERVER['HTTP_USER_AGENT'],'android') ) {
			$device = "android";
		}

		if( $device ) {
			return $device;
		} return false; {
			return false;
		}
	}
}