WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 13 months ago

Last modified 13 months ago

#20410 closed enhancement (fixed)

Introduce a function to detect a device's ability to upload files

Reported by: johnbillion Owned by: azaozz
Milestone: 3.4 Priority: normal
Severity: normal Version: 3.4
Component: Media Keywords: ux-feedback
Focuses: Cc:

Description

Precursors: #20100 and #20405.

Some browser/OS combos don't allow files to be uploaded. The most common of these is Mobile Safari on iOS.

We should introduce a function which tells us if a given device is capable of uploading files. We can then use it in place of some of the wp_is_mobile() calls (which were introduced in [20417] to replace the $is_iphone global) where we need to hide certain UI elements relating to file uploads.

I propose a conditional function such as device_can_upload() that defaults to a return value of true but returns false for known browser/OS/device combos that can't upload files. Browser sniffing is bad of course, but there's no other way to do it.

Attachments (4)

20410.patch (5.2 KB) - added by SergeyBiryukov 2 years ago.
20410.2.patch (4.7 KB) - added by SergeyBiryukov 2 years ago.
20410.3.patch (4.7 KB) - added by SergeyBiryukov 2 years ago.
20410.minor-typo-fix.patch (747 bytes) - added by SergeyBiryukov 2 years ago.

Download all attachments as: .zip

Change History (28)

comment:1 nacin2 years ago

Is this something we could reasonably hook in via map_meta_cap for upload_files?

comment:2 johnbillion2 years ago

Yes, probably, but we'd have to make sure any corresponding error messages made sense instead of telling the user they don't have permission to upload files.

comment:3 SergeyBiryukov2 years ago

  • Component changed from General to Media
  • Milestone changed from Awaiting Review to 3.4
  • Version set to 3.4

Regression: since [20417], it's no longer possible to upload files using Opera Mini on Windows Mobile.

comment:4 azaozz2 years ago

  • Keywords ux-feedback added

So in any case there should be a list of mobile devices + browsers combos that cannot upload files wrapped in a function similar to wp_is_mobile().

What would be a better UX here? Leaving the links to media-new.php, etc. visible everywhere and showing an error message that the device doesn't allow uploading or removing all links to media-new.php?

SergeyBiryukov2 years ago

SergeyBiryukov2 years ago

comment:5 follow-up: SergeyBiryukov2 years ago

20410.patch is the first attempt:

  1. Improves iPhone/iPad detection so that it doesn't catch other mobile Safari devices.
  2. Introduces _device_can_upload() and leverages it where appropriate.
  3. Hooks in via map_meta_cap() for upload_files.

However I've noticed that point 3 blocks access to Media Library, making it impossible to browse the files uploaded earlier.

20410.2.patch contains points 1 and 2.

comment:6 in reply to: ↑ 5 ; follow-up: johnbillion2 years ago

Replying to SergeyBiryukov:

  1. Improves iPhone/iPad detection so that it doesn't catch other mobile Safari devices.

Will these changes detect Mobile Safari on iPod?

comment:7 in reply to: ↑ 6 SergeyBiryukov2 years ago

Replying to johnbillion:

Will these changes detect Mobile Safari on iPod?

I guess so. In 3.3, there was a similar check in _ipad_meta():
http://core.trac.wordpress.org/browser/tags/3.3.1/wp-admin/includes/misc.php#L588

However I've only tested with an emulator, would be great if anyone with a real device could confirm.

Last edited 2 years ago by SergeyBiryukov (previous) (diff)

comment:8 follow-up: SergeyBiryukov2 years ago

Scratch that, I misread the question.

Seems we need to add a check for iPod as well.

SergeyBiryukov2 years ago

comment:9 in reply to: ↑ 8 ; follow-up: azaozz2 years ago

Replying to SergeyBiryukov:

Seems we need to add a check for iPod as well.

Seems we will need to add more devices there. For example Kindle Fire is Android based but no point in showing the file upload on it as there are no files that can be uploaded.

Thinking that in general we need to detect only mobile devices that have cameras (i.e. the device can create some sort of files) and allow browser access to the underlying OS so these files can be uploaded.

comment:10 azaozz2 years ago

Also: if we go with showing the upload screens everywhere but show an error message for devices that cannot upload, perhaps we can detect and handle that with JS. Seems would be better than to try to maintain a list of devices.

comment:11 jane2 years ago

I vote for showing the upload links and giving informative error messages so people don't just think the dashboard is broken. Informative = saying it is a device limitation.

comment:12 azaozz2 years ago

Proposed text for the error message:

"The web browser on your device cannot be used to upload files. If you need to upload images, for example photos you have taken with your smart phone or tablet, you may be able to use the native app for your device. There are <a href="http://wordpress.org/extend/mobile/">native WordPress apps</a> for all popular mobile platforms."

Or instead of "you may be able to use..." perhaps "please use...".

Last edited 2 years ago by azaozz (previous) (diff)

comment:13 helenyhou2 years ago

Perhaps shorter?

"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."

comment:14 azaozz2 years ago

In [20449]:

Don't hide links to the upload form and show an error for mobile devices that cannot upload, see #20410

comment:15 azaozz2 years ago

Missed the "props" on the above commit :(

Props go to SergeyBiryukov and helenyhou.

comment:16 in reply to: ↑ 9 ; follow-up: SergeyBiryukov2 years ago

Replying to azaozz:

Thinking that in general we need to detect only mobile devices that have cameras (i.e. the device can create some sort of files) and allow browser access to the underlying OS so these files can be uploaded.

That might be an inaccurate assumption. Some devices don't have a camera, but still can create text and sound files.

comment:17 in reply to: ↑ 16 azaozz2 years ago

Replying to SergeyBiryukov:

Yes, tested that on the Kindle Fire. It can upload files created there.

Version 0, edited 2 years ago by azaozz (next)

comment:18 azaozz2 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Seems to work properly. More devices can be added to _device_can_upload() as needed.

comment:19 SergeyBiryukov2 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

There's an odd space in the URL (20410.minor-typo-fix.patch).

comment:20 azaozz2 years ago

  • Owner set to azaozz
  • Resolution set to fixed
  • Status changed from reopened to closed

In [20544]:

Fix typo in the error message shown when a device doesn't support uploading, props SergeyBiryukov, fixes #20410

comment:21 follow-up: scamartist2613 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Type changed from enhancement to defect (bug)

This is complete bahloney, @ Wordcamp Atl today a gent introduced me to a plugin he wrote that opened the "take a photo/from library [sic] button options on his iphone 5. He has offered to write a plugin for me since this is a very simple feature he has included on the front end of many sites. I will add to this track any real code value I find in positive or negative within the month. I don't understand and why it's not already addressed.

comment:22 in reply to: ↑ 21 rmccue13 months ago

Replying to scamartist26:

I don't understand and why it's not already addressed.

You need to be using iOS 6 or newer. This was added in r21141 as per #20923.

For versions of iOS before iOS 6, Mobile Safari doesn't support uploads.

comment:23 rmccue13 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed
  • Type changed from defect (bug) to enhancement

Also, if you're not getting the correct behaviour, please open a new ticket.

comment:24 scamartist2613 months ago

Thanks! My version of of WP was behind. Sorry for the confusion.

Note: See TracTickets for help on using tickets.