Created
May 13, 2014 20:06
-
-
Save jaredatch/d9230215ed8d8beca2c3 to your computer and use it in GitHub Desktop.
Mobile detection for NGINX Synthesis accounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Basic mobile detection for Synthesis accounts with NGINX caching. | |
* | |
* @since 1.0.0 | |
* @return boolean | |
*/ | |
function ja_is_mobile() { | |
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) | |
return false; | |
$agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); | |
$mobile = false; | |
$mobile_devices = array( 'android', 'iphone', 'ipod', 'winphone8' ); | |
$tablet_devices = array( 'tablet', 'tablet-android' ); | |
// Check for mobile device user agent | |
foreach ( $mobile_devices as $device ) { | |
if ( false !== strrpos( $agent , $device ) ) { | |
$mobile = true; | |
} | |
} | |
// Check for tablet user agent part, which will override the first check | |
foreach ( $tablet_devices as $device ) { | |
if ( false !== strrpos( $agent , $device ) ) { | |
$mobile = false; | |
} | |
} | |
return $mobile; | |
} | |
/** | |
* Load mobile changes and tweaks if needed. | |
*/ | |
if ( ja_is_mobile() ) { | |
require_once( CHILD_DIR . '/inc/mobile.php' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment