Make WordPress Core

Changeset 20417


Ignore:
Timestamp:
04/10/2012 01:19:30 AM (13 years ago)
Author:
azaozz
Message:

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

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-header.php

    r19871 r20417  
    1212
    1313// In case admin-header.php is included in a function.
    14 global $title, $hook_suffix, $current_screen, $wp_locale, $pagenow, $wp_version, $is_iphone,
     14global $title, $hook_suffix, $current_screen, $wp_locale, $pagenow, $wp_version,
    1515    $current_site, $update_title, $total_update_count, $parent_file;
    1616
     
    8888$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
    8989
    90 if ( $is_iphone ) { ?>
    91 <style type="text/css">.row-actions{visibility:visible;}</style>
    92 <?php } ?>
     90if ( wp_is_mobile() )
     91    $admin_body_class .= ' mobile';
     92
     93?>
    9394</head>
    9495<body class="wp-admin no-js <?php echo apply_filters( 'admin_body_class', '' ) . " $admin_body_class"; ?>">
  • trunk/wp-admin/css/wp-admin.dev.css

    r20414 r20417  
    53245324}
    53255325
     5326.mobile .row-actions {
     5327    visibility: visible;
     5328}
     5329
    53265330tr:hover .row-actions,
    53275331div.comment-item:hover .row-actions {
  • trunk/wp-admin/includes/media.php

    r20382 r20417  
    6363 */
    6464function the_media_upload_tabs() {
    65     global $redir_tab, $is_iphone;
     65    global $redir_tab;
    6666    $tabs = media_upload_tabs();
    6767
    68     if ( $is_iphone ) {
     68    if ( wp_is_mobile() ) {
    6969        unset($tabs['type']);
    7070        $default = 'type_url';
     
    529529 */
    530530function wp_media_upload_handler() {
    531     global $is_iphone;
    532 
    533531    $errors = array();
    534532    $id = 0;
     
    601599    }
    602600
    603     if ( $is_iphone )
     601    if ( wp_is_mobile() )
    604602        return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
    605603    else
     
    13071305 */
    13081306function media_upload_form( $errors = null ) {
    1309     global $type, $tab, $pagenow, $is_IE, $is_opera, $is_iphone;
    1310 
    1311     if ( $is_iphone )
     1307    global $type, $tab, $pagenow, $is_IE, $is_opera;
     1308
     1309    if ( wp_is_mobile() )
    13121310        return;
    13131311
     
    14411439 */
    14421440function media_upload_type_form($type = 'file', $errors = null, $id = null) {
    1443     global $is_iphone;
    1444 
    1445     if ( $is_iphone )
     1441    if ( wp_is_mobile() )
    14461442        return;
    14471443
  • trunk/wp-admin/includes/misc.php

    r20023 r20417  
    584584
    585585function _ipad_meta() {
    586     if ( strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false ) { ?>
    587         <meta name="viewport" id="ipad-viewportmeta" content="width=device-width, initial-scale=1">
    588     <?php
     586    if ( wp_is_mobile() ) {
     587        ?>
     588        <meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1">
     589        <?php
    589590    }
    590591}
  • trunk/wp-admin/js/postbox.dev.js

    r20293 r20417  
    1 var postboxes, is_iPad = navigator.userAgent.match(/iPad/);
     1var postboxes;
    22
    33(function($) {
  • trunk/wp-admin/media-new.php

    r19712 r20417  
    77 */
    88
    9 global $is_iphone;
    10 
    11 if ( $is_iphone ) // cannot upload files from iPhone/iPad
     9if ( wp_is_mobile() ) // cannot upload files from mobile devices
    1210    return;
    1311
  • trunk/wp-admin/menu.php

    r19712 r20417  
    5757    $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php');
    5858    /* translators: add new file */
    59     if ( !$is_iphone )
     59    if ( ! wp_is_mobile() )
    6060        $submenu['upload.php'][10] = array( _x('Add New', 'file'), 'upload_files', 'media-new.php');
    6161
  • trunk/wp-includes/class-wp-admin-bar.php

    r19712 r20417  
    322322
    323323    final protected function _render( $root ) {
    324         global $is_IE, $is_iphone;
     324        global $is_IE;
    325325
    326326        // Add browser classes.
     
    334334            elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) )
    335335                $class .= ' ie9';
    336         } elseif ( $is_iphone ) {
     336        } elseif ( wp_is_mobile() ) {
    337337            $class .= ' mobile';
    338338        }
  • trunk/wp-includes/general-template.php

    r20326 r20417  
    17471747 */
    17481748function user_can_richedit() {
    1749     global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_iphone, $is_IE;
     1749    global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE;
    17501750
    17511751    if ( !isset($wp_rich_edit) ) {
     
    17541754        if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
    17551755            if ( $is_safari ) {
    1756                 if ( $is_iphone || false !== strpos( $_SERVER['HTTP_USER_AGENT'], '; Silk/' ) )
     1756                if ( wp_is_mobile() || false !== strpos( $_SERVER['HTTP_USER_AGENT'], '; Silk/' ) )
    17571757                    $wp_rich_edit = ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
    17581758                else
  • trunk/wp-includes/vars.php

    r19712 r20417  
    9898 */
    9999$is_iis7 = $is_IIS && (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7.') !== false);
     100
     101/**
     102 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
     103 *
     104 * @return bool true|false
     105 */
     106function wp_is_mobile() {
     107    static $is_mobile;
     108
     109    if ( isset($is_mobile) )
     110        return $is_mobile;
     111
     112    if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
     113        $is_mobile = false;
     114    } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
     115        || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
     116        || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
     117        || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false ) {
     118            $is_mobile = true;
     119    } else {
     120        $is_mobile = false;
     121    }
     122
     123    return $is_mobile;
     124}
  • trunk/wp-login.php

    r19925 r20417  
    4040 */
    4141function login_header($title = 'Log In', $message = '', $wp_error = '') {
    42     global $error, $is_iphone, $interim_login, $current_site;
     42    global $error, $interim_login, $current_site;
    4343
    4444    // Don't index any of these forms
     
    5555        add_action( 'login_head', 'wp_shake_js', 12 );
    5656
    57     ?>
    58 <!DOCTYPE html>
    59 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    60 <head>
     57    ?><!DOCTYPE html>
     58    <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
     59    <head>
    6160    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    6261    <title><?php bloginfo('name'); ?> &rsaquo; <?php echo $title; ?></title>
    63 <?php
     62    <?php
     63
    6464    wp_admin_css( 'wp-admin', true );
    6565    wp_admin_css( 'colors-fresh', true );
    6666
    67     if ( $is_iphone ) { ?>
    68     <meta name="viewport" content="width=320; initial-scale=0.9; maximum-scale=1.0; user-scalable=0;" />
    69     <style type="text/css" media="screen">
    70     .login form, .login .message, #login_error { margin-left: 0px; }
    71     .login #nav, .login #backtoblog { margin-left: 8px; }
    72     .login h1 a { width: auto; }
    73     #login { padding: 20px 0; }
    74     </style>
    75 <?php
     67    if ( wp_is_mobile() ) {
     68        ?>
     69        <meta name="viewport" content="width=320; initial-scale=0.9; maximum-scale=1.0; user-scalable=0;" />
     70        <style type="text/css" media="screen">
     71        .login form, .login .message, #login_error { margin-left: 0px; }
     72        .login #nav, .login #backtoblog { margin-left: 8px; }
     73        .login h1 a { width: auto; }
     74        #login { padding: 20px 0; }
     75        </style>
     76        <?php
    7677    }
    7778
     
    8990    $login_header_url   = apply_filters( 'login_headerurl',   $login_header_url   );
    9091    $login_header_title = apply_filters( 'login_headertitle', $login_header_title );
    91 ?>
    92 </head>
    93 <body class="login">
     92
     93    ?>
     94    </head>
     95    <body class="login">
    9496    <div id="login">
    9597        <h1><a href="<?php echo esc_url( $login_header_url ); ?>" title="<?php echo esc_attr( $login_header_title ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
    96 <?php
     98    <?php
     99
    97100    unset( $login_header_url, $login_header_title );
    98101
    99102    $message = apply_filters('login_message', $message);
    100     if ( !empty( $message ) ) echo $message . "\n";
     103    if ( !empty( $message ) )
     104        echo $message . "\n";
    101105
    102106    // In case a plugin uses $error rather than the $wp_errors object
     
    135139    </div>
    136140
    137 <?php if ( !empty($input_id) ) : ?>
    138 <script type="text/javascript">
    139 try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
    140 if(typeof wpOnload=='function')wpOnload();
    141 </script>
    142 <?php endif; ?>
    143 
    144 <?php do_action('login_footer'); ?>
    145 <div class="clear"></div>
    146 </body>
    147 </html>
    148 <?php
     141    <?php if ( !empty($input_id) ) : ?>
     142    <script type="text/javascript">
     143    try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
     144    if(typeof wpOnload=='function')wpOnload();
     145    </script>
     146    <?php endif; ?>
     147
     148    <?php do_action('login_footer'); ?>
     149    <div class="clear"></div>
     150    </body>
     151    </html>
     152    <?php
    149153}
    150154
    151155function wp_shake_js() {
    152     global $is_iphone;
    153     if ( $is_iphone )
     156    if ( wp_is_mobile() )
    154157        return;
    155158?>
Note: See TracChangeset for help on using the changeset viewer.