Introduce wp_is_mobile() and use it instead of $is_iphone global, see #20014

git-svn-id: https://develop.svn.wordpress.org/trunk@20417 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2012-04-10 01:19:30 +00:00
parent fdce6271d0
commit bce0d37a67
11 changed files with 87 additions and 59 deletions

View File

@@ -321,7 +321,7 @@ class WP_Admin_Bar {
}
final protected function _render( $root ) {
global $is_IE, $is_iphone;
global $is_IE;
// Add browser classes.
// We have to do this here since admin bar shows on the front end.
@@ -333,7 +333,7 @@ class WP_Admin_Bar {
$class .= ' ie8';
elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) )
$class .= ' ie9';
} elseif ( $is_iphone ) {
} elseif ( wp_is_mobile() ) {
$class .= ' mobile';
}

View File

@@ -1746,14 +1746,14 @@ function rich_edit_exists() {
* @return bool
*/
function user_can_richedit() {
global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_iphone, $is_IE;
global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE;
if ( !isset($wp_rich_edit) ) {
$wp_rich_edit = false;
if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
if ( $is_safari ) {
if ( $is_iphone || false !== strpos( $_SERVER['HTTP_USER_AGENT'], '; Silk/' ) )
if ( wp_is_mobile() || false !== strpos( $_SERVER['HTTP_USER_AGENT'], '; Silk/' ) )
$wp_rich_edit = ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
else
$wp_rich_edit = true;

View File

@@ -97,3 +97,28 @@ $is_IIS = !$is_apache && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !
* @global bool $is_iis7
*/
$is_iis7 = $is_IIS && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7.') !== false);
/**
* Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
*
* @return bool true|false
*/
function wp_is_mobile() {
static $is_mobile;
if ( isset($is_mobile) )
return $is_mobile;
if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
$is_mobile = false;
} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false ) {
$is_mobile = true;
} else {
$is_mobile = false;
}
return $is_mobile;
}