Created
December 10, 2012 14:31
-
-
Save magadanskiuchen/4250872 to your computer and use it in GitHub Desktop.
WP Mobile Detector
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 | |
/* | |
Plugin Name: Theme Mobile Detector | |
Version: 1.0 | |
*/ | |
# Replace all occurrences of "theme" with your theme name | |
if (get_option('template') == 'theme') { | |
if (!session_id()) session_start(); | |
if (isset($_GET['desktop']) && $_GET['desktop'] == 1) { | |
unset($_SESSION['mobile']); | |
$_SESSION['desktop'] = 1; | |
} | |
if (isset($_GET['mobile'])) { | |
unset($_SESSION['desktop']); | |
$_SESSION['mobile'] = 1; | |
} | |
if (!isset($_SESSION['desktop']) || $_SESSION['desktop'] != 1) { | |
$iphone = preg_match('~iphone~iu', $_SERVER['HTTP_USER_AGENT']); | |
$ipod = preg_match('~ipod~iu', $_SERVER['HTTP_USER_AGENT']); | |
$android = preg_match('~android~iu', $_SERVER['HTTP_USER_AGENT']); | |
$android_tablet = $android; | |
if ($android) { | |
$android_phone = preg_match('~mobile~iu', $_SERVER['HTTP_USER_AGENT']); | |
$android_tablet = !$android_phone; | |
} | |
$blackberry = preg_match('~blackberry~iu', $_SERVER['HTTP_USER_AGENT']); | |
$palm = preg_match('~palm~iu', $_SERVER['HTTP_USER_AGENT']); | |
$iemobile = preg_match('~iemobile~iu', $_SERVER['HTTP_USER_AGENT']); | |
$zunewp7 = preg_match('~zunewp7~iu', $_SERVER['HTTP_USER_AGENT']); | |
if (!is_admin()) { | |
if ($iphone || $ipod || $android_phone || $blackberry || $palm || $iemobile || $zunewp7 || isset($_SESSION['mobile'])) { | |
define('THEME_MOBILE', true); | |
add_filter('stylesheet', create_function('', 'return "theme-mobile";')); | |
// add_filter('template', create_function('', 'return "theme";')); # Comment out if mobile theme is child of desktop theme | |
} else { | |
define('THEME_MOBILE', false); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment