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

git-svn-id: http://svn.automattic.com/wordpress/trunk@20417 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2012-04-10 01:19:30 +00:00
parent 36a725ff82
commit 1d12cd07b0
11 changed files with 87 additions and 59 deletions

View File

@ -11,7 +11,7 @@ if ( ! defined( 'WP_ADMIN' ) )
require_once( './admin.php' );
// In case admin-header.php is included in a function.
global $title, $hook_suffix, $current_screen, $wp_locale, $pagenow, $wp_version, $is_iphone,
global $title, $hook_suffix, $current_screen, $wp_locale, $pagenow, $wp_version,
$current_site, $update_title, $total_update_count, $parent_file;
// Catch plugins that include admin-header.php before admin.php completes.
@ -87,9 +87,10 @@ $admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-
$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
if ( $is_iphone ) { ?>
<style type="text/css">.row-actions{visibility:visible;}</style>
<?php } ?>
if ( wp_is_mobile() )
$admin_body_class .= ' mobile';
?>
</head>
<body class="wp-admin no-js <?php echo apply_filters( 'admin_body_class', '' ) . " $admin_body_class"; ?>">
<script type="text/javascript">document.body.className = document.body.className.replace('no-js','js');</script>

View File

@ -5323,6 +5323,10 @@ p.pagenav {
padding: 2px 0 0;
}
.mobile .row-actions {
visibility: visible;
}
tr:hover .row-actions,
div.comment-item:hover .row-actions {
visibility: visible;

View File

@ -62,10 +62,10 @@ add_filter('media_upload_tabs', 'update_gallery_tab');
* @since 2.5.0
*/
function the_media_upload_tabs() {
global $redir_tab, $is_iphone;
global $redir_tab;
$tabs = media_upload_tabs();
if ( $is_iphone ) {
if ( wp_is_mobile() ) {
unset($tabs['type']);
$default = 'type_url';
} else {
@ -528,8 +528,6 @@ function media_upload_form_handler() {
* @return unknown
*/
function wp_media_upload_handler() {
global $is_iphone;
$errors = array();
$id = 0;
@ -600,7 +598,7 @@ function wp_media_upload_handler() {
return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id );
}
if ( $is_iphone )
if ( wp_is_mobile() )
return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
else
return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
@ -1306,9 +1304,9 @@ function media_upload_header() {
* @param unknown_type $errors
*/
function media_upload_form( $errors = null ) {
global $type, $tab, $pagenow, $is_IE, $is_opera, $is_iphone;
global $type, $tab, $pagenow, $is_IE, $is_opera;
if ( $is_iphone )
if ( wp_is_mobile() )
return;
$upload_action_url = admin_url('async-upload.php');
@ -1440,9 +1438,7 @@ if ( ($is_IE || $is_opera) && $max_upload_size > 100 * 1024 * 1024 ) { ?>
* @param unknown_type $id
*/
function media_upload_type_form($type = 'file', $errors = null, $id = null) {
global $is_iphone;
if ( $is_iphone )
if ( wp_is_mobile() )
return;
media_upload_header();

View File

@ -583,9 +583,10 @@ foreach ( $_wp_admin_css_colors as $color => $color_info ): ?>
}
function _ipad_meta() {
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false ) { ?>
<meta name="viewport" id="ipad-viewportmeta" content="width=device-width, initial-scale=1">
<?php
if ( wp_is_mobile() ) {
?>
<meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1">
<?php
}
}
add_action('admin_head', '_ipad_meta');

View File

@ -1,4 +1,4 @@
var postboxes, is_iPad = navigator.userAgent.match(/iPad/);
var postboxes;
(function($) {
postboxes = {

View File

@ -6,9 +6,7 @@
* @subpackage Administration
*/
global $is_iphone;
if ( $is_iphone ) // cannot upload files from iPhone/iPad
if ( wp_is_mobile() ) // cannot upload files from mobile devices
return;
$_GET['inline'] = 'true';

View File

@ -56,7 +56,7 @@ $menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu
$menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'div' );
$submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php');
/* translators: add new file */
if ( !$is_iphone )
if ( ! wp_is_mobile() )
$submenu['upload.php'][10] = array( _x('Add New', 'file'), 'upload_files', 'media-new.php');
$menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-top menu-icon-links', 'menu-links', 'div' );

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;
}

View File

@ -39,7 +39,7 @@ if ( force_ssl_admin() && !is_ssl() ) {
* @param WP_Error $wp_error Optional. WordPress Error Object
*/
function login_header($title = 'Log In', $message = '', $wp_error = '') {
global $error, $is_iphone, $interim_login, $current_site;
global $error, $interim_login, $current_site;
// Don't index any of these forms
add_action( 'login_head', 'wp_no_robots' );
@ -54,25 +54,26 @@ function login_header($title = 'Log In', $message = '', $wp_error = '') {
if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
add_action( 'login_head', 'wp_shake_js', 12 );
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head>
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<title><?php bloginfo('name'); ?> &rsaquo; <?php echo $title; ?></title>
<?php
<?php
wp_admin_css( 'wp-admin', true );
wp_admin_css( 'colors-fresh', true );
if ( $is_iphone ) { ?>
<meta name="viewport" content="width=320; initial-scale=0.9; maximum-scale=1.0; user-scalable=0;" />
<style type="text/css" media="screen">
.login form, .login .message, #login_error { margin-left: 0px; }
.login #nav, .login #backtoblog { margin-left: 8px; }
.login h1 a { width: auto; }
#login { padding: 20px 0; }
</style>
<?php
if ( wp_is_mobile() ) {
?>
<meta name="viewport" content="width=320; initial-scale=0.9; maximum-scale=1.0; user-scalable=0;" />
<style type="text/css" media="screen">
.login form, .login .message, #login_error { margin-left: 0px; }
.login #nav, .login #backtoblog { margin-left: 8px; }
.login h1 a { width: auto; }
#login { padding: 20px 0; }
</style>
<?php
}
do_action( 'login_enqueue_scripts' );
@ -88,16 +89,19 @@ function login_header($title = 'Log In', $message = '', $wp_error = '') {
$login_header_url = apply_filters( 'login_headerurl', $login_header_url );
$login_header_title = apply_filters( 'login_headertitle', $login_header_title );
?>
</head>
<body class="login">
?>
</head>
<body class="login">
<div id="login">
<h1><a href="<?php echo esc_url( $login_header_url ); ?>" title="<?php echo esc_attr( $login_header_title ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
<?php
<?php
unset( $login_header_url, $login_header_title );
$message = apply_filters('login_message', $message);
if ( !empty( $message ) ) echo $message . "\n";
if ( !empty( $message ) )
echo $message . "\n";
// In case a plugin uses $error rather than the $wp_errors object
if ( !empty( $error ) ) {
@ -134,23 +138,22 @@ function login_footer($input_id = '') {
<p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr_e( 'Are you lost?' ); ?>"><?php printf( __( '&larr; Back to %s' ), get_bloginfo( 'title', 'display' ) ); ?></a></p>
</div>
<?php if ( !empty($input_id) ) : ?>
<script type="text/javascript">
try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
if(typeof wpOnload=='function')wpOnload();
</script>
<?php endif; ?>
<?php if ( !empty($input_id) ) : ?>
<script type="text/javascript">
try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
if(typeof wpOnload=='function')wpOnload();
</script>
<?php endif; ?>
<?php do_action('login_footer'); ?>
<div class="clear"></div>
</body>
</html>
<?php
<?php do_action('login_footer'); ?>
<div class="clear"></div>
</body>
</html>
<?php
}
function wp_shake_js() {
global $is_iphone;
if ( $is_iphone )
if ( wp_is_mobile() )
return;
?>
<script type="text/javascript">