Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Commit

Permalink
Don't hide links to the upload form and show an error for mobile devi…
Browse files Browse the repository at this point in the history
…ces that cannot upload, see #20410

git-svn-id: http://core.svn.wordpress.org/trunk@20449 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
azaozz committed Apr 12, 2012
1 parent 1420887 commit 692cf6d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 23 deletions.
19 changes: 5 additions & 14 deletions wp-admin/includes/media.php
Expand Up @@ -64,13 +64,7 @@ function update_gallery_tab($tabs) {
function the_media_upload_tabs() {
global $redir_tab;
$tabs = media_upload_tabs();

if ( wp_is_mobile() ) {
unset($tabs['type']);
$default = 'type_url';
} else {
$default = 'type';
}
$default = 'type';

if ( !empty($tabs) ) {
echo "<ul id='sidemenu'>\n";
Expand Down Expand Up @@ -598,10 +592,7 @@ function wp_media_upload_handler() {
return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id );
}

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 );
return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
}

/**
Expand Down Expand Up @@ -1306,8 +1297,10 @@ function media_upload_header() {
function media_upload_form( $errors = null ) {
global $type, $tab, $pagenow, $is_IE, $is_opera;

if ( wp_is_mobile() )
if ( ! _device_can_upload() ) {
echo '<p>' . __('The web browser on your device cannot be used to upload files. You may be able to use the <a href=" http://wordpress.org/extend/mobile/">native app for your device</a> instead.') . '</p>';
return;
}

$upload_action_url = admin_url('async-upload.php');
$post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
Expand Down Expand Up @@ -1438,8 +1431,6 @@ function media_upload_form( $errors = null ) {
* @param unknown_type $id
*/
function media_upload_type_form($type = 'file', $errors = null, $id = null) {
if ( wp_is_mobile() )
return;

media_upload_header();

Expand Down
4 changes: 0 additions & 4 deletions wp-admin/media-new.php
Expand Up @@ -9,8 +9,4 @@
$_GET['inline'] = 'true';
/** Administration bootstrap */
require_once('./admin.php');

if ( wp_is_mobile() ) // cannot upload files from mobile devices
return;

require_once('./media-upload.php');
2 changes: 1 addition & 1 deletion wp-admin/media.php
Expand Up @@ -106,7 +106,7 @@
<h2>
<?php
echo esc_html( $title );
if ( current_user_can( 'upload_files' ) && ! wp_is_mobile() ) { ?>
if ( current_user_can( 'upload_files' ) ) { ?>
<a href="media-new.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'file'); ?></a>
<?php } ?>
</h2>
Expand Down
3 changes: 1 addition & 2 deletions wp-admin/menu.php
Expand Up @@ -56,8 +56,7 @@
$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 ( ! wp_is_mobile() )
$submenu['upload.php'][10] = array( _x('Add New', 'file'), 'upload_files', 'media-new.php');
$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' );
$submenu['link-manager.php'][5] = array( _x('All Links', 'admin menu'), 'manage_links', 'link-manager.php' );
Expand Down
2 changes: 1 addition & 1 deletion wp-admin/upload.php
Expand Up @@ -179,7 +179,7 @@
<h2>
<?php
echo esc_html( $title );
if ( current_user_can( 'upload_files' ) && ! wp_is_mobile() ) { ?>
if ( current_user_can( 'upload_files' ) ) { ?>
<a href="media-new.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'file'); ?></a><?php
}
if ( ! empty( $_REQUEST['s'] ) )
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/admin-bar.php
Expand Up @@ -489,7 +489,7 @@ function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
unset( $cpts['post'] );
}

if ( current_user_can( 'upload_files' ) && ! wp_is_mobile() )
if ( current_user_can( 'upload_files' ) )
$actions[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' );

if ( current_user_can( 'manage_links' ) )
Expand Down
23 changes: 23 additions & 0 deletions wp-includes/functions.php
Expand Up @@ -3676,3 +3676,26 @@ function _get_non_cached_ids( $object_ids, $cache_key ) {
return $clean;
}

/**
* Test if the current device has the capability to upload files.
*
* @since 3.4.0
* @access private
*
* @return bool true|false
*/
function _device_can_upload() {
if ( ! wp_is_mobile() )
return true;

$ua = $_SERVER['HTTP_USER_AGENT'];

if ( strpos($ua, 'iPhone') !== false
|| strpos($ua, 'iPad') !== false
|| strpos($ua, 'iPod') !== false ) {
return false;
} else {
return true;
}
}

0 comments on commit 692cf6d

Please sign in to comment.